rust-lang / rust-lang/rust-clippy
Regression: `undocumented_unsafe_blocks` false positive on a multi-line attribute between // SAFETY and `unsafe`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
Seems to be a recent regression. I'm not sure what the release cycle for clippy is, but it has appreared in rustup's nightly within the last week. Maybe due to #15678?
Lint Name
undocumented_unsafe_blocks
Reproducer
I tried this code:
#![warn(clippy::undocumented_unsafe_blocks)]
unsafe fn f() {}
fn main() {
// SAFETY: trust me
#[allow(
unused // can be any lint
)]
unsafe {
f();
}
}
I saw this happen:
warning: unsafe block missing a safety comment
--> src/main.rs:10:5
|
10 | unsafe {
| ^^^^^^^^
|
= 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/main.rs:1:9
|
1 | #![warn(clippy::undocumented_unsafe_blocks)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I expected to see this happen:
no warning
Version
clippy 0.1.92 (f04e3dfc87 2025-10-19)
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 running the provided reproducer in src/main.rs with Clippy's undocumented_unsafe_blocks lint enabled. Investigate how the lint handles the multi-line #[allow(...)] attribute between the // SAFETY comment and unsafe block, then add coverage showing that this case produces no warning.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100