Summary
taking &raw const or &raw mut of a union field is a safe operation, but the lint detects them as additional unsafe operations when put in an unsafe block along with other unsafe operations.
Reproducer
union AorB {
a: i64,
b: u64,
}
#[warn(clippy::multiple_unsafe_ops_per_block)]
fn main() {
let data = AorB { a: -1 };
let access = unsafe { (&raw const data.b).read() };
}
Current output:
emits warning
Desired output:
no warnings
Version
rustc 1.93.0-nightly (6647be936 2025-11-09)
binary: rustc
commit-hash: 6647be93640686a2a443a49f15c3390b68c8b5dd
commit-date: 2025-11-09
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.3
clippy 0.1.93 (6647be9364 2025-11-09)
Additional Labels
No response