Static rustc_ap_rustc_lint_defs::builtin::SAFE_PACKED_BORROWS[][src]

pub static SAFE_PACKED_BORROWS: &Lint

The safe_packed_borrows lint detects borrowing a field in the interior of a packed structure with alignment other than 1.

Example

#[repr(packed)]
pub struct Unaligned<T>(pub T);

pub struct Foo {
    start: u8,
    data: Unaligned<u32>,
}

fn main() {
    let x = Foo { start: 0, data: Unaligned(1) };
    let y = &x.data.0;
}

{{produces}}

Explanation

This type of borrow is unsafe and can cause errors on some platforms and violates some assumptions made by the compiler. This was previously allowed unintentionally. This is a future-incompatible lint to transition this to a hard error in the future. See issue #46043 for more details, including guidance on how to solve the problem.