Skip to content

Regression: undocumented_unsafe_blocks false positive on a multi-line attribute between // SAFETY and unsafe #15915

@purplesyringa

Description

@purplesyringa

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions