- Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing
Description
Summary
clippy fails to understand nested pattern matches. It treats if let Some(Some(a))
the same as if let Some(a)
, resulting in invalid code when --fix
-ing.
Reproducer
I tried this code:
fn main() { let foo = Some(Some(5)); let num: i32 = if let Some(Some(num)) = foo { num } else { 0 }; println!("{num}"); }
I expected to see this happen:
Nothing, really.
Instead, this happened:
The following errors were reported: error[E0308]: mismatched types --> src/main.rs:3:20 | 3 | let num: i32 = foo.unwrap_or_default(); | --- ^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `Option<{integer}>` | | | expected due to this | = note: expected type `i32` found enum `std::option::Option<{integer}>` help: consider using `Option::expect` to unwrap the `std::option::Option<{integer}>` value, panicking if the value is an `Option::None` | 3 | let num: i32 = foo.unwrap_or_default().expect("REASON"); | +++++++++++++++++
Version
No response
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing