Skip to content

Lint request: Safety comment on safe code #6880

@alice-i-cecile

Description

@alice-i-cecile

What it does

Warns when a SAFETY comment is left on a safe function, trait etc.

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

Avoids users accidentally using unsafe code in an inappropriate fashion because it's marked safe.

Drawbacks

Won't work on normal comments, see #4828.

Example

/// Safety: This function must be used very carefully 
pub fn my_fn(){
}

Should be written as:

/// Safety: This function must be used very carefully 
pub unsafe fn my_fn(){
}

Here's an example of where this slipped through into real code.

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