You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
What is the operational semantics of Box derefs? #617
#[repr(align(8))]structS{f:(),}fnmain(){letmut x = Box::new(S{f:()});unsafe{(&rawmut x).cast::<usize>().write(1)};let _val = &(*x).f;}
This is because the *x desugars to projecting to the underlying NonNull inside the Box, and then deref'ing that. That is UB if the pointer is null, but does not care about alignment.
Basically, this is where Box behaves more like a library type than a language type. That nicely avoids Miri having to deal with the custom allocator on a Box, but it also means we are losing some information on the opsem level.
I feel like we should probably preserve the actual Box deref for Miri so that we can fully check this case for UB.
Something similar happens with Boxes that are not dereferenceable:
#[repr(C)]structS{a:(),b:i8,}fnmain(){letmut x = Box::new(S{a:(),b:0});unsafe{(&rawmut x).cast::<usize>().write(16)};let _val = x.a;//~ERROR: must be dereferenceable for 1 byte, but got 0x10[noalloc] which is a dangling pointer}
Activity
RalfJung commentedon Jul 26, 2026
Something similar happens with
Boxes that are not dereferenceable:Rollup merge of rust-lang#160012 - RalfJung:deref-validity, r=oli-obk
Rollup merge of rust-lang#160012 - RalfJung:deref-validity, r=oli-obk
Rollup merge of rust-lang#160012 - RalfJung:deref-validity, r=oli-obk
Rollup merge of rust-lang#160012 - RalfJung:deref-validity, r=oli-obk
Unrolled build for #160012
Rollup merge of #160012 - RalfJung:deref-validity, r=oli-obk
Rollup merge of #160012 - RalfJung:deref-validity, r=oli-obk
Rollup merge of #160012 - RalfJung:deref-validity, r=oli-obk
Rollup merge of #160012 - RalfJung:deref-validity, r=oli-obk
Rollup merge of rust-lang#160012 - RalfJung:deref-validity, r=oli-obk
Rollup merge of #160012 - RalfJung:deref-validity, r=oli-obk