Skip to content
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

fix: incorrect suggestions generated by manual_retain lint #12084

Merged
merged 2 commits into from Jan 27, 2024

Conversation

yuxqiu
Copy link
Contributor

@yuxqiu yuxqiu commented Jan 3, 2024

fixes #10393, fixes #11457, fixes #12081

#10393: In the current implementation of manual_retain, if the argument to the closure is matched using tuple, they are all treated as the result of a call to map.into_iter().filter(<f>). However, such tuple pattern matching can also occur in many different containers that stores tuples internally. The correct approach is to apply different lint policies depending on whether the receiver of into_iter is a map or not.

#11457 and #12081: In the current implementation of manual_retain, if the argument to the closure is Binding, the closure will be used directly in the retain method, which will result in incorrect suggestion because the first argument to the retain closure may be of a different type. In addition, if the argument to the closure is Ref + Binding, the lint will simply remove the Ref part and use the Binding part as the argument to the new closure, which will lead to bad suggestion for the same reason. The correct approach is to detect each of these cases and apply lint suggestions conservatively.

changelog: [manual_retain] refactor and add check for various patterns

@rustbot
Copy link
Collaborator

rustbot commented Jan 3, 2024

r? @Alexendoo

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jan 3, 2024
@Alexendoo
Copy link
Member

Thank you!

@bors r+

@bors
Copy link
Collaborator

bors commented Jan 27, 2024

📌 Commit 03b3a16 has been approved by Alexendoo

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Jan 27, 2024

⌛ Testing commit 03b3a16 with merge 8ccf6a6...

@bors
Copy link
Collaborator

bors commented Jan 27, 2024

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Alexendoo
Pushing 8ccf6a6 to master...

@bors bors merged commit 8ccf6a6 into rust-lang:master Jan 27, 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
4 participants