Open
Description
#[deny(clippy::option_if_let_else)]
pub fn foo(o: Option<i32>, f: impl FnOnce(i32), g: impl FnOnce()) {
if let Some(i) = o {
f(i)
}
else {
g()
}
}
The lint suggests o.map_or(g(), |i| f(i))
, which is wrong because the else
branch should be evaluated lazily because it's a function call. It ought to have suggested o.map_or_else(|| g(), |i| f(i))
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
Metadata
Metadata
Assignees
Labels
Category: Clippy is not doing the correct thingCategory: Enhancement of lints, like adding more cases or adding help messagesCall for participation: Medium difficulty level problem and requires some initial experience.Issue: The lint should have been triggered on code, but wasn'tLint: Currently in the nursery group