File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ fn main() {
4
4
read_does_not_invalidate1 ( ) ;
5
5
read_does_not_invalidate2 ( ) ;
6
6
ref_raw_int_raw ( ) ;
7
+ mut_shr_raw ( ) ;
8
+ mut_raw_then_mut_shr ( ) ;
7
9
}
8
10
9
11
// Deref a raw ptr to access a field of a large struct, where the field
@@ -48,3 +50,29 @@ fn ref_raw_int_raw() {
48
50
let xraw = xref as * mut i32 as usize as * mut i32 ;
49
51
assert_eq ! ( unsafe { * xraw } , 3 ) ;
50
52
}
53
+
54
+ // Creating a raw from a `&mut` through an `&` works, even if we
55
+ // write through that raw.
56
+ fn mut_shr_raw ( ) {
57
+ let mut x = 2 ;
58
+ {
59
+ let xref = & mut x;
60
+ let xraw = & * xref as * const i32 as * mut i32 ;
61
+ unsafe { * xraw = 4 ; }
62
+ }
63
+ assert_eq ! ( x, 4 ) ;
64
+ }
65
+
66
+ // Escape a mut to raw, then share the same mut and use the share, then the raw.
67
+ // That should work.
68
+ fn mut_raw_then_mut_shr ( ) {
69
+ let mut x = 2 ;
70
+ {
71
+ let xref = & mut x;
72
+ let xraw = & mut * xref as * mut _ ;
73
+ let xshr = & * xref;
74
+ assert_eq ! ( * xshr, 2 ) ;
75
+ unsafe { * xraw = 4 ; }
76
+ }
77
+ assert_eq ! ( x, 4 ) ;
78
+ }
You can’t perform that action at this time.
0 commit comments