]> git.lizzy.rs Git - rust.git/commitdiff
add mut_below_shr test
authorRalf Jung <post@ralfj.de>
Wed, 20 Apr 2022 14:47:22 +0000 (10:47 -0400)
committerRalf Jung <post@ralfj.de>
Wed, 20 Apr 2022 14:52:25 +0000 (10:52 -0400)
tests/run-pass/stacked-borrows/stacked-borrows.rs

index 8aea945f90939fdd553176c54b9c7e88bdb3e3e5..b63f9addb0f6cce417b4eea0c8358c8745a7bb2b 100644 (file)
@@ -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 `&`,
@@ -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;
+}