]> git.lizzy.rs Git - rust.git/blobdiff - src/stacked_borrows.rs
Stacked Borrows: alignment does not matter
[rust.git] / src / stacked_borrows.rs
index 3412f00964b4a1934157d54e0c90da429f399b11..03140c867b2d07d19dca3025ad198de6f1bffe8d 100644 (file)
@@ -11,7 +11,7 @@
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
 use rustc_middle::mir::RetagKind;
 use rustc_middle::ty;
-use rustc_target::abi::{LayoutOf, Size};
+use rustc_target::abi::{Align, LayoutOf, Size};
 use rustc_hir::Mutability;
 
 use crate::*;
@@ -577,11 +577,13 @@ fn retag_reference(
             .size_and_align_of_mplace(place)?
             .map(|(size, _)| size)
             .unwrap_or_else(|| place.layout.size);
+        // `reborrow` relies on getting a `Pointer` and everything being in-bounds,
+        // so let's ensure that. However, we do not care about alignment.
         // We can see dangling ptrs in here e.g. after a Box's `Unique` was
-        // updated using "self.0 = ..." (can happen in Box::from_raw); see miri#1050.
-        let place = this.mplace_access_checked(place)?;
+        // updated using "self.0 = ..." (can happen in Box::from_raw) so we cannot ICE; see miri#1050.
+        let place = this.mplace_access_checked(place, Some(Align::from_bytes(1).unwrap()))?;
+        // Nothing to do for ZSTs.
         if size == Size::ZERO {
-            // Nothing to do for ZSTs.
             return Ok(val);
         }