]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/array-index-is-temporary.rs
Render const pointers in MIR more compactly
[rust.git] / src / test / mir-opt / array-index-is-temporary.rs
1 // Retagging (from Stacked Borrows) relies on the array index being a fresh
2 // temporary, so that side-effects cannot change it.
3 // Test that this is indeed the case.
4
5 unsafe fn foo(z: *mut usize) -> u32 {
6     *z = 2;
7     99
8 }
9
10 fn main() {
11     let mut x = [42, 43, 44];
12     let mut y = 1;
13     let z: *mut usize = &mut y;
14     x[y] = unsafe { foo(z) };
15 }
16
17 // END RUST SOURCE
18 // START rustc.main.EraseRegions.after.mir
19 //     bb0: {
20 //         ...
21 //         _4 = &mut _2;
22 //         _3 = &raw mut (*_4);
23 //         ...
24 //         _6 = _3;
25 //         _5 = const foo(move _6) -> bb1;
26 //     }
27 //
28 //     bb1: {
29 //         ...
30 //         _7 = _2;
31 //         _8 = Len(_1);
32 //         _9 = Lt(_7, _8);
33 //         assert(move _9, "index out of bounds: the len is move _8 but the index is _7") -> bb2;
34 //     }
35 //
36 //     bb2: {
37 //         _1[_7] = move _5;
38 //         ...
39 //         return;
40 //     }
41 // END rustc.main.EraseRegions.after.mir