#![allow(unknown_lints, renamed_and_removed_lints)]
#![forbid(unaligned_references, safe_packed_borrows)]
#![allow(clippy::thread_local_initializer_can_be_made_const)]
use std::cell::Cell;
#[test]
fn weird_repr_packed() {
thread_local! {
static FIELD_ADDR: Cell<usize> = Cell::new(0);
}
#[repr(packed)]
struct Struct {
field: u8,
}
impl Drop for Struct {
fn drop(&mut self) {
FIELD_ADDR.with(|f| {
f.set(&self.field as *const u8 as usize);
});
}
}
let field_addr = {
let x = Struct { field: 27 };
&x.field as *const u8 as usize
};
assert_eq!(field_addr, FIELD_ADDR.with(Cell::get));
}