diff options
Diffstat (limited to 'tests/ui/unsafe/ranged_ints_const.rs')
-rw-r--r-- | tests/ui/unsafe/ranged_ints_const.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/ui/unsafe/ranged_ints_const.rs b/tests/ui/unsafe/ranged_ints_const.rs new file mode 100644 index 000000000..472b09681 --- /dev/null +++ b/tests/ui/unsafe/ranged_ints_const.rs @@ -0,0 +1,14 @@ +// revisions: mir thir +// [thir]compile-flags: -Z thir-unsafeck + +#![feature(rustc_attrs)] + +#[rustc_layout_scalar_valid_range_start(1)] +#[repr(transparent)] +pub(crate) struct NonZero<T>(pub(crate) T); +fn main() {} + +const fn foo() -> NonZero<u32> { NonZero(0) } +//~^ ERROR initializing type with `rustc_layout_scalar_valid_range` attr is unsafe + +const fn bar() -> NonZero<u32> { unsafe { NonZero(0) } } |