File tree 2 files changed +22
-5
lines changed
src/tools/miri/tests/pass/tree_borrows
2 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -8,12 +8,28 @@ use std::cell::UnsafeCell;
8
8
9
9
pub fn main ( ) {
10
10
let cell = UnsafeCell :: new ( 42 ) ;
11
- let mut root = Box :: new ( cell) ;
11
+ let box1 = Box :: new ( cell) ;
12
12
13
- let a = Box :: as_mut_ptr ( & mut root) ;
14
13
unsafe {
15
- name ! ( a) ;
16
- let alloc_id = alloc_id ! ( a) ;
14
+ let ptr1: * mut UnsafeCell < i32 > = Box :: into_raw ( box1) ;
15
+ name ! ( ptr1) ;
16
+
17
+ let mut box2 = Box :: from_raw ( ptr1) ;
18
+ // `ptr2` will be a descendant of `ptr1`.
19
+ let ptr2: * mut UnsafeCell < i32 > = Box :: as_mut_ptr ( & mut box2) ;
20
+ name ! ( ptr2) ;
21
+
22
+ // We perform a write through `x`.
23
+ // Because `ptr1` is ReservedIM, a child write will make it transition to Active.
24
+ // Because `ptr2` is ReservedIM, a foreign write doesn't have any effect on it.
25
+ let x = ( * ptr1) . get ( ) ;
26
+ * x = 1 ;
27
+
28
+ // We can still read from `ptr2`.
29
+ let val = * ( * ptr2) . get ( ) ;
30
+ assert_eq ! ( val, 1 ) ;
31
+
32
+ let alloc_id = alloc_id ! ( ptr1) ;
17
33
print_state ! ( alloc_id) ;
18
34
}
19
35
}
Original file line number Diff line number Diff line change 2
2
Warning: this tree is indicative only. Some tags may have been hidden.
3
3
0.. 4
4
4
| Act | └─┬──<TAG=root of the allocation>
5
- | ReIM| └────<TAG=a>
5
+ | Act | └─┬──<TAG=ptr1>
6
+ | ReIM| └────<TAG=ptr2>
6
7
──────────────────────────────────────────────────
You can’t perform that action at this time.
0 commit comments