]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/array-index-is-temporary.rs
Auto merge of #60250 - Centril:rollup-d9tehhr, r=Centril
[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 //         _5 = &mut _2;
22 //         _4 = &mut (*_5);
23 //         _3 = move _4 as *mut usize (Misc);
24 //         ...
25 //         _7 = _3;
26 //         _6 = const foo(move _7) -> bb1;
27 //     }
28 //
29 //     bb1: {
30 //         ...
31 //         _8 = _2;
32 //         _9 = Len(_1);
33 //         _10 = Lt(_8, _9);
34 //         assert(move _10, "index out of bounds: the len is move _9 but the index is _8") -> bb2;
35 //     }
36 //
37 //     bb2: {
38 //         _1[_8] = move _6;
39 //         ...
40 //         return;
41 //     }
42 // END rustc.main.EraseRegions.after.mir