Closed
Description
Summary
When a single-line unsafe block is long enough to be formatted on a new line,
it appears that the safety comment isn't found.
Lint Name
undocumented_unsafe_blocks
Reproducer
I tried this code:
#![deny(clippy::undocumented_unsafe_blocks)]
fn main() {
let aaaaaa = 1;
// SAFETY: A safety comment
let _some_var_name =
unsafe { path::to::aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaa, A::CONTEXT_INFO) };
}
pub(crate) mod path {
pub(crate) mod to {
pub(crate) unsafe fn aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(_: u32, _: ()) -> u32{
1
}
}
}
struct A {}
impl A {
const CONTEXT_INFO: () = ();
}
I saw this happen:
error: unsafe block missing a safety comment
--> src/main.rs:7:9
|
7 | unsafe { path::to::aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaa, A::CONTEXT_INFO) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding a safety comment on the preceding line
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#undocumented_unsafe_blocks
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![deny(clippy::undocumented_unsafe_blocks)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I expected to see this happen:
Lint shouldn't fire
Version
rustc 1.71.0-nightly (1c42cb4ef 2023-04-26)
binary: rustc
commit-hash: 1c42cb4ef0544fbfaa500216e53382d6b079c001
commit-date: 2023-04-26
host: x86_64-pc-windows-msvc
release: 1.71.0-nightly
LLVM version: 16.0.2
Additional Labels
No response