Lint request: Safety comment on safe code · Issue #6880 · rust-lang/rust-clippy (original) (raw)

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.