fix [redundant_closure] suggesting incorrect code with F: Fn()#12865
Conversation
| if path_to_local(callee).map_or(false, |l| { | ||
| // FIXME: Do we really need this `local_used_in` check? | ||
| // Isn't it checking something like... `callee(callee)`? | ||
| // If somehow this check is needed, add some test for it, | ||
| // 'cuz currently nothing changes after deleting this check. | ||
| local_used_in(cx, l, args) || local_used_after_expr(cx, l, expr) | ||
| }) { |
There was a problem hiding this comment.
confused, but too scared to remove it
There was a problem hiding this comment.
Yeah, I'm also not entirely sure what that is for. Seems like that additional check was introduced in #8685, but that was a rather large refactor. Before this, there was only the local_used_after_expr check. Unfortunate that there's no test for this.
There was a problem hiding this comment.
Oh, it might mean situation like this?
let fun = |x: i32| -> i32 {
x
};
let _ = fun(fun(0));but I'm not sure, I'll test it.
There was a problem hiding this comment.
I don't think so. There is a check somewhere in the if chain that makes sure that the fn arguments are only paths to locals. So in your example that wouldn't happen because fun(0) is more than just a path.
rust-clippy/clippy_lints/src/eta_reduction.rs
Lines 128 to 131 in 03654ba
rust-clippy/clippy_lints/src/eta_reduction.rs
Lines 230 to 234 in 03654ba
There was a problem hiding this comment.
right... then I'm afraid that I can't think of any examples that pass the compilation check😂
|
Don't think we need to block it on figuring out what that @bors r+ |
|
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
fixes: #12853
changelog: fix [
redundant_closure] suggesting incorrect code withF: Fn()