11// stderr-per-bitwidth
22// ignore-endian-big
33// ignore-tidy-linelength
4- // ignore-debug debug assertions catch some UB too early
54// normalize-stderr-test "╾─*ALLOC[0-9]+(\+[a-z0-9]+)?─*╼" -> "╾ALLOC_ID$1╼"
65
76#![ feature( never_type, rustc_attrs, ptr_metadata, slice_from_ptr_range, const_slice_from_ptr_range) ]
@@ -13,6 +12,8 @@ use std::ptr::NonNull;
1312use std:: num:: { NonZeroU8 , NonZeroUsize } ;
1413use std:: slice:: { from_ptr_range, from_raw_parts} ;
1514
15+ // # Bad enums and chars
16+
1617#[ repr( usize ) ]
1718#[ derive( Copy , Clone ) ]
1819enum Enum {
@@ -51,6 +52,7 @@ const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8)
5152const BAD_OPTION_CHAR : Option < ( char , char ) > = Some ( ( 'x' , unsafe { mem:: transmute ( !0u32 ) } ) ) ;
5253//~^ ERROR is undefined behavior
5354
55+ // # Bad pointers and references
5456
5557const NULL_PTR : NonNull < u8 > = unsafe { mem:: transmute ( 0usize ) } ;
5658//~^ ERROR it is undefined behavior to use this value
@@ -197,16 +199,7 @@ const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute((&92
197199const RAW_TRAIT_OBJ_VTABLE_INVALID : * const dyn Trait = unsafe { mem:: transmute ( ( & 92u8 , & 3u64 ) ) } ;
198200//~^ ERROR it is undefined behavior to use this value
199201
200-
201- // not ok, since alignment needs to be non-zero.
202- const LAYOUT_INVALID_ZERO : Layout = unsafe { Layout :: from_size_align_unchecked ( 0x1000 , 0x00 ) } ;
203- //~^ ERROR it is undefined behavior to use this value
204-
205- // not ok, since alignment needs to be a power of two.
206- const LAYOUT_INVALID_THREE : Layout = unsafe { Layout :: from_size_align_unchecked ( 9 , 3 ) } ;
207- //~^ ERROR it is undefined behavior to use this value
208-
209-
202+ // Uninhabited types
210203const _: & [ !; 1 ] = unsafe { & * ( 1_usize as * const [ !; 1 ] ) } ; //~ ERROR undefined behavior
211204const _: & [ !] = unsafe { & * ( 1_usize as * const [ !; 1 ] ) } ; //~ ERROR undefined behavior
212205const _: & [ !] = unsafe { & * ( 1_usize as * const [ !; 42 ] ) } ; //~ ERROR undefined behavior
0 commit comments