Skip to content

Commit 3545dae

Browse files
committed
let create_ref take a mutability, and leave it to step.rs to interpret mir::BorrowKind
1 parent f2f0f1a commit 3545dae

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/librustc_mir/interpret/place.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -299,23 +299,17 @@ where
299299

300300
/// Turn a mplace into a (thin or fat) pointer, as a reference, pointing to the same space.
301301
/// This is the inverse of `ref_to_mplace`.
302+
/// `mutbl` indicates whether we are create a shared or mutable ref, or a raw pointer (`None`).
302303
pub fn create_ref(
303304
&mut self,
304305
place: MPlaceTy<'tcx, M::PointerTag>,
305-
borrow_kind: Option<mir::BorrowKind>,
306+
mutbl: Option<hir::Mutability>,
306307
) -> EvalResult<'tcx, Value<M::PointerTag>> {
307308
// Pointer tag tracking might want to adjust the tag
308309
let place = if M::ENABLE_PTR_TRACKING_HOOKS {
309310
let (size, _) = self.size_and_align_of_mplace(place)?
310311
// for extern types, just cover what we can
311312
.unwrap_or_else(|| place.layout.size_and_align());
312-
let mutbl = match borrow_kind {
313-
Some(mir::BorrowKind::Mut { .. }) |
314-
Some(mir::BorrowKind::Unique) =>
315-
Some(hir::MutMutable),
316-
Some(_) => Some(hir::MutImmutable),
317-
None => None,
318-
};
319313
M::tag_reference(self, *place, place.layout.ty, size, mutbl)?
320314
} else {
321315
*place

src/librustc_mir/interpret/step.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//!
1313
//! The main entry point is the `step` method.
1414
15-
use rustc::mir;
15+
use rustc::{hir, mir};
1616
use rustc::ty::layout::LayoutOf;
1717
use rustc::mir::interpret::{EvalResult, Scalar, PointerArithmetic};
1818

@@ -250,7 +250,15 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
250250
Ref(_, borrow_kind, ref place) => {
251251
let src = self.eval_place(place)?;
252252
let val = self.force_allocation(src)?;
253-
let val = self.create_ref(val, Some(borrow_kind))?;
253+
let mutbl = match borrow_kind {
254+
mir::BorrowKind::Mut { .. } |
255+
mir::BorrowKind::Unique =>
256+
hir::MutMutable,
257+
mir::BorrowKind::Shared |
258+
mir::BorrowKind::Shallow =>
259+
hir::MutImmutable,
260+
};
261+
let val = self.create_ref(val, Some(mutbl))?;
254262
self.write_value(val, dest)?;
255263
}
256264

0 commit comments

Comments
 (0)