Closed
Description
Summary
When using nested if let
in a way that triggers clippy::manual_filter
, clippy makes an invalid suggestion.
Reproducer
I tried this code:
fn maybe_some() -> Option<u32> {
Some(0)
}
fn main() {
let result = if let Some(a) = maybe_some() {
if let Some(b) = maybe_some() {
Some(a + b)
} else {
Some(a)
}
} else {
None
};
println!("{result:?}");
}
I expected to see this happen: No lint error, or suggested fix compiles.
Instead, this happened:
warning: manual implementation of `Option::filter`
--> src/main.rs:6:17
|
6 | let outer = if let Some(a) = maybe_some() {
| _________________^
7 | | if let Some(b) = maybe_some() {
8 | | Some(a + b)
9 | | } else {
... |
13 | | None
14 | | };
| |_____^ help: try this: `maybe_some().filter(|&a| !(let Some(b) = maybe_some()))`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_filter
= note: `#[warn(clippy::manual_filter)]` on by default
Version
0.1.67 (2022-12-14 b70baa4)