#![warn(unsafe_code)]
#![warn(rust_2018_idioms)]
#![allow(dead_code)]
use std::cell::Cell;
#[test]
fn weird_repr_packed() {
thread_local! {
static FIELD_ADDR: Cell<usize> = Cell::new(0);
}
#[repr(packed)]
struct Foo {
field: u8,
}
impl Drop for Foo {
fn drop(&mut self) {
FIELD_ADDR.with(|f| {
f.set(&self.field as *const u8 as usize);
})
}
}
let field_addr = {
let foo = Foo { field: 27 };
let field_addr = &foo.field as *const u8 as usize;
field_addr
};
assert_eq!(field_addr, FIELD_ADDR.with(|f| f.get()));
}