1
1
// stderr-per-bitwidth
2
2
// ignore-endian-big
3
3
// ignore-tidy-linelength
4
- // ignore-debug debug assertions catch some UB too early
5
4
// normalize-stderr-test "╾─*ALLOC[0-9]+(\+[a-z0-9]+)?─*╼" -> "╾ALLOC_ID$1╼"
6
5
7
6
#![ feature( never_type, rustc_attrs, ptr_metadata, slice_from_ptr_range, const_slice_from_ptr_range) ]
@@ -13,6 +12,8 @@ use std::ptr::NonNull;
13
12
use std:: num:: { NonZeroU8 , NonZeroUsize } ;
14
13
use std:: slice:: { from_ptr_range, from_raw_parts} ;
15
14
15
+ // # Bad enums and chars
16
+
16
17
#[ repr( usize ) ]
17
18
#[ derive( Copy , Clone ) ]
18
19
enum Enum {
@@ -51,6 +52,7 @@ const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8)
51
52
const BAD_OPTION_CHAR : Option < ( char , char ) > = Some ( ( 'x' , unsafe { mem:: transmute ( !0u32 ) } ) ) ;
52
53
//~^ ERROR is undefined behavior
53
54
55
+ // # Bad pointers and references
54
56
55
57
const NULL_PTR : NonNull < u8 > = unsafe { mem:: transmute ( 0usize ) } ;
56
58
//~^ 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
197
199
const RAW_TRAIT_OBJ_VTABLE_INVALID : * const dyn Trait = unsafe { mem:: transmute ( ( & 92u8 , & 3u64 ) ) } ;
198
200
//~^ ERROR it is undefined behavior to use this value
199
201
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
210
203
const _: & [ !; 1 ] = unsafe { & * ( 1_usize as * const [ !; 1 ] ) } ; //~ ERROR undefined behavior
211
204
const _: & [ !] = unsafe { & * ( 1_usize as * const [ !; 1 ] ) } ; //~ ERROR undefined behavior
212
205
const _: & [ !] = unsafe { & * ( 1_usize as * const [ !; 42 ] ) } ; //~ ERROR undefined behavior
0 commit comments