You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is somewhat annoying when the project uses minimal-scope unsafe blocks. I would prefer for the lint to only trigger if the previous line from the word unsafe is not part of a // Safety comment. Currently it requires that the comment directly precede the unsafe token, which leads to a false positive witth very awkward formatting in the suggestion.
#![warn(clippy::undocumented_unsafe_blocks)]fnmain(){let x = &0as*const_;// Safety: x points to a valid valueprintln!("{}",unsafe{*x })}
warning: unsafe block missing a safety comment
--> src/main.rs:6:19
|
6 | println!("{}", unsafe { *x })
| ^^^^^^^^^^^^^
|
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![warn(clippy::undocumented_unsafe_blocks)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#undocumented_unsafe_blocks
help: consider adding a safety comment
|
6 ~ println!("{}", // SAFETY: ...
7 ~ unsafe { *x })
|
it only looks for comments in the enclosing scope. One way to fix this would be to keep going up the syntax tree until you find an enclosing scope that starts on a line different from the unsafe block itself. That would allow things like:
fnmain(){// Safety: <- too far away to count{// <- this is the enclosing scope within which safety comments are permitted// Safety: <- safety comment permitted here let x = {unsafe{foo()}};// <- surrounding block scope is ignored because it starts on same line}}
In principle this can be checked by the
clippy::undocumented_unsafe_blocks lint, and I used the lint to find
the issues. In practice the lint is buggy and so cannot safely be
enabled in CI. Hopefully it will be fixed within a few stable version
releases; keep your eyes on
rust-lang/rust-clippy#8449 .
Description
This is somewhat annoying when the project uses minimal-scope
unsafe
blocks. I would prefer for the lint to only trigger if the previous line from the wordunsafe
is not part of a// Safety
comment. Currently it requires that the comment directly precede theunsafe
token, which leads to a false positive witth very awkward formatting in the suggestion.Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: