]> git.lizzy.rs Git - rust.git/commitdiff
let create_ref take a mutability, and leave it to step.rs to interpret mir::BorrowKind
authorRalf Jung <post@ralfj.de>
Fri, 26 Oct 2018 09:12:22 +0000 (11:12 +0200)
committerRalf Jung <post@ralfj.de>
Mon, 29 Oct 2018 08:16:27 +0000 (09:16 +0100)
src/librustc_mir/interpret/place.rs
src/librustc_mir/interpret/step.rs

index 0eae2bfb226c614fa47c7f7549e032895d1985fa..3b104e2284fe2d51459f1c168209359ffc6f76c0 100644 (file)
@@ -299,23 +299,17 @@ pub fn ref_to_mplace(
 
     /// Turn a mplace into a (thin or fat) pointer, as a reference, pointing to the same space.
     /// This is the inverse of `ref_to_mplace`.
+    /// `mutbl` indicates whether we are create a shared or mutable ref, or a raw pointer (`None`).
     pub fn create_ref(
         &mut self,
         place: MPlaceTy<'tcx, M::PointerTag>,
-        borrow_kind: Option<mir::BorrowKind>,
+        mutbl: Option<hir::Mutability>,
     ) -> EvalResult<'tcx, Value<M::PointerTag>> {
         // Pointer tag tracking might want to adjust the tag
         let place = if M::ENABLE_PTR_TRACKING_HOOKS {
             let (size, _) = self.size_and_align_of_mplace(place)?
                 // for extern types, just cover what we can
                 .unwrap_or_else(|| place.layout.size_and_align());
-            let mutbl = match borrow_kind {
-                Some(mir::BorrowKind::Mut { .. }) |
-                Some(mir::BorrowKind::Unique) =>
-                    Some(hir::MutMutable),
-                Some(_) => Some(hir::MutImmutable),
-                None => None,
-            };
             M::tag_reference(self, *place, place.layout.ty, size, mutbl)?
         } else {
             *place
index 80b9948f612e498f96aa216e0917709e859ceff6..97431cfe6808e1a0afab7e107db72190a00e6692 100644 (file)
@@ -12,7 +12,7 @@
 //!
 //! The main entry point is the `step` method.
 
-use rustc::mir;
+use rustc::{hir, mir};
 use rustc::ty::layout::LayoutOf;
 use rustc::mir::interpret::{EvalResult, Scalar, PointerArithmetic};
 
@@ -250,7 +250,15 @@ fn eval_rvalue_into_place(
             Ref(_, borrow_kind, ref place) => {
                 let src = self.eval_place(place)?;
                 let val = self.force_allocation(src)?;
-                let val = self.create_ref(val, Some(borrow_kind))?;
+                let mutbl = match borrow_kind {
+                    mir::BorrowKind::Mut { .. } |
+                    mir::BorrowKind::Unique =>
+                        hir::MutMutable,
+                    mir::BorrowKind::Shared |
+                    mir::BorrowKind::Shallow =>
+                        hir::MutImmutable,
+                };
+                let val = self.create_ref(val, Some(mutbl))?;
                 self.write_value(val, dest)?;
             }