File tree Expand file tree Collapse file tree 20 files changed +201
-33
lines changed
tests/ui/precondition-checks Expand file tree Collapse file tree 20 files changed +201
-33
lines changed Original file line number Diff line number Diff line change 1
- ptr::swap_nonoverlapping
2
- ptr::replace
3
- ptr::read
4
- ptr::write
5
- ptr::read_volatile
6
- ptr::write_volatile
7
-
8
1
// for range::Range and for ops::Range?
9
2
str::get_unchecked
10
3
str::get_unchecked_mut
@@ -14,19 +7,8 @@ IndexRange::new_unchecked
14
7
char::from_u32_unchecked
15
8
ascii::Char::digit_unchecked
16
9
17
- ptr::copy
18
- ptr::write_bytes
19
-
20
- slice::from_raw_parts
21
- slice::from_raw_parts_mut
22
-
23
10
unchecked_add
24
11
unchecked_sub
25
12
unchecked_mul
26
13
unchecked_shr
27
14
unchecked_shl
28
-
29
- NonZero::from_mut_unchecked
30
-
31
- unreachable_unchecked
32
- assert_unchecked
Original file line number Diff line number Diff line change 1
1
//@ run-fail
2
2
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
3
- //@ error-pattern: unsafe precondition(s) violated: Alignment::new_unchecked
4
- //@ ignore-debug
3
+ //@ error-pattern: unsafe precondition(s) violated: Alignment::new_unchecked requires
5
4
6
5
#![ feature( ptr_alignment_type) ]
7
6
Original file line number Diff line number Diff line change
1
+ //@ run-fail
2
+ //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
3
+ //@ error-pattern: unsafe precondition(s) violated: hint::assert_unchecked must never be called when the condition is false
4
+
5
+ fn main ( ) {
6
+ unsafe {
7
+ std:: hint:: assert_unchecked ( false ) ;
8
+ }
9
+ }
Original file line number Diff line number Diff line change 1
1
//@ run-fail
2
2
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
3
- //@ error-pattern: unsafe precondition(s) violated: ptr::copy_nonoverlapping
4
- //@ ignore-debug
3
+ //@ error-pattern: unsafe precondition(s) violated: ptr::copy_nonoverlapping requires
5
4
//@ revisions: null_src null_dst misaligned_src misaligned_dst overlapping
6
5
7
6
use std:: ptr;
Original file line number Diff line number Diff line change
1
+ //@ run-fail
2
+ //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
3
+ //@ error-pattern: unsafe precondition(s) violated: ptr::copy requires
4
+ //@ revisions: null_src null_dst misaligned_src misaligned_dst
5
+
6
+ use std:: ptr;
7
+
8
+ fn main ( ) {
9
+ let src = [ 0u16 ; 3 ] ;
10
+ let mut dst = [ 0u16 ; 3 ] ;
11
+ let src = src. as_ptr ( ) ;
12
+ let dst = dst. as_mut_ptr ( ) ;
13
+ unsafe {
14
+ #[ cfg( null_src) ]
15
+ ptr:: copy ( ptr:: null ( ) , dst, 1 ) ;
16
+ #[ cfg( null_dst) ]
17
+ ptr:: copy ( src, ptr:: null_mut ( ) , 1 ) ;
18
+ #[ cfg( misaligned_src) ]
19
+ ptr:: copy ( src. byte_add ( 1 ) , dst, 1 ) ;
20
+ #[ cfg( misaligned_dst) ]
21
+ ptr:: copy ( src, dst. byte_add ( 1 ) , 1 ) ;
22
+ }
23
+ }
Original file line number Diff line number Diff line change 1
1
//@ run-fail
2
2
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
3
- //@ error-pattern: slice::get_unchecked requires
4
- //@ ignore-debug
3
+ //@ error-pattern: unsafe precondition(s) violated: slice::get_unchecked requires
5
4
6
5
fn main ( ) {
7
6
unsafe {
Original file line number Diff line number Diff line change 1
1
//@ run-fail
2
2
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
3
- //@ error-pattern: unsafe precondition(s) violated: Layout::from_size_align_unchecked
4
- //@ ignore-debug
3
+ //@ error-pattern: unsafe precondition(s) violated: Layout::from_size_align_unchecked requires
5
4
//@ revisions: toolarge badalign
6
5
//@[toolarge] compile-flags: --cfg toolarge
7
6
//@[badalign] compile-flags: --cfg badalign
Original file line number Diff line number Diff line change 1
1
//@ run-fail
2
2
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
3
- //@ error-pattern: unsafe precondition(s) violated: NonNull::new_unchecked
4
- //@ ignore-debug
3
+ //@ error-pattern: unsafe precondition(s) violated: NonNull::new_unchecked requires
5
4
6
5
fn main ( ) {
7
6
unsafe {
Original file line number Diff line number Diff line change
1
+ //@ run-fail
2
+ //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
3
+ //@ error-pattern: unsafe precondition(s) violated: NonZero::from_mut_unchecked requires
4
+
5
+ #![ feature( nonzero_from_mut) ]
6
+
7
+ fn main ( ) {
8
+ unsafe {
9
+ let mut num = 0u8 ;
10
+ std:: num:: NonZeroU8 :: from_mut_unchecked ( & mut num) ;
11
+ }
12
+ }
Original file line number Diff line number Diff line change
1
+ //@ run-fail
2
+ //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
3
+ //@ error-pattern: unsafe precondition(s) violated: NonZero::new_unchecked requires
4
+
5
+ fn main ( ) {
6
+ unsafe {
7
+ std:: num:: NonZeroU8 :: new_unchecked ( 0 ) ;
8
+ }
9
+ }
Original file line number Diff line number Diff line change
1
+ //@ run-fail
2
+ //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
3
+ //@ error-pattern: unsafe precondition(s) violated: ptr::read requires
4
+ //@ revisions: null misaligned
5
+ //@ ignore-test
6
+
7
+ use std:: ptr;
8
+
9
+ fn main ( ) {
10
+ let src = [ 0u16 ; 2 ] ;
11
+ let src = src. as_ptr ( ) ;
12
+ unsafe {
13
+ #[ cfg( null) ]
14
+ ptr:: read ( ptr:: null :: < u8 > ( ) ) ;
15
+ #[ cfg( misaligned) ]
16
+ ptr:: read ( src. byte_add ( 1 ) ) ;
17
+ }
18
+ }
Original file line number Diff line number Diff line change
1
+ //@ run-fail
2
+ //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
3
+ //@ error-pattern: unsafe precondition(s) violated: ptr::read_volatile requires
4
+ //@ revisions: null misaligned
5
+
6
+ use std:: ptr;
7
+
8
+ fn main ( ) {
9
+ let src = [ 0u16 ; 2 ] ;
10
+ let src = src. as_ptr ( ) ;
11
+ unsafe {
12
+ #[ cfg( null) ]
13
+ ptr:: read_volatile ( ptr:: null :: < u8 > ( ) ) ;
14
+ #[ cfg( misaligned) ]
15
+ ptr:: read_volatile ( src. byte_add ( 1 ) ) ;
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ //@ run-fail
2
+ //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
3
+ //@ error-pattern: unsafe precondition(s) violated: ptr::replace requires
4
+ //@ revisions: null misaligned
5
+
6
+ use std:: ptr;
7
+
8
+ fn main ( ) {
9
+ let mut dst = [ 0u16 ; 2 ] ;
10
+ let dst = dst. as_mut_ptr ( ) ;
11
+ unsafe {
12
+ #[ cfg( null) ]
13
+ ptr:: replace ( ptr:: null_mut :: < u8 > ( ) , 1 ) ;
14
+ #[ cfg( misaligned) ]
15
+ ptr:: replace ( dst. byte_add ( 1 ) , 1u16 ) ;
16
+ }
17
+ }
Original file line number Diff line number Diff line change 1
1
//@ run-fail
2
2
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
3
- //@ error-pattern: unsafe precondition(s) violated: slice::from_raw_parts_mut
4
- //@ ignore-debug
3
+ //@ error-pattern: unsafe precondition(s) violated: slice::from_raw_parts_mut requires
5
4
//@ revisions: null misaligned toolarge
6
5
7
6
fn main ( ) {
@@ -11,6 +10,7 @@ fn main() {
11
10
#[ cfg( misaligned) ]
12
11
let _s: & mut [ u16 ] = std:: slice:: from_raw_parts_mut ( 1usize as * mut u16 , 0 ) ;
13
12
#[ cfg( toolarge) ]
14
- let _s: & mut [ u16 ] = std:: slice:: from_raw_parts_mut ( 2usize as * mut u16 , isize:: MAX as usize ) ;
13
+ let _s: & mut [ u16 ] =
14
+ std:: slice:: from_raw_parts_mut ( 2usize as * mut u16 , isize:: MAX as usize ) ;
15
15
}
16
16
}
Original file line number Diff line number Diff line change 1
1
//@ run-fail
2
2
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
3
- //@ error-pattern: unsafe precondition(s) violated: slice::from_raw_parts
4
- //@ ignore-debug
3
+ //@ error-pattern: unsafe precondition(s) violated: slice::from_raw_parts requires
5
4
//@ revisions: null misaligned toolarge
6
5
7
6
fn main ( ) {
Original file line number Diff line number Diff line change
1
+ //@ run-fail
2
+ //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
3
+ //@ error-pattern: unsafe precondition(s) violated: ptr::swap_nonoverlapping requires
4
+ //@ revisions: null_src null_dst misaligned_src misaligned_dst overlapping
5
+
6
+ use std:: ptr;
7
+
8
+ fn main ( ) {
9
+ let mut src = [ 0u16 ; 3 ] ;
10
+ let mut dst = [ 0u16 ; 3 ] ;
11
+ let src = src. as_mut_ptr ( ) ;
12
+ let dst = dst. as_mut_ptr ( ) ;
13
+ unsafe {
14
+ #[ cfg( null_src) ]
15
+ ptr:: swap_nonoverlapping ( ptr:: null_mut ( ) , dst, 1 ) ;
16
+ #[ cfg( null_dst) ]
17
+ ptr:: swap_nonoverlapping ( src, ptr:: null_mut ( ) , 1 ) ;
18
+ #[ cfg( misaligned_src) ]
19
+ ptr:: swap_nonoverlapping ( src. byte_add ( 1 ) , dst, 1 ) ;
20
+ #[ cfg( misaligned_dst) ]
21
+ ptr:: swap_nonoverlapping ( src, dst. byte_add ( 1 ) , 1 ) ;
22
+ #[ cfg( overlapping) ]
23
+ ptr:: swap_nonoverlapping ( dst, dst. add ( 1 ) , 2 ) ;
24
+ }
25
+ }
Original file line number Diff line number Diff line change
1
+ //@ run-fail
2
+ //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
3
+ //@ error-pattern: unsafe precondition(s) violated: hint::unreachable_unchecked must never be reached
4
+
5
+ fn main ( ) {
6
+ unsafe {
7
+ std:: hint:: unreachable_unchecked ( ) ;
8
+ }
9
+ }
Original file line number Diff line number Diff line change
1
+ //@ run-fail
2
+ //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
3
+ //@ error-pattern: unsafe precondition(s) violated: ptr::write requires
4
+ //@ revisions: null misaligned
5
+ //@ ignore-test
6
+
7
+ use std:: ptr;
8
+
9
+ fn main ( ) {
10
+ let mut dst = [ 0u16 ; 2 ] ;
11
+ let mut dst = dst. as_mut_ptr ( ) ;
12
+ unsafe {
13
+ #[ cfg( null) ]
14
+ ptr:: write ( ptr:: null_mut :: < u8 > ( ) , 1u8 ) ;
15
+ #[ cfg( misaligned) ]
16
+ ptr:: write ( dst. byte_add ( 1 ) , 1u16 ) ;
17
+ }
18
+ }
Original file line number Diff line number Diff line change
1
+ //@ run-fail
2
+ //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
3
+ //@ error-pattern: unsafe precondition(s) violated: ptr::write requires
4
+ //@ revisions: null misaligned
5
+ //@ ignore-test
6
+
7
+ use std:: ptr;
8
+
9
+ fn main ( ) {
10
+ let mut dst = [ 0u16 ; 2 ] ;
11
+ let mut dst = dst. as_mut_ptr ( ) ;
12
+ unsafe {
13
+ #[ cfg( null) ]
14
+ ptr:: write_bytes ( ptr:: null_mut :: < u8 > ( ) , 1u8 , 2 ) ;
15
+ #[ cfg( misaligned) ]
16
+ ptr:: write_bytes ( dst. byte_add ( 1 ) , 1u8 , 2 ) ;
17
+ }
18
+ }
Original file line number Diff line number Diff line change
1
+ //@ run-fail
2
+ //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
3
+ //@ error-pattern: unsafe precondition(s) violated: ptr::write_volatile requires
4
+ //@ revisions: null misaligned
5
+
6
+ use std:: ptr;
7
+
8
+ fn main ( ) {
9
+ let mut dst = [ 0u16 ; 2 ] ;
10
+ let mut dst = dst. as_mut_ptr ( ) ;
11
+ unsafe {
12
+ #[ cfg( null) ]
13
+ ptr:: write_volatile ( ptr:: null_mut :: < u8 > ( ) , 1u8 ) ;
14
+ #[ cfg( misaligned) ]
15
+ ptr:: write_volatile ( dst. byte_add ( 1 ) , 1u16 ) ;
16
+ }
17
+ }
You can’t perform that action at this time.
0 commit comments