1 // revisions: mirunsafeck thirunsafeck
2 // [thirunsafeck]compile-flags: -Z thir-unsafeck
4 #![feature(rustc_attrs)]
5 #![allow(unused,dead_code)]
8 #[rustc_layout_scalar_valid_range_start(1)]
11 let mut foo = unsafe { NonZero((1,)) };
13 //~^ ERROR: mutation of layout constrained field is unsafe
17 #[rustc_layout_scalar_valid_range_start(1)]
18 struct NonZero<'a, T>(&'a mut [T]);
20 let mut nums = [1, 2, 3, 4];
21 let mut foo = unsafe { NonZero(&mut nums[..]) };
22 let a = &mut foo.0[2];
23 // ^ not unsafe because there is an implicit dereference here
27 #[rustc_layout_scalar_valid_range_start(1)]
28 struct NonZero<T>([T; 4]);
30 let nums = [1, 2, 3, 4];
31 let mut foo = unsafe { NonZero(nums) };
32 let a = &mut foo.0[2];
33 //~^ ERROR: mutation of layout constrained field is unsafe
37 #[rustc_layout_scalar_valid_range_start(1)]
40 let foo = unsafe { NonZero((1,)) };
42 // ^ not unsafe because the result of the block expression is a new place
46 #[rustc_layout_scalar_valid_range_start(1)]
49 let mut foo = unsafe { NonZero((1,)) };
51 NonZero((a,)) => *a = 0,
52 //~^ ERROR: mutation of layout constrained field is unsafe