2018-11-06 18:10:15 +01:00
|
|
|
// Retagging (from Stacked Borrows) relies on the array index being a fresh
|
|
|
|
// temporary, so that side-effects cannot change it.
|
|
|
|
// Test that this is indeed the case.
|
|
|
|
|
|
|
|
unsafe fn foo(z: *mut usize) -> u32 {
|
|
|
|
*z = 2;
|
|
|
|
99
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut x = [42, 43, 44];
|
|
|
|
let mut y = 1;
|
|
|
|
let z: *mut usize = &mut y;
|
|
|
|
x[y] = unsafe { foo(z) };
|
|
|
|
}
|
|
|
|
|
|
|
|
// END RUST SOURCE
|
2020-03-19 11:40:38 +00:00
|
|
|
// START rustc.main.SimplifyCfg-elaborate-drops.after.mir
|
2018-11-06 18:10:15 +01:00
|
|
|
// bb0: {
|
|
|
|
// ...
|
2019-04-20 18:06:03 +01:00
|
|
|
// _4 = &mut _2;
|
|
|
|
// _3 = &raw mut (*_4);
|
2018-11-06 18:10:15 +01:00
|
|
|
// ...
|
2019-04-20 18:06:03 +01:00
|
|
|
// _6 = _3;
|
|
|
|
// _5 = const foo(move _6) -> bb1;
|
2018-11-06 18:10:15 +01:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// bb1: {
|
|
|
|
// ...
|
2019-04-20 18:06:03 +01:00
|
|
|
// _7 = _2;
|
|
|
|
// _8 = Len(_1);
|
|
|
|
// _9 = Lt(_7, _8);
|
|
|
|
// assert(move _9, "index out of bounds: the len is move _8 but the index is _7") -> bb2;
|
2018-11-06 18:10:15 +01:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// bb2: {
|
2019-04-20 18:06:03 +01:00
|
|
|
// _1[_7] = move _5;
|
2018-11-06 18:10:15 +01:00
|
|
|
// ...
|
|
|
|
// return;
|
|
|
|
// }
|
2020-03-19 11:40:38 +00:00
|
|
|
// END rustc.main.SimplifyCfg-elaborate-drops.after.mir
|