This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ // build-fail
2
+
3
+ fn main ( ) {
4
+ divide_by_zero ( ) ;
5
+ mod_by_zero ( ) ;
6
+ oob_error_for_slices ( ) ;
7
+ }
8
+
9
+ fn divide_by_zero ( ) {
10
+ let y = 0 ;
11
+ let _z = 1 / y; //~ ERROR this operation will panic at runtime [unconditional_panic]
12
+ }
13
+
14
+ fn mod_by_zero ( ) {
15
+ let y = 0 ;
16
+ let _z = 1 % y; //~ ERROR this operation will panic at runtime [unconditional_panic]
17
+ }
18
+
19
+ fn oob_error_for_slices ( ) {
20
+ let a: * const [ _ ] = & [ 1 , 2 , 3 ] ;
21
+ unsafe {
22
+ let _b = ( * a) [ 3 ] ; //~ ERROR this operation will panic at runtime [unconditional_panic]
23
+ }
24
+ }
Original file line number Diff line number Diff line change
1
+ error: this operation will panic at runtime
2
+ --> $DIR/mir_detects_invalid_ops.rs:11:14
3
+ |
4
+ LL | let _z = 1 / y;
5
+ | ^^^^^ attempt to divide by zero
6
+ |
7
+ = note: `#[deny(unconditional_panic)]` on by default
8
+
9
+ error: this operation will panic at runtime
10
+ --> $DIR/mir_detects_invalid_ops.rs:16:14
11
+ |
12
+ LL | let _z = 1 % y;
13
+ | ^^^^^ attempt to calculate the remainder with a divisor of zero
14
+
15
+ error: this operation will panic at runtime
16
+ --> $DIR/mir_detects_invalid_ops.rs:22:18
17
+ |
18
+ LL | let _b = (*a)[3];
19
+ | ^^^^^^^ index out of bounds: the len is 3 but the index is 3
20
+
21
+ error: aborting due to 3 previous errors
22
+
You can’t perform that action at this time.
0 commit comments