Skip to content

Newline in assignment causes false negative in undocumented_unsafe_blocks #11534

Closed
@joshlf

Description

@joshlf

Summary

When a newline separates the = sign and the beginning of an unsafe block (as rustfmt sometimes produces), Clippy doesn't recognize a safety comment as decorating the unsafe block:

// SAFETY: ...
let x =
    unsafe { ... };

Lint Name

undocumented_unsafe_blocks

Reproducer

I tried this code:

#![deny(clippy::undocumented_unsafe_blocks)]

fn main() {
    // SAFETY: No unsafe code here!
    let _x =
        unsafe { 0 };
    // SAFETY: No unsafe code here!
    let _y = unsafe { 0 };
}

I expected to see this happen:

Both unsafe blocks should have been recognized as having a safety comment.

Instead, this happened:

undocumented_unsafe_blocks fired on let _x = ....

Version

1.72 (stable)

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