- 
                Notifications
    
You must be signed in to change notification settings  - Fork 13.9k
 
Open
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
trait Trait {}
async fn fun() -> Trait {
    todo!()
}
fn main() {}Current output
error[E0782]: expected a type, found a trait
 --> src/main.rs:3:19
  |
3 | async fn fun() -> Trait {
  |                   ^^^^^
  |
help: you can add the `dyn` keyword if you want a trait object
  |
3 | async fn fun() -> dyn Trait {
  |                   +++
help: you might have meant to write a bound here
  |
1 | : Trait {
  | ~
Desired output
error[E0782]: expected a type, found a trait
 --> src/main.rs:3:19
  |
3 | async fn fun() -> Trait {
  |                   ^^^^^
  |
help: use `impl Trait` to return an opaque type, as long as you return a single underlying type
  |
3 | async fn fun() -> impl Trait {
  |                   ++++
help: alternatively, you can return an owned trait object
  |
3 | async fn fun() -> Box<dyn Trait> {
  |                   +++++++      +
Rationale and extra context
No response
Other cases
No response
Rust Version
rustc 1.83.0-dev
binary: rustc
commit-hash: ecf2d1f
commit-date: 2024-10-13
host: x86_64-unknown-linux-gnu
release: 1.83.0-dev
LLVM version: 19.1.1
Anything else?
Originally reported in #127691 (comment)
The non-async case was fixed in #131239
Metadata
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.