-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Summary
unnecessary_safety_comment
and undocumented_unsafe_blocks
have an accept-comment-above-attributes
configuration, signaling that SAFETY
comments can be accepted or looked for above attributes. However, this changes the semantics of the lint, only looking for comments above the topmost attribute.
For example, the following code only lints if accept-comment-above-attributes
is false:
fn foo() {
#[doc(hidden)]
// SAFETY: ...
let x = 34;
}
As far as I understand, that's a bug rather than the config indicating that SAFETY
comments are only looked for above attributes, since if that were the case there's code that won't lint in any configuration:
fn foo() {
#[doc(hidden)]
// SAFETY: ...
#[must_use]
let x = 34;
}
Reproducer
I tried this code:
fn foo() {
#[doc(hidden)]
// SAFETY: ...
let x = 34;
}
I expected to see this happen:
A lint indicating an unnecessary_safety_comment
occured.
Instead, this happened:
No lint
https://godbolt.org/z/v7xTozs6h
Version
rustc 1.92.0-nightly (4645a7988 2025-09-17)
binary: rustc
commit-hash: 4645a7988177c286f61609cc667ecae4c571a2e8
commit-date: 2025-09-17
host: aarch64-apple-darwin
release: 1.92.0-nightly
LLVM version: 21.1.1
Additional Labels
No response