Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Lint for reading entire struct instead of field
When 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