-
Notifications
You must be signed in to change notification settings - Fork 14k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
Perhaps this is more a thing for clippy to detect, I'm not sure.
A co-worker of mine tried this code:
if !matches!(binding_to_uuid, binding_to_other_uuid) {
// ...
}I expected to see this happen:
Compiler should say that this is an obvious error, because there is no way to use the binding_to_other_uuid binding because it is internal to the match statement (and just shadows the actual binding_to_other_uuid).
Instead, this happened:
The matches! macro here expands to something that is never useful:
if !match binding_to_uuid {
binding_to_other_uuid => true,
_ => false,
} { ... }Clippy suggests underscoring the binding_to_other_uuid because it's unused, but that's not super clear unless you are familiar with the macro expansion. Ideally providing variable bindings that are not used in a guard would be disallowed in matches! because they cannot otherwise be used.
Meta
rustc --version --verbose:
rustc 1.52.1 (9bc8c42bb 2021-05-09)
binary: rustc
commit-hash: 9bc8c42bb2f19e745a63f3445f1ac248fb015e53
commit-date: 2021-05-09
host: x86_64-unknown-linux-gnu
release: 1.52.1
LLVM version: 12.0.0
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.