-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix [redundant_closure
] suggesting incorrect code with F: Fn()
#12865
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
confused, but too scared to remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
|| !check_inputs(typeck, body.params, None, args) | |
{ | |
return; | |
} |
rust-clippy/clippy_lints/src/eta_reduction.rs
Lines 230 to 234 in 03654ba
matches!( | |
p.pat.kind, | |
PatKind::Binding(BindingMode::NONE, id, _, None) | |
if path_to_local_id(arg, id) | |
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()