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
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
Anything else?
No response
Code
Current output
Desired output
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
letbinding outside theifwould be bad as then it remains in scope after theif, 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
Anything else?
No response