Skip to content

Fix the swapped arguments in redundant_closure's late-bound region check#17455

Open
shulaoda wants to merge 1 commit into
rust-lang:masterfrom
shulaoda:07-26-fix_the_swapped_arguments_in_redundant_closure_s_late-bound_region_check
Open

Fix the swapped arguments in redundant_closure's late-bound region check#17455
shulaoda wants to merge 1 commit into
rust-lang:masterfrom
shulaoda:07-26-fix_the_swapped_arguments_in_redundant_closure_s_late-bound_region_check

Conversation

@shulaoda

@shulaoda shulaoda commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Fixes #14215

redundant_closure only reduces |x| f(x) to f when both signatures agree on which regions are late-bound, because rustc cannot late bind an early-bound region. The helper that compares a type's generic arguments zipped the two lists in the wrong order, inverting the directional check_region so that the case it exists to reject was let through. Only ADTs were affected, since a region held directly, as in &'a u32, takes the ty::Ref arm. So for a bound like FnOnce(&mut Guard<S>) the lint offered a machine-applicable rewrite that fails to compile with implementation of FnOnce is not general enough.

This zips them in the same order as the call site and the rest of the function.

Correcting the direction also fixes the opposite error, where a safe rewrite was rejected. Four such closures in clippy's own source are now caught by redundant_closure_for_method_calls, so this reduces them as well to keep dogfood passing.

changelog: [redundant_closure]: don't suggest a non-compiling rewrite when an early-bound region sits inside an ADT

@rustbot rustbot added S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jul 25, 2026
@rustbot

rustbot commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request. A reviewer will take a look after it receives 2 community reviews.

In the meantime, we would highly appreciate if you could try to review any of PRs waiting on community reviews.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@github-actions

github-actions Bot commented Jul 25, 2026

Copy link
Copy Markdown

Lintcheck changes for 9cb7746

Lint Added Removed Changed
clippy::redundant_closure 1 0 0
clippy::redundant_closure_for_method_calls 45 0 0

This comment will be updated if you push new changes

@shulaoda
shulaoda force-pushed the 07-26-fix_the_swapped_arguments_in_redundant_closure_s_late-bound_region_check branch from ff1ae6a to 9cb7746 Compare July 25, 2026 23:26

@CommanderStorm CommanderStorm left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return true;
}
for (from_arg, to_arg) in to_subs.iter().zip(from_subs) {
for (from_arg, to_arg) in from_subs.iter().zip(to_subs) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol. Having a lint specifically for this kind of from_* <-> to_* bug might be nice..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. 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 suggested fix fails to compile due to lifetime requirements

3 participants