collapsible_match suggests an incorrect behavior change · Issue #7575 · rust-lang/rust-clippy (original) (raw)

fn next() -> Option { None }

enum Enum { Yes, No, }

fn main() { while let Some(thing) = next() { if let Enum::Yes = thing { println!("yes"); } } }

$ cargo clippy

warning: unnecessary nested if let or match --> src/main.rs:12:9 | 12 | / if let Enum::Yes = thing { 13 | | println!("yes"); 14 | | } | |_________^ | = note: #[warn(clippy::collapsible_match)] on by default help: the outer pattern can be modified to include the inner pattern --> src/main.rs:11:20 | 11 | while let Some(thing) = next() { | ^^^^^ replace this binding 12 | if let Enum::Yes = thing { | ^^^^^^^^^ with this pattern = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_match

Clippy apparently wants this loop written as:

while let Some(Enum::Yes) = next() {
    println!("yes");
}

which is just not the same meaning.

Meta

rustc 1.56.0-nightly (0035d9dce 2021-08-16)  
binary: rustc  
commit-hash: 0035d9dcecee49d1f7349932bfa52c05a6f83641  
commit-date: 2021-08-16  
host: x86_64-unknown-linux-gnu  
release: 1.56.0-nightly  
LLVM version: 12.0.1