Skip to content

clippy::multiple-unsafe-ops-per-block: detects safe operation as unsafe #16076

@Paladynee

Description

@Paladynee

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thing

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions