Skip to content

docs: discourage #[async_trait] and #[allow(async_fn_in_trait)]#20242

Merged
bolinfest merged 1 commit intomainfrom
pr20242
Apr 29, 2026
Merged

docs: discourage #[async_trait] and #[allow(async_fn_in_trait)]#20242
bolinfest merged 1 commit intomainfrom
pr20242

Conversation

@bolinfest
Copy link
Copy Markdown
Collaborator

@bolinfest bolinfest commented Apr 29, 2026

Why

We have run into two avoidable problems when introducing async trait APIs in Rust:

  • #[async_trait] has caused materially worse build times in this repository.
  • #[allow(async_fn_in_trait)] makes it too easy to ship a public trait without spelling out whether the returned future is Send, which hides an important part of the trait contract.

We already have a good example of the preferred alternative in #16630 / 3c7f013f9735, but that guidance currently lives only as prior art in the codebase. This PR documents the rule in AGENTS.md so contributors are more likely to follow the native RPITIT pattern before these two shortcuts spread further.

What Changed

  • added Rust guidance in AGENTS.md discouraging both #[async_trait] and #[allow(async_fn_in_trait)]
  • pointed contributors to the native RPITIT pattern with explicit Send bounds on the returned future
  • clarified that implementations may still use async fn when they satisfy that trait contract

Verification

  • docs-only change; no tests run

@chatgpt-codex-connector
Copy link
Copy Markdown
Contributor

Note

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@bolinfest bolinfest changed the title doc: discourage the use of #[async_trait] docs: discourage #[async_trait] and #[allow(async_fn_in_trait)] Apr 29, 2026
@bolinfest bolinfest merged commit b154600 into main Apr 29, 2026
25 checks passed
@bolinfest bolinfest deleted the pr20242 branch April 29, 2026 22:29
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants