rust-lang / rust-lang/rust-clippy
`undocumented_unsafe_blocks` false positive despite `accept-comment-above-attributes = true`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
undocumented_unsafe_blocks fires when attribute follows safety comment even though accept-comment-above-attributes = true is set in clippy.toml.
See https://github.com/google/zerocopy/pull/2753 for full context and another example of the failure.
Lint Name
undocumented_unsafe_blocks
Reproducer
I tried this code:
// We use `transmute` instead of an `as` cast since Miri (with strict
// provenance enabled) notices and complains that an `as` cast creates a
// pointer with no provenance. Miri isn't smart enough to realize that
// we're only executing this branch when we're constructing a zero-sized
// `Box`, which doesn't require provenance.
//
// SAFETY: any initialized bit sequence is a bit-valid `*mut u8`. All
// bits of a `usize` are initialized.
#[allow(unknown_lints)] // For `integer_to_ptr_transmutes`
#[allow(clippy::useless_transmute, integer_to_ptr_transmutes)]
let dangling = unsafe { mem::transmute::<usize, *mut u8>(align) };
I saw this happen:
error: unsafe block missing a safety comment
--> src/util/mod.rs:375:24
|
375 | let dangling = unsafe { mem::transmute::<usize, *mut u8>(align) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#undocumented_unsafe_blocks
note: the lint level is defined here
--> src/lib.rs:272:5
|
272 | clippy::undocumented_unsafe_blocks,
|
I expected to see this happen:
No lint triggered
Version
rustc 1.93.0-nightly (20383c9f1 2025-11-03)
binary: rustc
commit-hash: 20383c9f1d84eb9b9c6668a1668ef68a81eae274
commit-date: 2025-11-03
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.3
Here's the toolchain version we're running on main, where this failure is not showing up. Presumably this is a regression introduced between these two toolchain versions.
rustc 1.92.0-nightly (53a741fc4 2025-10-16)
binary: rustc
commit-hash: 53a741fc4b8cf2d8e7b1b2336ed8edf889db84f4
commit-date: 2025-10-16
host: x86_64-unknown-linux-gnu
release: 1.92.0-nightly
LLVM version: 21.1.3
Additional Labels
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the undocumented_unsafe_blocks diagnostic with the supplied code and accept-comment-above-attributes = true, comparing the Rust 1.92 and 1.93 nightly toolchains. Trace the lint's handling of safety comments above attributes and add a regression test; done means the reproducer emits no lint with that configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100