File tree 2 files changed +24
-0
lines changed
2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change
1
+ // compile-flags: -Zmiri-disable-validation
2
+
3
+ use std:: mem:: MaybeUninit ;
4
+
5
+ fn main ( ) { unsafe {
6
+ let mut x = MaybeUninit :: < i64 > :: uninit ( ) ;
7
+ // Put in a ptr.
8
+ x. as_mut_ptr ( ) . cast :: < & i32 > ( ) . write_unaligned ( & 0 ) ;
9
+ // Overwrite parts of that pointer with 'uninit' through a Scalar.
10
+ let ptr = x. as_mut_ptr ( ) . cast :: < i32 > ( ) ;
11
+ * ptr = MaybeUninit :: uninit ( ) . assume_init ( ) ;
12
+ // Reading this back should hence work fine.
13
+ let _c = * ptr;
14
+ } }
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ fn main() {
16
16
disjoint_mutable_subborrows ( ) ;
17
17
raw_ref_to_part ( ) ;
18
18
array_casts ( ) ;
19
+ mut_below_shr ( ) ;
19
20
}
20
21
21
22
// Make sure that reading from an `&mut` does, like reborrowing to `&`,
@@ -186,3 +187,12 @@ fn array_casts() {
186
187
let p = & x as * const usize ;
187
188
assert_eq ! ( unsafe { * p. add( 1 ) } , 1 ) ;
188
189
}
190
+
191
+ /// Transmuting &&i32 to &&mut i32 is fine.
192
+ fn mut_below_shr ( ) {
193
+ let x = 0 ;
194
+ let y = & x;
195
+ let p = unsafe { core:: mem:: transmute :: < & & i32 , & & mut i32 > ( & y) } ;
196
+ let r = & * * p;
197
+ let _val = * r;
198
+ }
You can’t perform that action at this time.
0 commit comments