Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clippy::undocumented_unsafe_blocks reports incorrectly when statement spilt onto multiple lines #11311

Closed
ShakenCodes opened this issue Aug 9, 2023 · 2 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@ShakenCodes
Copy link

Summary

Having code with an unsafe block that splits the unsafe statement onto multiple lines, erroneously reports there is an clippy::undocumented_unsafe_blocks issue.

The code before running "cargo fmt" which generates no clippy issue:

    // Safety: My notes about safety
    let my_really_long_name_in_deep_nesting = unsafe { *my_pointer_into_a_c_data_structure };

The code after running "cargo fmt" which generates a false positive clippy issue:

    // Safety: My notes about safety
    let my_really_long_name_in_deep_nesting
        = unsafe { *my_pointer_into_a_c_data_structure };

Note that moving the safety comment down one line (into the middle of the statement) does eliminate the clippy error report. However, this is disruptive to the readability of the code. Also, it is undesirable that running "cargo fmt" causes different behavior in clippy:

    let my_really_long_name_in_deep_nesting
        // Safety: My notes about safety
        = unsafe { *my_pointer_into_a_c_data_structure };

Lint Name

clippy::undocumented_unsafe_blocks

Reproducer

I tried this code:

    // Safety: My notes about safety
    let my_really_long_name_in_deep_nesting
        = unsafe { *my_pointer_into_a_c_data_structure };

I saw this happen:

error: unsafe block missing a safety comment

I expected to see this happen:
No error

Version

rustc 1.72.0-nightly (871b59520 2023-05-31)
binary: rustc
commit-hash: 871b5952023139738f72eba235063575062bc2e9
commit-date: 2023-05-31
host: aarch64-apple-darwin
release: 1.72.0-nightly
LLVM version: 16.0.4

Additional Labels

No response

@ShakenCodes ShakenCodes added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Aug 9, 2023
@Centri3
Copy link
Member

Centri3 commented Aug 9, 2023

Please try this with the accept-comment-above-statement configuration option enabled. Unless there's a bug in that this should be exactly what you're after

@Alexendoo
Copy link
Member

Fixed by #11170

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

3 participants