Lint for reading entire struct instead of field
⚓ Rust 📅 2025-07-10 👤 surdeus 👁️ 16When writing unsafe code you may accidentally write this:
#[derive(Copy,Clone)]
struct Foo {
field: u32,
field2: u16,
}
fn foo(ptr: *const Foo) -> u32 {
unsafe { *ptr }.field
}
The foo function unfortunately reads the entire struct Foo and then reads field from the copy of Foo. The user probably meant to write unsafe { (*ptr).field }. Is there a clippy lint for this scenario?
2 posts - 2 participants
🏷️ rust_feed