]> git.proxmox.com Git - rustc.git/blob - src/test/ui/unsafe/ranged_ints4_const.rs
Update unsuspicious file list
[rustc.git] / src / test / ui / unsafe / ranged_ints4_const.rs
1 // revisions: mirunsafeck thirunsafeck
2 // [thirunsafeck]compile-flags: -Z thir-unsafeck
3
4 #![feature(rustc_attrs)]
5
6 #[rustc_layout_scalar_valid_range_start(1)]
7 #[repr(transparent)]
8 pub(crate) struct NonZero<T>(pub(crate) T);
9 fn main() {}
10
11 const fn foo() -> NonZero<u32> {
12 let mut x = unsafe { NonZero(1) };
13 x.0 = 0;
14 //~^ ERROR mutation of layout constrained field is unsafe
15 x
16 }
17
18 const fn bar() -> NonZero<u32> {
19 let mut x = unsafe { NonZero(1) };
20 unsafe { x.0 = 0 }; // this is UB
21 x
22 }