Skip to content

Invalid 'compatible variant' suggestion on mismatched types in .await expression #93074

Closed
@m-ou-se

Description

This code:

async fn a() {}

async fn b() -> Result<(), i32> {
    a().await
}

produces:

error[E0308]: mismatched types
 --> src/main.rs:4:8
  |
4 |     a().await
  |        ^^^^^^ expected enum `Result`, found `()`
  |
  = note:   expected enum `Result<(), i32>`
          found unit type `()`
help: try wrapping the expression in `Ok`
  |
4 |     a()Ok(.await)
  |        +++      +

Which is invalid.

Looks like the span of the desugaring of .await uses only the .await part, instead of the span of the entire expression. This results in invalid suggestions when used by the suggest_compatible_variants code in compiler/rustc_typeck/src/check/demand.rs.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.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