-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
option_if_let_else suggests map_or instead of map_or_else even if else branch contains a function call #5821
Comments
I now see that #5301 (comment) implies this is intentional, and that after the suggestion, the #[deny(clippy::or_fun_call)]
pub fn foo(o: Option<i32>, f: impl FnOnce(i32), g: impl FnOnce()) {
o.map_or(g(), |i| f(i))
} does not raise any errors. It does cause the So if we modify the code to remove the possibility of triggering #[deny(clippy::or_fun_call)]
pub fn foo(o: Option<i32>, f: impl FnOnce(i32) -> i32, g: impl FnOnce() -> i32) -> i32 {
o.map_or(g(), |i| f(i))
} this code still does not raise any errors. Perhaps this issue can be repurposed to figure out why |
I think |
doesn't trigger the lint because it only looks for function calls of at least one argument. See in methods/mod.rs. |
option_if_let_else - distinguish pure from impure else expressions Addresses partially #5821. changelog: improve the lint `option_if_let_else`. Suggest `map_or` or `map_or_else` based on the else expression purity.
This issue seems to be fixed. Clippy at least suggests the usage of |
The change you're seeing is from #5937 , which considered this issue to only be "partially fixed". I'm not sure what the unfixed part is, however. |
as of today, this does not lint at all, not sure when that happened or whether it was on purpose or not |
The lint suggests
o.map_or(g(), |i| f(i))
, which is wrong because theelse
branch should be evaluated lazily because it's a function call. It ought to have suggestedo.map_or_else(|| g(), |i| f(i))
Meta
cargo clippy -V
:clippy 0.0.212 (39d5a61 2020-07-17)
rustc -Vv
:The text was updated successfully, but these errors were encountered: