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