Skip to content

Lint for unsafe code style tips #1554

@F001

Description

@F001

In unsafe block, it is very easy to make a bunch of mistakes which rustc can't detect.
A few examples from my head:

  1. transmuting &T to *mut T or &mut T.
    Just like std::vec::IntoIter::as_mut_slice borrows &self, returns &mut of contents. rust#39465 showed, even experienced programmers may overlook this kind of errors. Glad to see the progress here: https://github.com/Manishearth/rust-clippy/pull/1528.

  2. types based on Unique<T> should not allow alias
    Example: LinkedList implementation violates aliasing rules rust#34417.

  3. types containing raw pointers probably need a PhantomData field

  4. Raw pointers which are never assigned by null, could be wrapped in NonZero

This list could be very long. These kind of issues are vital to memory safety.

My intent of this issue is to discuss what kind of checkers could be added into our backlist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions