[−][src]Static rustc_ap_rustc_lint_defs::builtin::UNALIGNED_REFERENCES
pub static UNALIGNED_REFERENCES: &Lint
The unaligned_references
lint detects unaligned references to fields
of packed structs.
Example
ⓘThis example deliberately fails to compile
#![deny(unaligned_references)] #[repr(packed)] pub struct Foo { field1: u64, field2: u8, } fn main() { unsafe { let foo = Foo { field1: 0, field2: 0 }; let _ = &foo.field1; } }
{{produces}}
Explanation
Creating a reference to an insufficiently aligned packed field is undefined behavior and should be disallowed.
This lint is "allow" by default because there is no stable alternative, and it is not yet certain how widespread existing code will trigger this lint.
See issue #27060 for more discussion.