- Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
rust-lang/rust
#88163Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
fn next() -> Option<Enum> { 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_matchClippy apparently wants this loop written as:
while let Some(Enum::Yes) = next() { println!("yes"); }which is just not the same meaning.
Meta
cargo clippy -V: e.g. clippy 0.1.56 (0035d9d 2021-08-16)rustc -Vv: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
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have