async makes pattern matching errors in function signatures worse
Open
Nobody has claimed this yet.
A-diagnostics
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report from the src/main.rs example with rustc 1.84.1, comparing the async and non-async function signatures. Start by tracing how the compiler formats the E0005 diagnostic for the async case. Done means the async example reports a refutable pattern in a function argument with the expected location, wording, and without the extra let-binding notes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100