Skip to content

Incorrect diagnostic "pattern requires .. due to inaccessible fields" when matching in a macro #130588

Open
@goffrie

Description

@goffrie

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 (f79a912 2024-09-18)
binary: rustc
commit-hash: f79a912
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

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-hygieneArea: Macro hygieneA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)D-confusingDiagnostics: Confusing error or lint that should be reworked.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