Skip to content

Add more context when trying to write async trait function #65899

Closed
@estebank

Description

@estebank

Given

trait T {
    async fn foo() {}
    async fn bar(&self) {}
}

we currently emit

error[E0706]: trait fns cannot be declared `async`
 --> src/lib.rs:2:5
  |
2 |     async fn foo() {}
  |     ^^^^^^^^^^^^^^^^^

error[E0706]: trait fns cannot be declared `async`
 --> src/lib.rs:3:5
  |
3 |     async fn bar(&self) {}
  |     ^^^^^^^^^^^^^^^^^^^^^^

We should tell people that async trait functions are not possible because of technical restrictions, and possibly point them to the async-trait crate.

This issue has been assigned to @jafern14 via this comment.

Metadata

Metadata

Assignees

Labels

A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-trait-systemArea: Trait systemAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions