Closed
Description
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