Skip to content

unnecessary_safety_comment does not lint the first item of a module without a body #14554

Open
@ojeda

Description

@ojeda

Summary

unnecessary_safety_comment does not lint the first item inside a module without a body (i.e. loaded from a file).

Possibly related: #14553.
Possibly related: #14555.
Possibly related: #14556.

Lint Name

unnecessary_safety_comment

Reproducer

https://godbolt.org/z/776jh93s8

I tried this code:

File a.rs:

mod b;

File b.rs:

// This line should avoid #14553.

// SAFETY: ...
mod x {}

// SAFETY: ...
mod y {}

I expected to see this happen: Two lints, for both safety comments.

Instead, this happened: Only the comment on y is linted.

Note that there is no false negative if we embed module b:

mod b {
    // This line should avoid #14553.

    // SAFETY: ...
    mod x {}

    // SAFETY: ...
    mod y {}
}

Version

rustc 1.86.0 (05f9846f8 2025-03-31)
rustc 1.88.0-nightly (17ffbc81a 2025-04-04)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions