1 // revisions: mirunsafeck thirunsafeck
2 // [thirunsafeck]compile-flags: -Z thir-unsafeck
4 #![feature(rustc_attrs)]
6 #[rustc_layout_scalar_valid_range_start(1)]
8 pub(crate) struct NonZero<T>(pub(crate) T);
12 const fn foo() -> NonZero<u32> {
13 let mut x = unsafe { NonZero(1) };
14 let y = &mut x.0; //~ ERROR mutable references
15 //~^ ERROR mutation of layout constrained field is unsafe
19 const fn bar() -> NonZero<u32> {
20 let mut x = unsafe { NonZero(1) };
21 let y = unsafe { &mut x.0 }; //~ ERROR mutable references
25 const fn boo() -> NonZero<u32> {
26 let mut x = unsafe { NonZero(1) };
27 unsafe { let y = &mut x.0; } //~ ERROR mutable references