Description
Summary
unnecessary_safety_comment
appears to detect /// SAFETY: ...
as a safety comment (i.e. not # Safety
section) in a normal function, but it doesn't inside an impl
block.
Lint Name
unnecessary_safety_comment
Reproducer
I tried this code:
/// SAFETY: ...
fn f() {}
and it triggers unnecessary_safety_comment
. However, this:
struct S;
impl S {
/// SAFETY: ...
fn f() {}
}
does not trigger it.
I assume unnecessary_safety_comment
is intended to only lint on actual safety comments (i.e. not safety docs/sections), even if they use ///
instead of //
. If so, then the former is expected, and the latter is a false negative.
Please also see this other suggested lint for consistency on safety comments/docs: #15033. For instance, if the former case above were to be a false positive, one could use that new/suggested lint to catch a case like this where the function was supposed to be unsafe fn
. And if the former is indeed expected, then perhaps the message of the lint could be clarified if the user used ///
instead of just //
.
More combinations: https://godbolt.org/z/43onqxYrh
Version
rustc 1.89.0-nightly (d13a431a6 2025-06-09)
binary: rustc
commit-hash: d13a431a6cc69cd65efe7c3eb7808251d6fd7a46
commit-date: 2025-06-09
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5