Skip to content

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

Merged
merged 1 commit into from
May 31, 2024

Conversation

J-ZhengLi
Copy link
Member

fixes: #12853


changelog: fix [redundant_closure] suggesting incorrect code with F: Fn()

@rustbot
Copy link
Collaborator

rustbot commented May 29, 2024

r? @y21

rustbot has assigned @y21.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label May 29, 2024
Comment on lines +174 to 180
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)
}) {
Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

|| !check_inputs(typeck, body.params, None, args)
{
return;
}

matches!(
p.pat.kind,
PatKind::Binding(BindingMode::NONE, id, _, None)
if path_to_local_id(arg, id)
)

Copy link
Member Author

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😂

@y21
Copy link
Member

y21 commented May 31, 2024

Don't think we need to block it on figuring out what that local_used_in check is for. LGTM, thanks!

@bors r+

@bors
Copy link
Contributor

bors commented May 31, 2024

📌 Commit db30f6c has been approved by y21

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented May 31, 2024

⌛ Testing commit db30f6c with merge 0b598b6...

@bors
Copy link
Contributor

bors commented May 31, 2024

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: y21
Pushing 0b598b6 to master...

@bors bors merged commit 0b598b6 into rust-lang:master May 31, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

redundant_closure doesn't handle Fn
4 participants