4 // Make sure that `Ref` and `RefMut` do not make false promises about aliasing,
5 // because once they drop, their reference/pointer can alias other writes.
7 // Adapted from comex's proof of concept:
8 // https://github.com/rust-lang/rust/issues/63787#issuecomment-523588164
10 use std::cell::RefCell;
13 pub fn break_if_r_is_noalias(rc: &RefCell<i32>, r: impl Deref<Target = i32>) -> i32 {
14 let ptr1 = &*r as *const i32;
19 let ptr2 = &*r2 as *const i32;
23 // If LLVM knows the pointers are the same, and if `r` was `noalias`,
24 // then it may replace this with `a + a`, ignoring the earlier write.
29 let mut rc = RefCell::new(1);
30 let res = break_if_r_is_noalias(&rc, rc.borrow());
34 let res = break_if_r_is_noalias(&rc, rc.borrow_mut());