-
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 thingE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.L-suggestionLint: Improving, adding or fixing lint suggestionsLint: Improving, adding or fixing lint suggestions
Description
#[deny(clippy::unit_arg)]
pub fn foo(o: Option<i32>, f: impl FnOnce(i32), g: impl FnOnce()) {
o.map_or(g(), |i| f(i))
}
(For context, this is the code after taking the code in #5821 and applying clippy::option_if_let_else
's suggestion.)
The lint's suggestion is:
help: move the expression in front of the call...
|
3 | g();
|
help: ...and use a unit literal instead
|
3 | o.map_or((), |i| f(i))
| ^^
I'm not sure what the first suggestion is trying to say.
The second suggestion is removing the call to g
entirely, which is definitely wrong.
Note that the expectation of this code was that it would actually trigger clippy::or_fun_call
to suggest o.map_or_else(|| g(), |i| f(i))
(as mentioned in #5821), so the problem is not only that it ended up triggering clippy::unit_arg
instead but also that the suggestions don't make sense.
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
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.L-suggestionLint: Improving, adding or fixing lint suggestionsLint: Improving, adding or fixing lint suggestions