Skip to content

async makes pattern matching errors in function signatures worse #136719

@BaerLKR

Description

@BaerLKR

Code

struct A(pub i32);

async fn example(Some(A(_)): Option<A>) {
}

Current output

error[E0005]: refutable pattern in local binding
 --> src/main.rs:7:12
  |
7 | async fn example(Some(A(_)): Option<A>) {}
  |            ^^^^^^^^^^ pattern `None` not covered
  |
  = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
  = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
  = note: the matched value is of type `Option<A>`
help: you might want to use `let else` to handle the variant that isn't matched
  |
7 | async fn example(Some(A(_)) else { todo!() }: Option<A>) {}
  |                       ++++++++++++++++

For more information about this error, try `rustc --explain E0005`.

Desired output

error[E0005]: refutable pattern in function argument
 --> src/main.rs:7:6
  |
7 | fn example(Some(A(_)): Option<A>) {}
  |      ^^^^^^^^^^ pattern `None` not covered
  |
  = note: the matched value is of type `Option<A>`

For more information about this error, try `rustc --explain E0005`.

Rationale and extra context

The desired output is what I get when I don't make the funtion async. So this

struct A(pub i32);
fn example(Some(A(_)): Option<A>) {}

gives the desired output

Other cases

Rust Version

rustc 1.84.1 (e71f9a9a9 2025-01-27)
binary: rustc
commit-hash: e71f9a9a98b0faf423844bf0ba7438f29dc27d58
commit-date: 2025-01-27
host: x86_64-unknown-linux-gnu
release: 1.84.1
LLVM version: 19.1.5

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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