This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +22
-5
lines changed
src/tools/miri/tests/pass/tree_borrows Expand file tree Collapse file tree 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;
88
99pub fn main ( ) {
1010 let cell = UnsafeCell :: new ( 42 ) ;
11- let mut root = Box :: new ( cell) ;
11+ let box1 = Box :: new ( cell) ;
1212
13- let a = Box :: as_mut_ptr ( & mut root) ;
1413 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) ;
1733 print_state ! ( alloc_id) ;
1834 }
1935}
Original file line number Diff line number Diff line change 22Warning: this tree is indicative only. Some tags may have been hidden.
330.. 4
44| Act | └─┬──<TAG=root of the allocation>
5- | ReIM| └────<TAG=a>
5+ | Act | └─┬──<TAG=ptr1>
6+ | ReIM| └────<TAG=ptr2>
67──────────────────────────────────────────────────
You can’t perform that action at this time.
0 commit comments