Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
goffrie opened this issue Sep 19, 2024 · 1 comment
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@goffrie
Copy link
Contributor

goffrie commented Sep 19, 2024

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

@goffrie goffrie added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 19, 2024
@fmease fmease self-assigned this Sep 19, 2024
@fmease fmease added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) D-confusing Diagnostics: Confusing error or lint that should be reworked. labels Sep 19, 2024
@fmease
Copy link
Member

fmease commented Sep 19, 2024

Thanks for your report, good catch! I'm pretty sure my closed PR #116575 would address it, though I have to double-check. Will try to rework the PR soon and reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants