Until `if let` chains are stabilized, we do not collapse them together or with other `if` expressions unless the `let_chains` feature is enabled. This is the case for example in Clippy sources.
29 lines
604 B
Rust
29 lines
604 B
Rust
#![feature(let_chains)]
|
|
#![warn(clippy::collapsible_if)]
|
|
|
|
fn main() {
|
|
if let Some(a) = Some(3) {
|
|
// with comment, so do not lint
|
|
if let Some(b) = Some(4) {
|
|
let _ = a + b;
|
|
}
|
|
}
|
|
|
|
if let Some(a) = Some(3)
|
|
&& let Some(b) = Some(4) {
|
|
let _ = a + b;
|
|
}
|
|
//~^^^^^ collapsible_if
|
|
|
|
if let Some(a) = Some(3)
|
|
&& a + 1 == 4 {
|
|
let _ = a;
|
|
}
|
|
//~^^^^^ collapsible_if
|
|
|
|
if Some(3) == Some(4).map(|x| x - 1)
|
|
&& let Some(b) = Some(4) {
|
|
let _ = b;
|
|
}
|
|
//~^^^^^ collapsible_if
|
|
}
|