Incorrect diagnostic "pattern requires `..` due to inaccessible fields" when matching in a macro
Open
@fmease is already working on this.
Since Sep 19, 2024.
A-diagnostics
A-hygiene
A-macros
D-confusing
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
struct A {
field1: String,
field2: String,
}
fn test(x: A) {
macro_rules! weird {
() => { let A { field1 } = x; }
}
weird!();
}
Current output
error: pattern requires `..` due to inaccessible fields
--> a.rs:8:21
|
8 | () => { let A { field1 } = x; }
| ^^^^^^^^^^^^
9 | }
10 | weird!();
| -------- in this macro invocation
|
= note: this error originates in the macro `weird` (in Nightly builds, run with -Z macro-backtrace for more info)
help: ignore the inaccessible and unused fields
|
8 | () => { let A { field1, .. } = x; }
| ++++
Desired output
error[E0027]: pattern does not mention field `field2`
--> a.rs:8:21
|
8 | () => { let A { field1 } = x; }
| ^^^^^^^^^^^^ missing field `field2`
|
Rationale and extra context
It seems this error message gets generated whenever an incomplete pattern shows up within a macro invocation, whether or not the fields are actually inaccessible.
Other cases
No response
Rust Version
rustc 1.83.0-nightly (f79a912d9 2024-09-18)
binary: rustc
commit-hash: f79a912d9edc3ad4db910c0e93672ed5c65133fa
commit-date: 2024-09-18
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0
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.
Assessment
This issue has not been assessed yet.