]> git.lizzy.rs Git - rust.git/blob - src/test/ui/unsafe/ranged_ints2_const.rs
Auto merge of #87044 - cjgillot:expnhash, r=petrochenkov
[rust.git] / src / test / ui / unsafe / ranged_ints2_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
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
16     unsafe { NonZero(1) }
17 }
18
19 const fn bar() -> NonZero<u32> {
20     let mut x = unsafe { NonZero(1) };
21     let y = unsafe { &mut x.0 }; //~ ERROR mutable references
22     unsafe { NonZero(1) }
23 }
24
25 const fn boo() -> NonZero<u32> {
26     let mut x = unsafe { NonZero(1) };
27     unsafe { let y = &mut x.0; } //~ ERROR mutable references
28     unsafe { NonZero(1) }
29 }