File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
tests/compile-fail/unaligned_pointers Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change 4
4
use std:: ptr;
5
5
6
6
fn main ( ) {
7
- let x = [ 2u16 , 3 , 4 ] ; // Make it big enough so we don't get an out-of-bounds error.
8
- let x = & x[ 0 ] as * const _ as * const u32 ;
9
- // This must fail because alignment is violated: the allocation's base is not sufficiently aligned.
10
- // The deref is UB even if we just put the result into a raw pointer.
11
- let _x = unsafe { ptr:: raw_const!( * x) } ; //~ ERROR memory with alignment 2, but alignment 4 is required
7
+ for _ in 0 ..10 { // Try many times as this might work by chance.
8
+ let x = [ 2u16 , 3 , 4 ] ; // Make it big enough so we don't get an out-of-bounds error.
9
+ let x = & x[ 0 ] as * const _ as * const u32 ;
10
+ // This must fail because alignment is violated: the allocation's base is not sufficiently aligned.
11
+ // The deref is UB even if we just put the result into a raw pointer.
12
+ let _x = unsafe { ptr:: raw_const!( * x) } ; //~ ERROR memory with alignment 2, but alignment 4 is required
13
+ }
12
14
}
You can’t perform that action at this time.
0 commit comments