Skip to content

Suggest std::ptr::swap(a, b) instead of std::mem::swap(&mut *a, &mut *b) #7381

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

Closed
Tracked by #79
vihdzp opened this issue Jun 20, 2021 · 0 comments · Fixed by #8916
Closed
Tracked by #79

Suggest std::ptr::swap(a, b) instead of std::mem::swap(&mut *a, &mut *b) #7381

vihdzp opened this issue Jun 20, 2021 · 0 comments · Fixed by #8916
Labels
A-lint Area: New lints

Comments

@vihdzp
Copy link

vihdzp commented Jun 20, 2021

What it does

This lint would find instances of a user converting two pointers into mutable references and calling swap on them. It would error upon finding them.

By the way, this mistake is an actual thing I once saw on production code: dimforge/nalgebra#919

Categories

  • Kind: clippy::correctness.

What is the advantage of the recommended code over the original code

If a and b are equal or overlap, the original code is actually UB, while the latter isn't.

Drawbacks

None that I can think of.

@vihdzp vihdzp added the A-lint Area: New lints label Jun 20, 2021
@bors bors closed this as completed in f0bf200 May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant