RS.CLIPPY.UNNECESSARY_SAFETY_COMMENT

Annotating safe code with a safety comment

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: unnecessary_safety_comment. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for // SAFETY: comments on safe code.

Why restrict this?

Safe code has no safety requirements, so there is no need to describe safety invariants.

Example

use std::ptr::NonNull;
let a = &mut 42;

// SAFETY: references are guaranteed to be non-null.
let ptr = NonNull::new(a).unwrap();

Use instead:

use std::ptr::NonNull;
let a = &mut 42;

let ptr = NonNull::new(a).unwrap();