fix manual_filter false positive

do explicit checks for the other branch being None
This commit is contained in:
Eric Wu 2022-12-15 23:29:28 -05:00
parent 3905f51230
commit 5b3a6669f7
3 changed files with 65 additions and 6 deletions

View file

@ -116,4 +116,31 @@ fn main() {
},
None => None,
};
match Some(20) {
// Don't Lint, because `Some(3*x)` is not `None`
None => None,
Some(x) => {
if x > 0 {
Some(3 * x)
} else {
Some(x)
}
},
};
// Don't lint: https://github.com/rust-lang/rust-clippy/issues/10088
let result = if let Some(a) = maybe_some() {
if let Some(b) = maybe_some() {
Some(a + b)
} else {
Some(a)
}
} else {
None
};
}
fn maybe_some() -> Option<u32> {
Some(0)
}

View file

@ -240,4 +240,31 @@ fn main() {
},
None => None,
};
match Some(20) {
// Don't Lint, because `Some(3*x)` is not `None`
None => None,
Some(x) => {
if x > 0 {
Some(3 * x)
} else {
Some(x)
}
},
};
// Don't lint: https://github.com/rust-lang/rust-clippy/issues/10088
let result = if let Some(a) = maybe_some() {
if let Some(b) = maybe_some() {
Some(a + b)
} else {
Some(a)
}
} else {
None
};
}
fn maybe_some() -> Option<u32> {
Some(0)
}