Skip to content

Commit cac6f4c

Browse files
committed
Move to_const_value from MPlaceTy to its only use site
1 parent 4a5c35b commit cac6f4c

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

src/librustc_mir/const_eval/eval_queries.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,23 @@ pub(super) fn op_to_const<'tcx>(
117117
// structs containing such.
118118
op.try_as_mplace(ecx)
119119
};
120+
121+
let to_const_value = |mplace: MPlaceTy<'_>| match mplace.ptr {
122+
Scalar::Ptr(ptr) => {
123+
let alloc = ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id);
124+
ConstValue::ByRef { alloc, offset: ptr.offset }
125+
}
126+
Scalar::Raw { data, .. } => {
127+
assert_eq!(data, mplace.layout.align.abi.bytes().into());
128+
ConstValue::Scalar(Scalar::zst())
129+
}
130+
};
120131
let val = match immediate {
121-
Ok(mplace) => mplace.to_const_value(ecx.tcx.tcx),
132+
Ok(mplace) => to_const_value(mplace),
122133
// see comment on `let try_as_immediate` above
123134
Err(ImmTy { imm: Immediate::Scalar(x), .. }) => match x {
124135
ScalarMaybeUndef::Scalar(s) => ConstValue::Scalar(s),
125-
ScalarMaybeUndef::Undef => op.assert_mem_place(ecx).to_const_value(ecx.tcx.tcx),
136+
ScalarMaybeUndef::Undef => to_const_value(op.assert_mem_place(ecx)),
126137
},
127138
Err(ImmTy { imm: Immediate::ScalarPair(a, b), .. }) => {
128139
let (data, start) = match a.not_undef().unwrap() {

src/librustc_mir/interpret/place.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ use std::convert::TryFrom;
66
use std::hash::Hash;
77

88
use rustc::mir;
9-
use rustc::mir::interpret::{truncate, ConstValue};
9+
use rustc::mir::interpret::truncate;
1010
use rustc::ty::layout::{
1111
self, Align, HasDataLayout, LayoutOf, PrimitiveExt, Size, TyLayout, VariantIdx,
1212
};
1313
use rustc::ty::TypeFoldable;
1414
use rustc::ty::{self, Ty};
15-
use rustc::ty::{self, Ty, TyCtxt};
1615
use rustc_macros::HashStable;
1716

1817
use super::{
@@ -196,20 +195,6 @@ impl<'tcx, Tag> MPlaceTy<'tcx, Tag> {
196195
_ => bug!("vtable not supported on type {:?}", self.layout.ty),
197196
}
198197
}
199-
200-
#[inline(always)]
201-
pub fn to_const_value(self, tcx: TyCtxt<'tcx>) -> ConstValue<'tcx> {
202-
match self.mplace.ptr {
203-
Scalar::Ptr(ptr) => {
204-
let alloc = tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id);
205-
ConstValue::ByRef { alloc, offset: ptr.offset }
206-
}
207-
Scalar::Raw { data, .. } => {
208-
assert_eq!(data, self.layout.align.abi.bytes().into());
209-
ConstValue::Scalar(Scalar::zst())
210-
}
211-
}
212-
}
213198
}
214199

215200
// These are defined here because they produce a place.

0 commit comments

Comments
 (0)