Skip to content

Commit

Permalink
Auto merge of #2077 - RalfJung:more-test, r=RalfJung
Browse files Browse the repository at this point in the history
add some more tests
  • Loading branch information
bors committed Apr 20, 2022
2 parents c9039de + e214e6d commit ba24c31
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/run-pass/issue-miri-2068-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// compile-flags: -Zmiri-disable-validation

use std::mem::MaybeUninit;

fn main() { unsafe {
let mut x = MaybeUninit::<i64>::uninit();
// Put in a ptr.
x.as_mut_ptr().cast::<&i32>().write_unaligned(&0);
// Overwrite parts of that pointer with 'uninit' through a Scalar.
let ptr = x.as_mut_ptr().cast::<i32>();
*ptr = MaybeUninit::uninit().assume_init();
// Reading this back should hence work fine.
let _c = *ptr;
} }
10 changes: 10 additions & 0 deletions tests/run-pass/stacked-borrows/stacked-borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fn main() {
disjoint_mutable_subborrows();
raw_ref_to_part();
array_casts();
mut_below_shr();
}

// Make sure that reading from an `&mut` does, like reborrowing to `&`,
Expand Down Expand Up @@ -186,3 +187,12 @@ fn array_casts() {
let p = &x as *const usize;
assert_eq!(unsafe { *p.add(1) }, 1);
}

/// Transmuting &&i32 to &&mut i32 is fine.
fn mut_below_shr() {
let x = 0;
let y = &x;
let p = unsafe { core::mem::transmute::<&&i32,&&mut i32>(&y) };
let r = &**p;
let _val = *r;
}

0 comments on commit ba24c31

Please sign in to comment.