2023-10-16 12:36:39 -05:00
|
|
|
// skip-filecheck
|
2023-06-08 02:18:34 -05:00
|
|
|
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
|
2023-02-17 11:36:43 -06:00
|
|
|
// Check that CopyProp considers reborrows as not mutating the pointer.
|
|
|
|
//@ unit-test: CopyProp
|
|
|
|
|
|
|
|
#![feature(raw_ref_op)]
|
|
|
|
|
2023-02-17 12:10:54 -06:00
|
|
|
#[inline(never)]
|
|
|
|
fn opaque(_: impl Sized) {}
|
|
|
|
|
2023-02-17 11:36:43 -06:00
|
|
|
// EMIT_MIR reborrow.remut.CopyProp.diff
|
|
|
|
fn remut(mut x: u8) {
|
|
|
|
let a = &mut x;
|
|
|
|
let b = &mut *a; //< this cannot mutate a.
|
|
|
|
let c = a; //< so `c` and `a` can be merged.
|
2023-02-17 12:10:54 -06:00
|
|
|
opaque(c);
|
2023-02-17 11:36:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR reborrow.reraw.CopyProp.diff
|
|
|
|
fn reraw(mut x: u8) {
|
|
|
|
let a = &mut x;
|
|
|
|
let b = &raw mut *a; //< this cannot mutate a.
|
|
|
|
let c = a; //< so `c` and `a` can be merged.
|
2023-02-17 12:10:54 -06:00
|
|
|
opaque(c);
|
2023-02-17 11:36:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR reborrow.miraw.CopyProp.diff
|
|
|
|
fn miraw(mut x: u8) {
|
|
|
|
let a = &raw mut x;
|
|
|
|
let b = unsafe { &raw mut *a }; //< this cannot mutate a.
|
|
|
|
let c = a; //< so `c` and `a` can be merged.
|
2023-02-17 12:10:54 -06:00
|
|
|
opaque(c);
|
2023-02-17 11:36:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// EMIT_MIR reborrow.demiraw.CopyProp.diff
|
|
|
|
fn demiraw(mut x: u8) {
|
|
|
|
let a = &raw mut x;
|
|
|
|
let b = unsafe { &mut *a }; //< this cannot mutate a.
|
|
|
|
let c = a; //< so `c` and `a` can be merged.
|
2023-02-17 12:10:54 -06:00
|
|
|
opaque(c);
|
2023-02-17 11:36:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
remut(0);
|
|
|
|
reraw(0);
|
|
|
|
miraw(0);
|
|
|
|
demiraw(0);
|
|
|
|
}
|