diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index 0eae2bfb226c..3b104e2284fe 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -299,23 +299,17 @@ where /// 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, + mutbl: Option, ) -> EvalResult<'tcx, Value> { // 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 diff --git a/src/librustc_mir/interpret/step.rs b/src/librustc_mir/interpret/step.rs index 80b9948f612e..97431cfe6808 100644 --- a/src/librustc_mir/interpret/step.rs +++ b/src/librustc_mir/interpret/step.rs @@ -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 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> 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)?; }