Skip to content

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

Closed
@vihdzp

Description

@vihdzp

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions