-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-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.
Description
Given the following code:
fn main() {
#[allow(irrefutable_let_patterns)]
println!("{}", if let _ = 1 { 42 } else { 0 });
// The macro doesn't matter, even macros like `asm!` exhibit this behavior
#[allow(irrefutable_let_patterns)]
dbg!("{}", if let _ = 1 { 42 } else { 0 });
#[allow(irrefutable_let_patterns)]
{
println!("{}", if let _ = 2 { 84 } else { 0 });
}
#[allow(irrefutable_let_patterns)]
if let _ = 3 {
println!("{}", 168);
} else {
println!("{}", 0);
}
}The current output is:
warning: irrefutable `if let` pattern
--> src/main.rs:3:20
|
3 | println!("{}", if let _ = 1 { 42 } else { 0 });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(irrefutable_let_patterns)]` on by default
= note: this pattern will always match, so the `if let` is useless
= help: consider replacing the `if let` with a `let`
warning: irrefutable `if let` pattern
--> src/main.rs:7:16
|
7 | dbg!("{}", if let _ = 1 { 42 } else { 0 });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this pattern will always match, so the `if let` is useless
= help: consider replacing the `if let` with a `let`
warning: 2 warnings emitted
Ideally in this case, the compilation should succeed without warning, as the lint appears to have been explicitly allowed everywhere it is used.
This likely applies for all lints and all lint levels and all macros
- (only tested
println!,dbg!, andasm!with allow, warn, and deny forirrefutable_let_patternsas well as in in my in progress lintnamed_asm_labels)
A current workaround is to create a scope to put the macro in, and apply the lint level to that scope, as demonstrated in the example.
Applying the lint level to the crate with #![level(lint)] works as expected, however this is often not desirable.
Possibly related: #59306
stevenengler
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-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.