]> git.lizzy.rs Git - rust.git/blob - tests/mir-opt/array_index_is_temporary.rs
Rollup merge of #107248 - erikdesjardins:addrspace, r=oli-obk
[rust.git] / tests / 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
11 // EMIT_MIR array_index_is_temporary.main.SimplifyCfg-elaborate-drops.after.mir
12 fn main() {
13     let mut x = [42, 43, 44];
14     let mut y = 1;
15     let z: *mut usize = &mut y;
16     x[y] = unsafe { foo(z) };
17 }