]> git.lizzy.rs Git - rust.git/blob - tests/ui/mir/mir_detects_invalid_ops.rs
Rollup merge of #106707 - ehuss:remove-dupe-sha-1, r=Mark-Simulacrum
[rust.git] / tests / ui / mir / mir_detects_invalid_ops.rs
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];
23     }
24 }