-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsI-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.L-irrefutable_let_patternsLint: irrefutable_let_patternsLint: irrefutable_let_patternsT-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-langRelevant to the language teamRelevant to the language team
Description
Code
#![feature(let_chains)]
fn max() -> usize {
42
}
fn main() {
if let mx = max() && mx < usize::MAX {
// ...
}
}
Current output
warning: leading irrefutable pattern in let chain
--> src/main.rs:7:8
|
7 | if let mx = max() && mx < usize::MAX {
| ^^^^^^^^^^^^^^
|
= note: this pattern will always match
= help: consider moving it outside of the construct
= note: `#[warn(irrefutable_let_patterns)]` on by default
Desired output
(no warning)
Rationale and extra context
This code naturally expresses "please call that function and then do something if the return value satisfies a condition". Putting the let
binding outside the if
would be bad as then it remains in scope after the if
, which is not the intent. I could wrap it in an extra layer of curly braces but that increases the overall indentation level.
I think this warning should never trigger for let chains.
Other cases
Rust Version
current nightly
Anything else?
No response
kurikomoe and goffrie
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsI-lang-radarItems that are on lang's radar and will need eventual work or consideration.Items that are on lang's radar and will need eventual work or consideration.L-irrefutable_let_patternsLint: irrefutable_let_patternsLint: irrefutable_let_patternsT-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-langRelevant to the language teamRelevant to the language team