File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 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() {
1616 disjoint_mutable_subborrows ( ) ;
1717 raw_ref_to_part ( ) ;
1818 array_casts ( ) ;
19+ mut_below_shr ( ) ;
1920}
2021
2122// Make sure that reading from an `&mut` does, like reborrowing to `&`,
@@ -186,3 +187,12 @@ fn array_casts() {
186187 let p = & x as * const usize ;
187188 assert_eq ! ( unsafe { * p. add( 1 ) } , 1 ) ;
188189}
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