Closed
Description
#[deny(clippy::option_if_let_else)]
pub fn foo(o: Option<i32>, mut f: impl FnMut(i32)) {
if let Some(i) = o {
f(i)
}
else {
f(5)
}
}
Apart from having the same problem as #5821, in this particular case even the suggestion of o.map_or_else(|| f(5), |i| f(i))
would be wrong because f
is being used as a &mut
, so it cannot be used with two closures at the same time. This also happens for f: impl FnOnce(i32)
.
I don't think there's any better way to write this code using any of the Option
combinators, so it seems to be the lint should not fire at all.
Meta
cargo clippy -V
:clippy 0.0.212 (39d5a61 2020-07-17)
rustc -Vv
:rustc 1.47.0-nightly (39d5a61f2 2020-07-17) binary: rustc commit-hash: 39d5a61f2e4e237123837f5162cc275c2fd7e625 commit-date: 2020-07-17 host: x86_64-unknown-linux-gnu release: 1.47.0-nightly LLVM version: 10.0