-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 swap suggestion #4478
Conversation
Clippy suggests using swap on fields belonging to the same owner causing two mutable borrows of the owner Fixes rust-lang#981 Signed-off-by: Cristian Kubis <cristian.kubis@tsunix.de>
Thanks for fixing this issue! First step would be to add tests for all the cases listed in #981. So slice access, field access and field access through a slice. I think your code currently just handles the field access case. Once you added the tests we can take the next step in fixing this issue. See also https://github.com/rust-lang/rust-clippy/blob/master/doc/adding_lints.md#Testing on writing tests in Clippy and adding/fixing lints. |
These tests make sure that the swap warning will not be triggered for expressions that will cause multiple mutable references of the same owner
Thanks for the feedback! I've added test cases for the field and field through slice access. Pure slice access alraedy has its own logic and test case. |
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.
LGTM, thanks! Let's wait for travis and then merge this.
Thanks! (Sorry, forgot about this) @bors r+ |
📌 Commit 9041856 has been approved by |
Fix incorrect swap suggestion Clippy suggests using swap on fields belonging to the same owner causing two mutable borrows of the owner. Disclosure: This is my first time working with clippy and rusts HIR. I'm very grateful for assistance and suggestions to improve the PR. fixes #981 changelog: none
@bors retry |
Fix incorrect swap suggestion Clippy suggests using swap on fields belonging to the same owner causing two mutable borrows of the owner. Disclosure: This is my first time working with clippy and rusts HIR. I'm very grateful for assistance and suggestions to improve the PR. fixes #981 changelog: Fix false positive in `manual_swap` lint
added changelog. |
💔 Test failed - checks-travis |
@bors retry (Timeout (30 minutes) reached. Terminating "./ci/base-tests.sh") |
Fix incorrect swap suggestion Clippy suggests using swap on fields belonging to the same owner causing two mutable borrows of the owner. Disclosure: This is my first time working with clippy and rusts HIR. I'm very grateful for assistance and suggestions to improve the PR. fixes #981 changelog: Fix false positive in `manual_swap` lint
☀️ Test successful - checks-travis, status-appveyor |
Clippy suggests using swap on fields belonging to the same owner causing two mutable borrows of the owner.
Disclosure: This is my first time working with clippy and rusts HIR. I'm very grateful for assistance and suggestions to improve the PR.
fixes #981
changelog: Fix false positive in
manual_swap
lint