]> git.lizzy.rs Git - rust.git/blob - src/test/ui/unsafe/ranged_ints3_const.rs
Add tests for stable unsafe features in const fn
[rust.git] / src / test / ui / unsafe / ranged_ints3_const.rs
1 #![feature(rustc_attrs, const_let, const_fn)]
2
3 use std::cell::Cell;
4
5 #[rustc_layout_scalar_valid_range_start(1)]
6 #[repr(transparent)]
7 pub(crate) struct NonZero<T>(pub(crate) T);
8 fn main() {}
9
10 const fn foo() -> NonZero<Cell<u32>> {
11     let mut x = unsafe { NonZero(Cell::new(1)) };
12     let y = &x.0; //~ ERROR cannot borrow a constant which may contain interior mutability
13     //~^ ERROR borrow of layout constrained field with interior mutability
14     unsafe { NonZero(Cell::new(1)) }
15 }
16
17 const fn bar() -> NonZero<Cell<u32>> {
18     let mut x = unsafe { NonZero(Cell::new(1)) };
19     let y = unsafe { &x.0 }; //~ ERROR cannot borrow a constant which may contain interior mut
20     unsafe { NonZero(Cell::new(1)) }
21 }