File tree Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Original file line number Diff line number Diff line change 1
1
//error-pattern: invalid use of NULL pointer
2
+ #![ feature( intrinsics) ]
3
+
4
+ // Directly call intrinsic to avoid debug assertions in libstd
5
+ extern "rust-intrinsic" {
6
+ fn copy_nonoverlapping < T > ( src : * const T , dst : * mut T , count : usize ) ;
7
+ }
2
8
3
9
fn main ( ) {
4
10
let mut data = [ 0u16 ; 4 ] ;
5
11
let ptr = & mut data[ 0 ] as * mut u16 ;
6
12
// Even copying 0 elements from NULL should error.
7
- unsafe { ptr . copy_from ( std:: ptr:: null ( ) , 0 ) ; }
13
+ unsafe { copy_nonoverlapping ( std:: ptr:: null ( ) , ptr , 0 ) ; }
8
14
}
Original file line number Diff line number Diff line change 1
- #![ feature( core_intrinsics) ]
2
-
3
1
//error-pattern: copy_nonoverlapping called on overlapping ranges
2
+ #![ feature( intrinsics) ]
3
+
4
+ // Directly call intrinsic to avoid debug assertions in libstd
5
+ extern "rust-intrinsic" {
6
+ fn copy_nonoverlapping < T > ( src : * const T , dst : * mut T , count : usize ) ;
7
+ }
4
8
5
9
fn main ( ) {
6
10
let mut data = [ 0u8 ; 16 ] ;
7
11
unsafe {
8
12
let a = data. as_mut_ptr ( ) ;
9
13
let b = a. wrapping_offset ( 1 ) as * mut _ ;
10
- std :: ptr :: copy_nonoverlapping ( a, b, 2 ) ;
14
+ copy_nonoverlapping ( a, b, 2 ) ;
11
15
}
12
16
}
Original file line number Diff line number Diff line change 1
1
//error-pattern: tried to access memory with alignment 1, but alignment 2 is required
2
+ #![ feature( intrinsics) ]
3
+
4
+ // Directly call intrinsic to avoid debug assertions in libstd
5
+ extern "rust-intrinsic" {
6
+ fn copy_nonoverlapping < T > ( src : * const T , dst : * mut T , count : usize ) ;
7
+ }
2
8
3
9
fn main ( ) {
4
10
let mut data = [ 0u16 ; 8 ] ;
5
11
let ptr = ( & mut data[ 0 ] as * mut u16 as * mut u8 ) . wrapping_add ( 1 ) as * mut u16 ;
6
12
// Even copying 0 elements to something unaligned should error
7
- unsafe { ptr . copy_from ( & data[ 5 ] , 0 ) ; }
13
+ unsafe { copy_nonoverlapping ( & data[ 5 ] , ptr , 0 ) ; }
8
14
}
You can’t perform that action at this time.
0 commit comments