Skip to content

Commit 1a614f8

Browse files
committed
wrap calls to lvalue_ty
1 parent 5c717a6 commit 1a614f8

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

src/librustc_trans/mir/block.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -777,9 +777,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
777777
}
778778
let dest = match *dest {
779779
mir::Lvalue::Temp(idx) => {
780-
let lvalue_ty = self.mir.lvalue_ty(bcx.tcx(), dest);
781-
let lvalue_ty = bcx.monomorphize(&lvalue_ty);
782-
let ret_ty = lvalue_ty.to_ty(bcx.tcx());
780+
let ret_ty = self.lvalue_ty(dest);
783781
match self.temps[idx as usize] {
784782
TempRef::Lvalue(dest) => dest,
785783
TempRef::Operand(None) => {

src/librustc_trans/mir/lvalue.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
9999
},
100100
mir::Lvalue::Arg(index) => self.args[index as usize],
101101
mir::Lvalue::Static(def_id) => {
102-
let const_ty = self.mir.lvalue_ty(tcx, lvalue);
103-
LvalueRef::new_sized(consts::get_static(ccx, def_id).val, const_ty)
102+
let const_ty = self.lvalue_ty(lvalue);
103+
LvalueRef::new_sized(consts::get_static(ccx, def_id).val,
104+
LvalueTy::from_ty(const_ty))
104105
},
105106
mir::Lvalue::ReturnPointer => {
106107
let llval = if !fcx.fn_ty.ret.is_ignore() {
@@ -195,7 +196,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
195196
ty::TyArray(..) => {
196197
// must cast the lvalue pointer type to the new
197198
// array type (*[%_; new_len]).
198-
let base_ty = self.mir.lvalue_ty(tcx, lvalue).to_ty(tcx);
199+
let base_ty = self.lvalue_ty(lvalue);
199200
let llbasety = type_of::type_of(bcx.ccx(), base_ty).ptr_to();
200201
let llbase = bcx.pointercast(llbase, llbasety);
201202
(bcx.pointercast(llbase, llbasety), ptr::null_mut())
@@ -236,27 +237,23 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
236237
match self.temps[idx as usize] {
237238
TempRef::Lvalue(lvalue) => f(self, lvalue),
238239
TempRef::Operand(None) => {
239-
let lvalue_ty = self.mir.lvalue_ty(bcx.tcx(), lvalue);
240-
let lvalue_ty = bcx.monomorphize(&lvalue_ty);
240+
let lvalue_ty = self.lvalue_ty(lvalue);
241241
let lvalue = LvalueRef::alloca(bcx,
242-
lvalue_ty.to_ty(bcx.tcx()),
242+
lvalue_ty,
243243
"lvalue_temp");
244244
let ret = f(self, lvalue);
245-
let op = self.trans_load(bcx, lvalue.llval, lvalue_ty.to_ty(bcx.tcx()));
245+
let op = self.trans_load(bcx, lvalue.llval, lvalue_ty);
246246
self.temps[idx as usize] = TempRef::Operand(Some(op));
247247
ret
248248
}
249249
TempRef::Operand(Some(_)) => {
250-
let lvalue_ty = self.mir.lvalue_ty(bcx.tcx(), lvalue);
251-
let lvalue_ty = bcx.monomorphize(&lvalue_ty);
252-
253250
// See comments in TempRef::new_operand as to why
254251
// we always have Some in a ZST TempRef::Operand.
255-
let ty = lvalue_ty.to_ty(bcx.tcx());
252+
let ty = self.lvalue_ty(lvalue);
256253
if common::type_is_zero_size(bcx.ccx(), ty) {
257254
// Pass an undef pointer as no stores can actually occur.
258255
let llptr = C_undef(type_of(bcx.ccx(), ty).ptr_to());
259-
f(self, LvalueRef::new_sized(llptr, lvalue_ty))
256+
f(self, LvalueRef::new_sized(llptr, LvalueTy::from_ty(ty)))
260257
} else {
261258
bug!("Lvalue temp already set");
262259
}
@@ -290,4 +287,10 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
290287
llindex
291288
}
292289
}
290+
291+
pub fn lvalue_ty(&self, lvalue: &mir::Lvalue<'tcx>) -> Ty<'tcx> {
292+
let tcx = self.fcx.ccx.tcx();
293+
let lvalue_ty = self.mir.lvalue_ty(tcx, lvalue);
294+
self.fcx.monomorphize(&lvalue_ty.to_ty(tcx))
295+
}
293296
}

src/librustc_trans/mir/statement.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
4040
bcx
4141
}
4242
TempRef::Operand(Some(_)) => {
43-
let ty = self.mir.lvalue_ty(bcx.tcx(), lvalue);
44-
let ty = bcx.monomorphize(&ty.to_ty(bcx.tcx()));
43+
let ty = self.lvalue_ty(lvalue);
4544

4645
if !common::type_is_zero_size(bcx.ccx(), ty) {
4746
span_bug!(statement.source_info.span,

0 commit comments

Comments
 (0)