From 62b2e5446d1a47f00729f2066f05254081f29914 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 11 Jul 2017 16:02:06 -0700 Subject: [PATCH 1/4] Refactor: {Lvalue,Rvalue,Operand}::ty only need the locals' types, not the full &Mir --- src/librustc/mir/mod.rs | 5 ++- src/librustc/mir/tcx.rs | 32 +++++++++---------- .../dataflow/drop_flag_effects.rs | 6 ++-- src/librustc_mir/dataflow/move_paths/mod.rs | 4 +-- src/librustc_mir/transform/inline.rs | 10 +++--- src/librustc_mir/transform/instcombine.rs | 2 +- src/librustc_mir/transform/promote_consts.rs | 4 +-- src/librustc_mir/transform/qualify_consts.rs | 16 +++++----- src/librustc_mir/transform/type_check.rs | 30 ++++++++--------- src/librustc_mir/util/elaborate_drops.rs | 2 +- src/librustc_trans/collector.rs | 10 +++--- src/librustc_trans/mir/analyze.rs | 4 +-- src/librustc_trans/mir/block.rs | 4 +-- src/librustc_trans/mir/constant.rs | 4 +-- src/librustc_trans/mir/lvalue.rs | 2 +- src/librustc_trans/mir/rvalue.rs | 6 ++-- 16 files changed, 72 insertions(+), 69 deletions(-) diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 96ccc3ba50078..8ac4e1208b0cb 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -66,6 +66,9 @@ macro_rules! newtype_index { ) } +/// Types for locals +type LocalDecls<'tcx> = IndexVec>; + /// Lowered representation of a single function. #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct Mir<'tcx> { @@ -90,7 +93,7 @@ pub struct Mir<'tcx> { /// The first local is the return value pointer, followed by `arg_count` /// locals for the function arguments, followed by any user-declared /// variables and temporaries. - pub local_decls: IndexVec>, + pub local_decls: LocalDecls<'tcx>, /// Number of arguments this function takes. /// diff --git a/src/librustc/mir/tcx.rs b/src/librustc/mir/tcx.rs index 71acb36ecf75d..b99c0180eccfd 100644 --- a/src/librustc/mir/tcx.rs +++ b/src/librustc/mir/tcx.rs @@ -121,31 +121,31 @@ impl<'tcx> TypeFoldable<'tcx> for LvalueTy<'tcx> { } impl<'tcx> Lvalue<'tcx> { - pub fn ty<'a, 'gcx>(&self, mir: &Mir<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> LvalueTy<'tcx> { + pub fn ty<'a, 'gcx>(&self, local_decls: &LocalDecls<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> LvalueTy<'tcx> { match *self { Lvalue::Local(index) => - LvalueTy::Ty { ty: mir.local_decls[index].ty }, + LvalueTy::Ty { ty: local_decls[index].ty }, Lvalue::Static(ref data) => LvalueTy::Ty { ty: data.ty }, Lvalue::Projection(ref proj) => - proj.base.ty(mir, tcx).projection_ty(tcx, &proj.elem), + proj.base.ty(local_decls, tcx).projection_ty(tcx, &proj.elem), } } } impl<'tcx> Rvalue<'tcx> { - pub fn ty<'a, 'gcx>(&self, mir: &Mir<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> + pub fn ty<'a, 'gcx>(&self, local_decls: &LocalDecls<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> { match *self { - Rvalue::Use(ref operand) => operand.ty(mir, tcx), + Rvalue::Use(ref operand) => operand.ty(local_decls, tcx), Rvalue::Repeat(ref operand, ref count) => { - let op_ty = operand.ty(mir, tcx); + let op_ty = operand.ty(local_decls, tcx); let count = count.as_u64(tcx.sess.target.uint_type); assert_eq!(count as usize as u64, count); tcx.mk_array(op_ty, count as usize) } Rvalue::Ref(reg, bk, ref lv) => { - let lv_ty = lv.ty(mir, tcx).to_ty(tcx); + let lv_ty = lv.ty(local_decls, tcx).to_ty(tcx); tcx.mk_ref(reg, ty::TypeAndMut { ty: lv_ty, @@ -156,22 +156,22 @@ impl<'tcx> Rvalue<'tcx> { Rvalue::Len(..) => tcx.types.usize, Rvalue::Cast(.., ty) => ty, Rvalue::BinaryOp(op, ref lhs, ref rhs) => { - let lhs_ty = lhs.ty(mir, tcx); - let rhs_ty = rhs.ty(mir, tcx); + let lhs_ty = lhs.ty(local_decls, tcx); + let rhs_ty = rhs.ty(local_decls, tcx); op.ty(tcx, lhs_ty, rhs_ty) } Rvalue::CheckedBinaryOp(op, ref lhs, ref rhs) => { - let lhs_ty = lhs.ty(mir, tcx); - let rhs_ty = rhs.ty(mir, tcx); + let lhs_ty = lhs.ty(local_decls, tcx); + let rhs_ty = rhs.ty(local_decls, tcx); let ty = op.ty(tcx, lhs_ty, rhs_ty); tcx.intern_tup(&[ty, tcx.types.bool], false) } Rvalue::UnaryOp(UnOp::Not, ref operand) | Rvalue::UnaryOp(UnOp::Neg, ref operand) => { - operand.ty(mir, tcx) + operand.ty(local_decls, tcx) } Rvalue::Discriminant(ref lval) => { - let ty = lval.ty(mir, tcx).to_ty(tcx); + let ty = lval.ty(local_decls, tcx).to_ty(tcx); if let ty::TyAdt(adt_def, _) = ty.sty { adt_def.repr.discr_type().to_ty(tcx) } else { @@ -189,7 +189,7 @@ impl<'tcx> Rvalue<'tcx> { } AggregateKind::Tuple => { tcx.mk_tup( - ops.iter().map(|op| op.ty(mir, tcx)), + ops.iter().map(|op| op.ty(local_decls, tcx)), false ) } @@ -206,9 +206,9 @@ impl<'tcx> Rvalue<'tcx> { } impl<'tcx> Operand<'tcx> { - pub fn ty<'a, 'gcx>(&self, mir: &Mir<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> { + pub fn ty<'a, 'gcx>(&self, local_decls: &LocalDecls<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> { match self { - &Operand::Consume(ref l) => l.ty(mir, tcx).to_ty(tcx), + &Operand::Consume(ref l) => l.ty(local_decls, tcx).to_ty(tcx), &Operand::Constant(ref c) => c.ty, } } diff --git a/src/librustc_mir/dataflow/drop_flag_effects.rs b/src/librustc_mir/dataflow/drop_flag_effects.rs index daafbecc5dfa3..a247cd774501e 100644 --- a/src/librustc_mir/dataflow/drop_flag_effects.rs +++ b/src/librustc_mir/dataflow/drop_flag_effects.rs @@ -129,7 +129,7 @@ pub fn move_path_children_matching<'tcx, F>(move_data: &MoveData<'tcx>, fn lvalue_contents_drop_state_cannot_differ<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, mir: &Mir<'tcx>, lv: &mir::Lvalue<'tcx>) -> bool { - let ty = lv.ty(mir, tcx).to_ty(tcx); + let ty = lv.ty(&mir.local_decls, tcx).to_ty(tcx); match ty.sty { ty::TyArray(..) | ty::TySlice(..) | ty::TyRef(..) | ty::TyRawPtr(..) => { debug!("lvalue_contents_drop_state_cannot_differ lv: {:?} ty: {:?} refd => true", @@ -216,7 +216,7 @@ pub(crate) fn on_all_drop_children_bits<'a, 'tcx, F>( { on_all_children_bits(tcx, mir, &ctxt.move_data, path, |child| { let lvalue = &ctxt.move_data.move_paths[path].lvalue; - let ty = lvalue.ty(mir, tcx).to_ty(tcx); + let ty = lvalue.ty(&mir.local_decls, tcx).to_ty(tcx); debug!("on_all_drop_children_bits({:?}, {:?} : {:?})", path, lvalue, ty); if ty.needs_drop(tcx, ctxt.param_env) { @@ -263,7 +263,7 @@ pub(crate) fn drop_flag_effects_for_location<'a, 'tcx, F>( // don't move out of non-Copy things let lvalue = &move_data.move_paths[path].lvalue; - let ty = lvalue.ty(mir, tcx).to_ty(tcx); + let ty = lvalue.ty(&mir.local_decls, tcx).to_ty(tcx); if !ty.moves_by_default(tcx, param_env, DUMMY_SP) { continue; } diff --git a/src/librustc_mir/dataflow/move_paths/mod.rs b/src/librustc_mir/dataflow/move_paths/mod.rs index d7ed0938e886a..e92ece7505f6d 100644 --- a/src/librustc_mir/dataflow/move_paths/mod.rs +++ b/src/librustc_mir/dataflow/move_paths/mod.rs @@ -286,7 +286,7 @@ impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> { -> Result { let base = try!(self.move_path_for(&proj.base)); - let lv_ty = proj.base.ty(self.mir, self.tcx).to_ty(self.tcx); + let lv_ty = proj.base.ty(&self.mir.local_decls, self.tcx).to_ty(self.tcx); match lv_ty.sty { // error: can't move out of borrowed content ty::TyRef(..) | ty::TyRawPtr(..) => return Err(MovePathError::IllegalMove), @@ -504,7 +504,7 @@ impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> { fn gather_move(&mut self, loc: Location, lval: &Lvalue<'tcx>) { debug!("gather_move({:?}, {:?})", loc, lval); - let lv_ty = lval.ty(self.mir, self.tcx).to_ty(self.tcx); + let lv_ty = lval.ty(&self.mir.local_decls, self.tcx).to_ty(self.tcx); if !lv_ty.moves_by_default(self.tcx, self.param_env, DUMMY_SP) { debug!("gather_move({:?}, {:?}) - {:?} is Copy. skipping", loc, lval, lv_ty); return diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 5f80c7bee1478..db951a7fef8c1 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -250,7 +250,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { work_list.push(target); // If the location doesn't actually need dropping, treat it like // a regular goto. - let ty = location.ty(&callee_mir, tcx).subst(tcx, callsite.substs); + let ty = location.ty(&callee_mir.local_decls, tcx).subst(tcx, callsite.substs); let ty = ty.to_ty(tcx); if ty.needs_drop(tcx, param_env) { cost += CALL_PENALTY; @@ -390,7 +390,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { BorrowKind::Mut, destination.0); - let ty = dest.ty(caller_mir, self.tcx); + let ty = dest.ty(&caller_mir.local_decls, self.tcx); let temp = LocalDecl::new_temp(ty, callsite.location.span); @@ -422,7 +422,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { bug!("Constant arg to \"box_free\""); }; - let ptr_ty = args[0].ty(caller_mir, self.tcx); + let ptr_ty = args[0].ty(&caller_mir.local_decls, self.tcx); vec![self.cast_box_free_arg(arg, ptr_ty, &callsite, caller_mir)] } else { // Copy the arguments if needed. @@ -475,7 +475,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { BorrowKind::Mut, arg.deref()); - let ty = arg.ty(caller_mir, self.tcx); + let ty = arg.ty(&caller_mir.local_decls, self.tcx); let ref_tmp = LocalDecl::new_temp(ty, callsite.location.span); let ref_tmp = caller_mir.local_decls.push(ref_tmp); let ref_tmp = Lvalue::Local(ref_tmp); @@ -529,7 +529,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { // Otherwise, create a temporary for the arg let arg = Rvalue::Use(a); - let ty = arg.ty(caller_mir, tcx); + let ty = arg.ty(&caller_mir.local_decls, tcx); let arg_tmp = LocalDecl::new_temp(ty, callsite.location.span); let arg_tmp = caller_mir.local_decls.push(arg_tmp); diff --git a/src/librustc_mir/transform/instcombine.rs b/src/librustc_mir/transform/instcombine.rs index 88a368077d4f5..65d20d3be8768 100644 --- a/src/librustc_mir/transform/instcombine.rs +++ b/src/librustc_mir/transform/instcombine.rs @@ -87,7 +87,7 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for OptimizationFinder<'b, 'a, 'tcx> { fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { if let Rvalue::Ref(_, _, Lvalue::Projection(ref projection)) = *rvalue { if let ProjectionElem::Deref = projection.elem { - if projection.base.ty(self.mir, self.tcx).to_ty(self.tcx).is_region_ptr() { + if projection.base.ty(&self.mir.local_decls, self.tcx).to_ty(self.tcx).is_region_ptr() { self.optimizations.and_stars.insert(location); } } diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index e1c4602b045eb..8cb6c0b055e7f 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -362,13 +362,13 @@ pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>, continue; } } - (statement.source_info.span, dest.ty(mir, tcx).to_ty(tcx)) + (statement.source_info.span, dest.ty(&mir.local_decls, tcx).to_ty(tcx)) } Candidate::ShuffleIndices(bb) => { let terminator = mir[bb].terminator(); let ty = match terminator.kind { TerminatorKind::Call { ref args, .. } => { - args[2].ty(mir, tcx) + args[2].ty(&mir.local_decls, tcx) } _ => { span_bug!(terminator.source_info.span, diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 68b687a2e6182..3180133b05a51 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -507,7 +507,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { this.add(Qualif::STATIC); } - let base_ty = proj.base.ty(this.mir, this.tcx).to_ty(this.tcx); + let base_ty = proj.base.ty(&this.mir.local_decls, this.tcx).to_ty(this.tcx); if let ty::TyRawPtr(_) = base_ty.sty { this.add(Qualif::NOT_CONST); if this.mode != Mode::Fn { @@ -530,7 +530,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { "cannot refer to the interior of another \ static, use a constant instead"); } - let ty = lvalue.ty(this.mir, this.tcx).to_ty(this.tcx); + let ty = lvalue.ty(&this.mir.local_decls, this.tcx).to_ty(this.tcx); this.qualif.restrict(ty, this.tcx, this.param_env); } @@ -606,7 +606,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { self.add(Qualif::STATIC_REF); } - let ty = lvalue.ty(self.mir, self.tcx).to_ty(self.tcx); + let ty = lvalue.ty(&self.mir.local_decls, self.tcx).to_ty(self.tcx); if kind == BorrowKind::Mut { // In theory, any zero-sized value could be borrowed // mutably without consequences. However, only &mut [] @@ -671,7 +671,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { } Rvalue::Cast(CastKind::Misc, ref operand, cast_ty) => { - let operand_ty = operand.ty(self.mir, self.tcx); + let operand_ty = operand.ty(&self.mir.local_decls, self.tcx); let cast_in = CastTy::from_ty(operand_ty).expect("bad input type for cast"); let cast_out = CastTy::from_ty(cast_ty).expect("bad output type for cast"); match (cast_in, cast_out) { @@ -689,7 +689,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { } Rvalue::BinaryOp(op, ref lhs, _) => { - if let ty::TyRawPtr(_) = lhs.ty(self.mir, self.tcx).sty { + if let ty::TyRawPtr(_) = lhs.ty(&self.mir.local_decls, self.tcx).sty { assert!(op == BinOp::Eq || op == BinOp::Ne || op == BinOp::Le || op == BinOp::Lt || op == BinOp::Ge || op == BinOp::Gt || @@ -727,7 +727,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { } if Some(def.did) == self.tcx.lang_items.unsafe_cell_type() { - let ty = rvalue.ty(self.mir, self.tcx); + let ty = rvalue.ty(&self.mir.local_decls, self.tcx); self.add_type(ty); assert!(self.qualif.intersects(Qualif::MUTABLE_INTERIOR)); // Even if the value inside may not need dropping, @@ -748,7 +748,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { if let TerminatorKind::Call { ref func, ref args, ref destination, .. } = *kind { self.visit_operand(func, location); - let fn_ty = func.ty(self.mir, self.tcx); + let fn_ty = func.ty(&self.mir.local_decls, self.tcx); let (is_shuffle, is_const_fn) = match fn_ty.sty { ty::TyFnDef(def_id, _) => { (self.tcx.fn_sig(def_id).abi() == Abi::PlatformIntrinsic && @@ -828,7 +828,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { } else { // Be conservative about the returned value of a const fn. let tcx = self.tcx; - let ty = dest.ty(self.mir, tcx).to_ty(tcx); + let ty = dest.ty(&self.mir.local_decls, tcx).to_ty(tcx); self.qualif = Qualif::empty(); self.add_type(ty); diff --git a/src/librustc_mir/transform/type_check.rs b/src/librustc_mir/transform/type_check.rs index 7e6fccf30192c..1175f955b4ed0 100644 --- a/src/librustc_mir/transform/type_check.rs +++ b/src/librustc_mir/transform/type_check.rs @@ -84,7 +84,7 @@ impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> { fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { self.super_rvalue(rvalue, location); - let rval_ty = rvalue.ty(self.mir, self.tcx()); + let rval_ty = rvalue.ty(&self.mir.local_decls, self.tcx()); self.sanitize_type(rvalue, rval_ty); } @@ -178,7 +178,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> { } ProjectionElem::Index(ref i) => { self.visit_operand(i, location); - let index_ty = i.ty(self.mir, tcx); + let index_ty = i.ty(&self.mir.local_decls, tcx); if index_ty != tcx.types.usize { LvalueTy::Ty { ty: span_mirbug_and_err!(self, i, "index by non-usize {:?}", i) @@ -378,15 +378,15 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { let tcx = self.tcx(); match stmt.kind { StatementKind::Assign(ref lv, ref rv) => { - let lv_ty = lv.ty(mir, tcx).to_ty(tcx); - let rv_ty = rv.ty(mir, tcx); + let lv_ty = lv.ty(&mir.local_decls, tcx).to_ty(tcx); + let rv_ty = rv.ty(&mir.local_decls, tcx); if let Err(terr) = self.sub_types(rv_ty, lv_ty) { span_mirbug!(self, stmt, "bad assignment ({:?} = {:?}): {:?}", lv_ty, rv_ty, terr); } } StatementKind::SetDiscriminant{ ref lvalue, variant_index } => { - let lvalue_type = lvalue.ty(mir, tcx).to_ty(tcx); + let lvalue_type = lvalue.ty(&mir.local_decls, tcx).to_ty(tcx); let adt = match lvalue_type.sty { TypeVariants::TyAdt(adt, _) if adt.is_enum() => adt, _ => { @@ -438,15 +438,15 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { ref value, .. } => { - let lv_ty = location.ty(mir, tcx).to_ty(tcx); - let rv_ty = value.ty(mir, tcx); + let lv_ty = location.ty(&mir.local_decls, tcx).to_ty(tcx); + let rv_ty = value.ty(&mir.local_decls, tcx); if let Err(terr) = self.sub_types(rv_ty, lv_ty) { span_mirbug!(self, term, "bad DropAndReplace ({:?} = {:?}): {:?}", lv_ty, rv_ty, terr); } } TerminatorKind::SwitchInt { ref discr, switch_ty, .. } => { - let discr_ty = discr.ty(mir, tcx); + let discr_ty = discr.ty(&mir.local_decls, tcx); if let Err(terr) = self.sub_types(discr_ty, switch_ty) { span_mirbug!(self, term, "bad SwitchInt ({:?} on {:?}): {:?}", switch_ty, discr_ty, terr); @@ -459,7 +459,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { // FIXME: check the values } TerminatorKind::Call { ref func, ref args, ref destination, .. } => { - let func_ty = func.ty(mir, tcx); + let func_ty = func.ty(&mir.local_decls, tcx); debug!("check_terminator: call, func_ty={:?}", func_ty); let sig = match func_ty.sty { ty::TyFnDef(..) | ty::TyFnPtr(_) => func_ty.fn_sig(tcx), @@ -479,16 +479,16 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { } } TerminatorKind::Assert { ref cond, ref msg, .. } => { - let cond_ty = cond.ty(mir, tcx); + let cond_ty = cond.ty(&mir.local_decls, tcx); if cond_ty != tcx.types.bool { span_mirbug!(self, term, "bad Assert ({:?}, not bool", cond_ty); } if let AssertMessage::BoundsCheck { ref len, ref index } = *msg { - if len.ty(mir, tcx) != tcx.types.usize { + if len.ty(&mir.local_decls, tcx) != tcx.types.usize { span_mirbug!(self, len, "bounds-check length non-usize {:?}", len) } - if index.ty(mir, tcx) != tcx.types.usize { + if index.ty(&mir.local_decls, tcx) != tcx.types.usize { span_mirbug!(self, index, "bounds-check index non-usize {:?}", index) } } @@ -504,7 +504,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { let tcx = self.tcx(); match *destination { Some((ref dest, _)) => { - let dest_ty = dest.ty(mir, tcx).to_ty(tcx); + let dest_ty = dest.ty(&mir.local_decls, tcx).to_ty(tcx); if let Err(terr) = self.sub_types(sig.output(), dest_ty) { span_mirbug!(self, term, "call dest mismatch ({:?} <- {:?}): {:?}", @@ -532,7 +532,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { span_mirbug!(self, term, "call to {:?} with wrong # of args", sig); } for (n, (fn_arg, op_arg)) in sig.inputs().iter().zip(args).enumerate() { - let op_arg_ty = op_arg.ty(mir, self.tcx()); + let op_arg_ty = op_arg.ty(&mir.local_decls, self.tcx()); if let Err(terr) = self.sub_types(op_arg_ty, fn_arg) { span_mirbug!(self, term, "bad arg #{:?} ({:?} <- {:?}): {:?}", n, fn_arg, op_arg_ty, terr); @@ -581,7 +581,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { return; } - let ty = args[0].ty(mir, self.tcx()); + let ty = args[0].ty(&mir.local_decls, self.tcx()); let arg_ty = match ty.sty { ty::TyRawPtr(mt) => mt.ty, ty::TyAdt(def, _) if def.is_box() => ty.boxed_ty(), diff --git a/src/librustc_mir/util/elaborate_drops.rs b/src/librustc_mir/util/elaborate_drops.rs index da7e218439cf0..efeffbbe7d140 100644 --- a/src/librustc_mir/util/elaborate_drops.rs +++ b/src/librustc_mir/util/elaborate_drops.rs @@ -130,7 +130,7 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D> where D: DropElaborator<'b, 'tcx> { fn lvalue_ty(&self, lvalue: &Lvalue<'tcx>) -> Ty<'tcx> { - lvalue.ty(self.elaborator.mir(), self.tcx()).to_ty(self.tcx()) + lvalue.ty(&self.elaborator.mir().local_decls, self.tcx()).to_ty(self.tcx()) } fn tcx(&self) -> ty::TyCtxt<'b, 'tcx, 'tcx> { diff --git a/src/librustc_trans/collector.rs b/src/librustc_trans/collector.rs index a76abcf7b49a6..4eb7efc593d8e 100644 --- a/src/librustc_trans/collector.rs +++ b/src/librustc_trans/collector.rs @@ -474,7 +474,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { mir::Rvalue::Cast(mir::CastKind::Unsize, ref operand, target_ty) => { let target_ty = self.scx.tcx().trans_apply_param_substs(self.param_substs, &target_ty); - let source_ty = operand.ty(self.mir, self.scx.tcx()); + let source_ty = operand.ty(&self.mir.local_decls, self.scx.tcx()); let source_ty = self.scx.tcx().trans_apply_param_substs(self.param_substs, &source_ty); let (source_ty, target_ty) = find_vtable_types_for_unsizing(self.scx, @@ -491,13 +491,13 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { } } mir::Rvalue::Cast(mir::CastKind::ReifyFnPointer, ref operand, _) => { - let fn_ty = operand.ty(self.mir, self.scx.tcx()); + let fn_ty = operand.ty(&self.mir.local_decls, self.scx.tcx()); let fn_ty = self.scx.tcx().trans_apply_param_substs(self.param_substs, &fn_ty); visit_fn_use(self.scx, fn_ty, false, &mut self.output); } mir::Rvalue::Cast(mir::CastKind::ClosureFnPointer, ref operand, _) => { - let source_ty = operand.ty(self.mir, self.scx.tcx()); + let source_ty = operand.ty(&self.mir.local_decls, self.scx.tcx()); let source_ty = self.scx.tcx().trans_apply_param_substs(self.param_substs, &source_ty); match source_ty.sty { @@ -555,13 +555,13 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { let tcx = self.scx.tcx(); match *kind { mir::TerminatorKind::Call { ref func, .. } => { - let callee_ty = func.ty(self.mir, tcx); + let callee_ty = func.ty(&self.mir.local_decls, tcx); let callee_ty = tcx.trans_apply_param_substs(self.param_substs, &callee_ty); visit_fn_use(self.scx, callee_ty, true, &mut self.output); } mir::TerminatorKind::Drop { ref location, .. } | mir::TerminatorKind::DropAndReplace { ref location, .. } => { - let ty = location.ty(self.mir, self.scx.tcx()) + let ty = location.ty(&self.mir.local_decls, self.scx.tcx()) .to_ty(self.scx.tcx()); let ty = tcx.trans_apply_param_substs(self.param_substs, &ty); visit_drop_use(self.scx, ty, true, self.output); diff --git a/src/librustc_trans/mir/analyze.rs b/src/librustc_trans/mir/analyze.rs index 45afcf51b5203..5c9f6f3b2976d 100644 --- a/src/librustc_trans/mir/analyze.rs +++ b/src/librustc_trans/mir/analyze.rs @@ -137,7 +137,7 @@ impl<'mir, 'a, 'tcx> Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'tcx> { // Allow uses of projections of immediate pair fields. if let mir::Lvalue::Projection(ref proj) = *lvalue { if let mir::Lvalue::Local(_) = proj.base { - let ty = proj.base.ty(self.cx.mir, self.cx.ccx.tcx()); + let ty = proj.base.ty(&self.cx.mir.local_decls, self.cx.ccx.tcx()); let ty = self.cx.monomorphize(&ty.to_ty(self.cx.ccx.tcx())); if common::type_is_imm_pair(self.cx.ccx, ty) { @@ -168,7 +168,7 @@ impl<'mir, 'a, 'tcx> Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'tcx> { } LvalueContext::Drop => { - let ty = lvalue.ty(self.cx.mir, self.cx.ccx.tcx()); + let ty = lvalue.ty(&self.cx.mir.local_decls, self.cx.ccx.tcx()); let ty = self.cx.monomorphize(&ty.to_ty(self.cx.ccx.tcx())); // Only need the lvalue if we're actually dropping it. diff --git a/src/librustc_trans/mir/block.rs b/src/librustc_trans/mir/block.rs index 48b166c61deb1..8cc1e7879283f 100644 --- a/src/librustc_trans/mir/block.rs +++ b/src/librustc_trans/mir/block.rs @@ -263,7 +263,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { } mir::TerminatorKind::Drop { ref location, target, unwind } => { - let ty = location.ty(&self.mir, bcx.tcx()).to_ty(bcx.tcx()); + let ty = location.ty(&self.mir.local_decls, bcx.tcx()).to_ty(bcx.tcx()); let ty = self.monomorphize(&ty); let drop_fn = monomorphize::resolve_drop_in_place(bcx.ccx.shared(), ty); @@ -438,7 +438,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { let extra_args = &args[sig.inputs().len()..]; let extra_args = extra_args.iter().map(|op_arg| { - let op_ty = op_arg.ty(&self.mir, bcx.tcx()); + let op_ty = op_arg.ty(&self.mir.local_decls, bcx.tcx()); self.monomorphize(&op_ty) }).collect::>(); diff --git a/src/librustc_trans/mir/constant.rs b/src/librustc_trans/mir/constant.rs index fcb4b25e6fe88..d2479f1d88378 100644 --- a/src/librustc_trans/mir/constant.rs +++ b/src/librustc_trans/mir/constant.rs @@ -275,7 +275,7 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> { let span = statement.source_info.span; match statement.kind { mir::StatementKind::Assign(ref dest, ref rvalue) => { - let ty = dest.ty(self.mir, tcx); + let ty = dest.ty(&self.mir.local_decls, tcx); let ty = self.monomorphize(&ty).to_ty(tcx); match self.const_rvalue(rvalue, ty, span) { Ok(value) => self.store(dest, value, span), @@ -331,7 +331,7 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> { } mir::TerminatorKind::Call { ref func, ref args, ref destination, .. } => { - let fn_ty = func.ty(self.mir, tcx); + let fn_ty = func.ty(&self.mir.local_decls, tcx); let fn_ty = self.monomorphize(&fn_ty); let (def_id, substs) = match fn_ty.sty { ty::TyFnDef(def_id, substs) => (def_id, substs), diff --git a/src/librustc_trans/mir/lvalue.rs b/src/librustc_trans/mir/lvalue.rs index 88e46b5c99a44..40cbb4e6537cb 100644 --- a/src/librustc_trans/mir/lvalue.rs +++ b/src/librustc_trans/mir/lvalue.rs @@ -408,7 +408,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { pub fn monomorphized_lvalue_ty(&self, lvalue: &mir::Lvalue<'tcx>) -> Ty<'tcx> { let tcx = self.ccx.tcx(); - let lvalue_ty = lvalue.ty(&self.mir, tcx); + let lvalue_ty = lvalue.ty(&self.mir.local_decls, tcx); self.monomorphize(&lvalue_ty.to_ty(tcx)) } } diff --git a/src/librustc_trans/mir/rvalue.rs b/src/librustc_trans/mir/rvalue.rs index 4bd5091a4f35f..695dd278bc8e6 100644 --- a/src/librustc_trans/mir/rvalue.rs +++ b/src/librustc_trans/mir/rvalue.rs @@ -422,7 +422,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { mir::Rvalue::Discriminant(ref lvalue) => { let discr_lvalue = self.trans_lvalue(&bcx, lvalue); let enum_ty = discr_lvalue.ty.to_ty(bcx.tcx()); - let discr_ty = rvalue.ty(&*self.mir, bcx.tcx()); + let discr_ty = rvalue.ty(&self.mir.local_decls, bcx.tcx()); let discr_type = type_of::immediate_type_of(bcx.ccx, discr_ty); let discr = adt::trans_get_discr(&bcx, enum_ty, discr_lvalue.llval, discr_lvalue.alignment, Some(discr_type), true); @@ -476,7 +476,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { mir::Rvalue::Aggregate(..) => { // According to `rvalue_creates_operand`, only ZST // aggregate rvalues are allowed to be operands. - let ty = rvalue.ty(self.mir, self.ccx.tcx()); + let ty = rvalue.ty(&self.mir.local_decls, self.ccx.tcx()); (bcx, OperandRef::new_zst(self.ccx, self.monomorphize(&ty))) } } @@ -676,7 +676,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { true, mir::Rvalue::Repeat(..) | mir::Rvalue::Aggregate(..) => { - let ty = rvalue.ty(self.mir, self.ccx.tcx()); + let ty = rvalue.ty(&self.mir.local_decls, self.ccx.tcx()); let ty = self.monomorphize(&ty); common::type_is_zero_size(self.ccx, ty) } From 66fce33ecb56c8aae8d77ffd4fc0562aadf66a0b Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 12 Jul 2017 12:59:05 -0700 Subject: [PATCH 2/4] overload the mir ty methods to make them more ergonomic to use --- src/librustc/mir/mod.rs | 16 ++++++++++ src/librustc/mir/tcx.rs | 8 ++--- .../dataflow/drop_flag_effects.rs | 6 ++-- src/librustc_mir/dataflow/move_paths/mod.rs | 4 +-- src/librustc_mir/transform/inline.rs | 10 +++---- src/librustc_mir/transform/instcombine.rs | 2 +- src/librustc_mir/transform/promote_consts.rs | 4 +-- src/librustc_mir/transform/qualify_consts.rs | 16 +++++----- src/librustc_mir/transform/type_check.rs | 30 +++++++++---------- src/librustc_mir/util/elaborate_drops.rs | 2 +- src/librustc_trans/collector.rs | 10 +++---- src/librustc_trans/mir/analyze.rs | 4 +-- src/librustc_trans/mir/block.rs | 4 +-- src/librustc_trans/mir/constant.rs | 4 +-- src/librustc_trans/mir/lvalue.rs | 2 +- src/librustc_trans/mir/rvalue.rs | 6 ++-- 16 files changed, 72 insertions(+), 56 deletions(-) diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 8ac4e1208b0cb..ba38d97d09261 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -69,6 +69,22 @@ macro_rules! newtype_index { /// Types for locals type LocalDecls<'tcx> = IndexVec>; +pub trait AsLocalDeclsRef<'tcx> { + fn as_ref(&self) -> &LocalDecls<'tcx>; +} + +impl<'tcx> AsLocalDeclsRef<'tcx> for LocalDecls<'tcx> { + fn as_ref(&self) -> &LocalDecls<'tcx> { + self + } +} + +impl<'tcx> AsLocalDeclsRef<'tcx> for Mir<'tcx> { + fn as_ref(&self) -> &LocalDecls<'tcx> { + &self.local_decls + } +} + /// Lowered representation of a single function. #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct Mir<'tcx> { diff --git a/src/librustc/mir/tcx.rs b/src/librustc/mir/tcx.rs index b99c0180eccfd..c99fffe2198b8 100644 --- a/src/librustc/mir/tcx.rs +++ b/src/librustc/mir/tcx.rs @@ -121,10 +121,10 @@ impl<'tcx> TypeFoldable<'tcx> for LvalueTy<'tcx> { } impl<'tcx> Lvalue<'tcx> { - pub fn ty<'a, 'gcx>(&self, local_decls: &LocalDecls<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> LvalueTy<'tcx> { + pub fn ty<'a, 'gcx, D: AsLocalDeclsRef<'tcx>>(&self, local_decls: &D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> LvalueTy<'tcx> { match *self { Lvalue::Local(index) => - LvalueTy::Ty { ty: local_decls[index].ty }, + LvalueTy::Ty { ty: local_decls.as_ref()[index].ty }, Lvalue::Static(ref data) => LvalueTy::Ty { ty: data.ty }, Lvalue::Projection(ref proj) => @@ -134,7 +134,7 @@ impl<'tcx> Lvalue<'tcx> { } impl<'tcx> Rvalue<'tcx> { - pub fn ty<'a, 'gcx>(&self, local_decls: &LocalDecls<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> + pub fn ty<'a, 'gcx, D: AsLocalDeclsRef<'tcx>>(&self, local_decls: &D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> { match *self { Rvalue::Use(ref operand) => operand.ty(local_decls, tcx), @@ -206,7 +206,7 @@ impl<'tcx> Rvalue<'tcx> { } impl<'tcx> Operand<'tcx> { - pub fn ty<'a, 'gcx>(&self, local_decls: &LocalDecls<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> { + pub fn ty<'a, 'gcx, D: AsLocalDeclsRef<'tcx>>(&self, local_decls: &D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> { match self { &Operand::Consume(ref l) => l.ty(local_decls, tcx).to_ty(tcx), &Operand::Constant(ref c) => c.ty, diff --git a/src/librustc_mir/dataflow/drop_flag_effects.rs b/src/librustc_mir/dataflow/drop_flag_effects.rs index a247cd774501e..daafbecc5dfa3 100644 --- a/src/librustc_mir/dataflow/drop_flag_effects.rs +++ b/src/librustc_mir/dataflow/drop_flag_effects.rs @@ -129,7 +129,7 @@ pub fn move_path_children_matching<'tcx, F>(move_data: &MoveData<'tcx>, fn lvalue_contents_drop_state_cannot_differ<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, mir: &Mir<'tcx>, lv: &mir::Lvalue<'tcx>) -> bool { - let ty = lv.ty(&mir.local_decls, tcx).to_ty(tcx); + let ty = lv.ty(mir, tcx).to_ty(tcx); match ty.sty { ty::TyArray(..) | ty::TySlice(..) | ty::TyRef(..) | ty::TyRawPtr(..) => { debug!("lvalue_contents_drop_state_cannot_differ lv: {:?} ty: {:?} refd => true", @@ -216,7 +216,7 @@ pub(crate) fn on_all_drop_children_bits<'a, 'tcx, F>( { on_all_children_bits(tcx, mir, &ctxt.move_data, path, |child| { let lvalue = &ctxt.move_data.move_paths[path].lvalue; - let ty = lvalue.ty(&mir.local_decls, tcx).to_ty(tcx); + let ty = lvalue.ty(mir, tcx).to_ty(tcx); debug!("on_all_drop_children_bits({:?}, {:?} : {:?})", path, lvalue, ty); if ty.needs_drop(tcx, ctxt.param_env) { @@ -263,7 +263,7 @@ pub(crate) fn drop_flag_effects_for_location<'a, 'tcx, F>( // don't move out of non-Copy things let lvalue = &move_data.move_paths[path].lvalue; - let ty = lvalue.ty(&mir.local_decls, tcx).to_ty(tcx); + let ty = lvalue.ty(mir, tcx).to_ty(tcx); if !ty.moves_by_default(tcx, param_env, DUMMY_SP) { continue; } diff --git a/src/librustc_mir/dataflow/move_paths/mod.rs b/src/librustc_mir/dataflow/move_paths/mod.rs index e92ece7505f6d..d7ed0938e886a 100644 --- a/src/librustc_mir/dataflow/move_paths/mod.rs +++ b/src/librustc_mir/dataflow/move_paths/mod.rs @@ -286,7 +286,7 @@ impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> { -> Result { let base = try!(self.move_path_for(&proj.base)); - let lv_ty = proj.base.ty(&self.mir.local_decls, self.tcx).to_ty(self.tcx); + let lv_ty = proj.base.ty(self.mir, self.tcx).to_ty(self.tcx); match lv_ty.sty { // error: can't move out of borrowed content ty::TyRef(..) | ty::TyRawPtr(..) => return Err(MovePathError::IllegalMove), @@ -504,7 +504,7 @@ impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> { fn gather_move(&mut self, loc: Location, lval: &Lvalue<'tcx>) { debug!("gather_move({:?}, {:?})", loc, lval); - let lv_ty = lval.ty(&self.mir.local_decls, self.tcx).to_ty(self.tcx); + let lv_ty = lval.ty(self.mir, self.tcx).to_ty(self.tcx); if !lv_ty.moves_by_default(self.tcx, self.param_env, DUMMY_SP) { debug!("gather_move({:?}, {:?}) - {:?} is Copy. skipping", loc, lval, lv_ty); return diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index db951a7fef8c1..d3fee8045e6e3 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -250,7 +250,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { work_list.push(target); // If the location doesn't actually need dropping, treat it like // a regular goto. - let ty = location.ty(&callee_mir.local_decls, tcx).subst(tcx, callsite.substs); + let ty = location.ty(callee_mir, tcx).subst(tcx, callsite.substs); let ty = ty.to_ty(tcx); if ty.needs_drop(tcx, param_env) { cost += CALL_PENALTY; @@ -390,7 +390,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { BorrowKind::Mut, destination.0); - let ty = dest.ty(&caller_mir.local_decls, self.tcx); + let ty = dest.ty(caller_mir, self.tcx); let temp = LocalDecl::new_temp(ty, callsite.location.span); @@ -422,7 +422,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { bug!("Constant arg to \"box_free\""); }; - let ptr_ty = args[0].ty(&caller_mir.local_decls, self.tcx); + let ptr_ty = args[0].ty(caller_mir, self.tcx); vec![self.cast_box_free_arg(arg, ptr_ty, &callsite, caller_mir)] } else { // Copy the arguments if needed. @@ -475,7 +475,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { BorrowKind::Mut, arg.deref()); - let ty = arg.ty(&caller_mir.local_decls, self.tcx); + let ty = arg.ty(caller_mir, self.tcx); let ref_tmp = LocalDecl::new_temp(ty, callsite.location.span); let ref_tmp = caller_mir.local_decls.push(ref_tmp); let ref_tmp = Lvalue::Local(ref_tmp); @@ -529,7 +529,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { // Otherwise, create a temporary for the arg let arg = Rvalue::Use(a); - let ty = arg.ty(&caller_mir.local_decls, tcx); + let ty = arg.ty(caller_mir, tcx); let arg_tmp = LocalDecl::new_temp(ty, callsite.location.span); let arg_tmp = caller_mir.local_decls.push(arg_tmp); diff --git a/src/librustc_mir/transform/instcombine.rs b/src/librustc_mir/transform/instcombine.rs index 65d20d3be8768..88a368077d4f5 100644 --- a/src/librustc_mir/transform/instcombine.rs +++ b/src/librustc_mir/transform/instcombine.rs @@ -87,7 +87,7 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for OptimizationFinder<'b, 'a, 'tcx> { fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { if let Rvalue::Ref(_, _, Lvalue::Projection(ref projection)) = *rvalue { if let ProjectionElem::Deref = projection.elem { - if projection.base.ty(&self.mir.local_decls, self.tcx).to_ty(self.tcx).is_region_ptr() { + if projection.base.ty(self.mir, self.tcx).to_ty(self.tcx).is_region_ptr() { self.optimizations.and_stars.insert(location); } } diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index 8cb6c0b055e7f..e1c4602b045eb 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -362,13 +362,13 @@ pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>, continue; } } - (statement.source_info.span, dest.ty(&mir.local_decls, tcx).to_ty(tcx)) + (statement.source_info.span, dest.ty(mir, tcx).to_ty(tcx)) } Candidate::ShuffleIndices(bb) => { let terminator = mir[bb].terminator(); let ty = match terminator.kind { TerminatorKind::Call { ref args, .. } => { - args[2].ty(&mir.local_decls, tcx) + args[2].ty(mir, tcx) } _ => { span_bug!(terminator.source_info.span, diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 3180133b05a51..68b687a2e6182 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -507,7 +507,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { this.add(Qualif::STATIC); } - let base_ty = proj.base.ty(&this.mir.local_decls, this.tcx).to_ty(this.tcx); + let base_ty = proj.base.ty(this.mir, this.tcx).to_ty(this.tcx); if let ty::TyRawPtr(_) = base_ty.sty { this.add(Qualif::NOT_CONST); if this.mode != Mode::Fn { @@ -530,7 +530,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { "cannot refer to the interior of another \ static, use a constant instead"); } - let ty = lvalue.ty(&this.mir.local_decls, this.tcx).to_ty(this.tcx); + let ty = lvalue.ty(this.mir, this.tcx).to_ty(this.tcx); this.qualif.restrict(ty, this.tcx, this.param_env); } @@ -606,7 +606,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { self.add(Qualif::STATIC_REF); } - let ty = lvalue.ty(&self.mir.local_decls, self.tcx).to_ty(self.tcx); + let ty = lvalue.ty(self.mir, self.tcx).to_ty(self.tcx); if kind == BorrowKind::Mut { // In theory, any zero-sized value could be borrowed // mutably without consequences. However, only &mut [] @@ -671,7 +671,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { } Rvalue::Cast(CastKind::Misc, ref operand, cast_ty) => { - let operand_ty = operand.ty(&self.mir.local_decls, self.tcx); + let operand_ty = operand.ty(self.mir, self.tcx); let cast_in = CastTy::from_ty(operand_ty).expect("bad input type for cast"); let cast_out = CastTy::from_ty(cast_ty).expect("bad output type for cast"); match (cast_in, cast_out) { @@ -689,7 +689,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { } Rvalue::BinaryOp(op, ref lhs, _) => { - if let ty::TyRawPtr(_) = lhs.ty(&self.mir.local_decls, self.tcx).sty { + if let ty::TyRawPtr(_) = lhs.ty(self.mir, self.tcx).sty { assert!(op == BinOp::Eq || op == BinOp::Ne || op == BinOp::Le || op == BinOp::Lt || op == BinOp::Ge || op == BinOp::Gt || @@ -727,7 +727,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { } if Some(def.did) == self.tcx.lang_items.unsafe_cell_type() { - let ty = rvalue.ty(&self.mir.local_decls, self.tcx); + let ty = rvalue.ty(self.mir, self.tcx); self.add_type(ty); assert!(self.qualif.intersects(Qualif::MUTABLE_INTERIOR)); // Even if the value inside may not need dropping, @@ -748,7 +748,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { if let TerminatorKind::Call { ref func, ref args, ref destination, .. } = *kind { self.visit_operand(func, location); - let fn_ty = func.ty(&self.mir.local_decls, self.tcx); + let fn_ty = func.ty(self.mir, self.tcx); let (is_shuffle, is_const_fn) = match fn_ty.sty { ty::TyFnDef(def_id, _) => { (self.tcx.fn_sig(def_id).abi() == Abi::PlatformIntrinsic && @@ -828,7 +828,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> { } else { // Be conservative about the returned value of a const fn. let tcx = self.tcx; - let ty = dest.ty(&self.mir.local_decls, tcx).to_ty(tcx); + let ty = dest.ty(self.mir, tcx).to_ty(tcx); self.qualif = Qualif::empty(); self.add_type(ty); diff --git a/src/librustc_mir/transform/type_check.rs b/src/librustc_mir/transform/type_check.rs index 1175f955b4ed0..7e6fccf30192c 100644 --- a/src/librustc_mir/transform/type_check.rs +++ b/src/librustc_mir/transform/type_check.rs @@ -84,7 +84,7 @@ impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> { fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { self.super_rvalue(rvalue, location); - let rval_ty = rvalue.ty(&self.mir.local_decls, self.tcx()); + let rval_ty = rvalue.ty(self.mir, self.tcx()); self.sanitize_type(rvalue, rval_ty); } @@ -178,7 +178,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> { } ProjectionElem::Index(ref i) => { self.visit_operand(i, location); - let index_ty = i.ty(&self.mir.local_decls, tcx); + let index_ty = i.ty(self.mir, tcx); if index_ty != tcx.types.usize { LvalueTy::Ty { ty: span_mirbug_and_err!(self, i, "index by non-usize {:?}", i) @@ -378,15 +378,15 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { let tcx = self.tcx(); match stmt.kind { StatementKind::Assign(ref lv, ref rv) => { - let lv_ty = lv.ty(&mir.local_decls, tcx).to_ty(tcx); - let rv_ty = rv.ty(&mir.local_decls, tcx); + let lv_ty = lv.ty(mir, tcx).to_ty(tcx); + let rv_ty = rv.ty(mir, tcx); if let Err(terr) = self.sub_types(rv_ty, lv_ty) { span_mirbug!(self, stmt, "bad assignment ({:?} = {:?}): {:?}", lv_ty, rv_ty, terr); } } StatementKind::SetDiscriminant{ ref lvalue, variant_index } => { - let lvalue_type = lvalue.ty(&mir.local_decls, tcx).to_ty(tcx); + let lvalue_type = lvalue.ty(mir, tcx).to_ty(tcx); let adt = match lvalue_type.sty { TypeVariants::TyAdt(adt, _) if adt.is_enum() => adt, _ => { @@ -438,15 +438,15 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { ref value, .. } => { - let lv_ty = location.ty(&mir.local_decls, tcx).to_ty(tcx); - let rv_ty = value.ty(&mir.local_decls, tcx); + let lv_ty = location.ty(mir, tcx).to_ty(tcx); + let rv_ty = value.ty(mir, tcx); if let Err(terr) = self.sub_types(rv_ty, lv_ty) { span_mirbug!(self, term, "bad DropAndReplace ({:?} = {:?}): {:?}", lv_ty, rv_ty, terr); } } TerminatorKind::SwitchInt { ref discr, switch_ty, .. } => { - let discr_ty = discr.ty(&mir.local_decls, tcx); + let discr_ty = discr.ty(mir, tcx); if let Err(terr) = self.sub_types(discr_ty, switch_ty) { span_mirbug!(self, term, "bad SwitchInt ({:?} on {:?}): {:?}", switch_ty, discr_ty, terr); @@ -459,7 +459,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { // FIXME: check the values } TerminatorKind::Call { ref func, ref args, ref destination, .. } => { - let func_ty = func.ty(&mir.local_decls, tcx); + let func_ty = func.ty(mir, tcx); debug!("check_terminator: call, func_ty={:?}", func_ty); let sig = match func_ty.sty { ty::TyFnDef(..) | ty::TyFnPtr(_) => func_ty.fn_sig(tcx), @@ -479,16 +479,16 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { } } TerminatorKind::Assert { ref cond, ref msg, .. } => { - let cond_ty = cond.ty(&mir.local_decls, tcx); + let cond_ty = cond.ty(mir, tcx); if cond_ty != tcx.types.bool { span_mirbug!(self, term, "bad Assert ({:?}, not bool", cond_ty); } if let AssertMessage::BoundsCheck { ref len, ref index } = *msg { - if len.ty(&mir.local_decls, tcx) != tcx.types.usize { + if len.ty(mir, tcx) != tcx.types.usize { span_mirbug!(self, len, "bounds-check length non-usize {:?}", len) } - if index.ty(&mir.local_decls, tcx) != tcx.types.usize { + if index.ty(mir, tcx) != tcx.types.usize { span_mirbug!(self, index, "bounds-check index non-usize {:?}", index) } } @@ -504,7 +504,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { let tcx = self.tcx(); match *destination { Some((ref dest, _)) => { - let dest_ty = dest.ty(&mir.local_decls, tcx).to_ty(tcx); + let dest_ty = dest.ty(mir, tcx).to_ty(tcx); if let Err(terr) = self.sub_types(sig.output(), dest_ty) { span_mirbug!(self, term, "call dest mismatch ({:?} <- {:?}): {:?}", @@ -532,7 +532,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { span_mirbug!(self, term, "call to {:?} with wrong # of args", sig); } for (n, (fn_arg, op_arg)) in sig.inputs().iter().zip(args).enumerate() { - let op_arg_ty = op_arg.ty(&mir.local_decls, self.tcx()); + let op_arg_ty = op_arg.ty(mir, self.tcx()); if let Err(terr) = self.sub_types(op_arg_ty, fn_arg) { span_mirbug!(self, term, "bad arg #{:?} ({:?} <- {:?}): {:?}", n, fn_arg, op_arg_ty, terr); @@ -581,7 +581,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { return; } - let ty = args[0].ty(&mir.local_decls, self.tcx()); + let ty = args[0].ty(mir, self.tcx()); let arg_ty = match ty.sty { ty::TyRawPtr(mt) => mt.ty, ty::TyAdt(def, _) if def.is_box() => ty.boxed_ty(), diff --git a/src/librustc_mir/util/elaborate_drops.rs b/src/librustc_mir/util/elaborate_drops.rs index efeffbbe7d140..da7e218439cf0 100644 --- a/src/librustc_mir/util/elaborate_drops.rs +++ b/src/librustc_mir/util/elaborate_drops.rs @@ -130,7 +130,7 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D> where D: DropElaborator<'b, 'tcx> { fn lvalue_ty(&self, lvalue: &Lvalue<'tcx>) -> Ty<'tcx> { - lvalue.ty(&self.elaborator.mir().local_decls, self.tcx()).to_ty(self.tcx()) + lvalue.ty(self.elaborator.mir(), self.tcx()).to_ty(self.tcx()) } fn tcx(&self) -> ty::TyCtxt<'b, 'tcx, 'tcx> { diff --git a/src/librustc_trans/collector.rs b/src/librustc_trans/collector.rs index 4eb7efc593d8e..a76abcf7b49a6 100644 --- a/src/librustc_trans/collector.rs +++ b/src/librustc_trans/collector.rs @@ -474,7 +474,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { mir::Rvalue::Cast(mir::CastKind::Unsize, ref operand, target_ty) => { let target_ty = self.scx.tcx().trans_apply_param_substs(self.param_substs, &target_ty); - let source_ty = operand.ty(&self.mir.local_decls, self.scx.tcx()); + let source_ty = operand.ty(self.mir, self.scx.tcx()); let source_ty = self.scx.tcx().trans_apply_param_substs(self.param_substs, &source_ty); let (source_ty, target_ty) = find_vtable_types_for_unsizing(self.scx, @@ -491,13 +491,13 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { } } mir::Rvalue::Cast(mir::CastKind::ReifyFnPointer, ref operand, _) => { - let fn_ty = operand.ty(&self.mir.local_decls, self.scx.tcx()); + let fn_ty = operand.ty(self.mir, self.scx.tcx()); let fn_ty = self.scx.tcx().trans_apply_param_substs(self.param_substs, &fn_ty); visit_fn_use(self.scx, fn_ty, false, &mut self.output); } mir::Rvalue::Cast(mir::CastKind::ClosureFnPointer, ref operand, _) => { - let source_ty = operand.ty(&self.mir.local_decls, self.scx.tcx()); + let source_ty = operand.ty(self.mir, self.scx.tcx()); let source_ty = self.scx.tcx().trans_apply_param_substs(self.param_substs, &source_ty); match source_ty.sty { @@ -555,13 +555,13 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { let tcx = self.scx.tcx(); match *kind { mir::TerminatorKind::Call { ref func, .. } => { - let callee_ty = func.ty(&self.mir.local_decls, tcx); + let callee_ty = func.ty(self.mir, tcx); let callee_ty = tcx.trans_apply_param_substs(self.param_substs, &callee_ty); visit_fn_use(self.scx, callee_ty, true, &mut self.output); } mir::TerminatorKind::Drop { ref location, .. } | mir::TerminatorKind::DropAndReplace { ref location, .. } => { - let ty = location.ty(&self.mir.local_decls, self.scx.tcx()) + let ty = location.ty(self.mir, self.scx.tcx()) .to_ty(self.scx.tcx()); let ty = tcx.trans_apply_param_substs(self.param_substs, &ty); visit_drop_use(self.scx, ty, true, self.output); diff --git a/src/librustc_trans/mir/analyze.rs b/src/librustc_trans/mir/analyze.rs index 5c9f6f3b2976d..45afcf51b5203 100644 --- a/src/librustc_trans/mir/analyze.rs +++ b/src/librustc_trans/mir/analyze.rs @@ -137,7 +137,7 @@ impl<'mir, 'a, 'tcx> Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'tcx> { // Allow uses of projections of immediate pair fields. if let mir::Lvalue::Projection(ref proj) = *lvalue { if let mir::Lvalue::Local(_) = proj.base { - let ty = proj.base.ty(&self.cx.mir.local_decls, self.cx.ccx.tcx()); + let ty = proj.base.ty(self.cx.mir, self.cx.ccx.tcx()); let ty = self.cx.monomorphize(&ty.to_ty(self.cx.ccx.tcx())); if common::type_is_imm_pair(self.cx.ccx, ty) { @@ -168,7 +168,7 @@ impl<'mir, 'a, 'tcx> Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'tcx> { } LvalueContext::Drop => { - let ty = lvalue.ty(&self.cx.mir.local_decls, self.cx.ccx.tcx()); + let ty = lvalue.ty(self.cx.mir, self.cx.ccx.tcx()); let ty = self.cx.monomorphize(&ty.to_ty(self.cx.ccx.tcx())); // Only need the lvalue if we're actually dropping it. diff --git a/src/librustc_trans/mir/block.rs b/src/librustc_trans/mir/block.rs index 8cc1e7879283f..9bb29c340d983 100644 --- a/src/librustc_trans/mir/block.rs +++ b/src/librustc_trans/mir/block.rs @@ -263,7 +263,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { } mir::TerminatorKind::Drop { ref location, target, unwind } => { - let ty = location.ty(&self.mir.local_decls, bcx.tcx()).to_ty(bcx.tcx()); + let ty = location.ty(self.mir, bcx.tcx()).to_ty(bcx.tcx()); let ty = self.monomorphize(&ty); let drop_fn = monomorphize::resolve_drop_in_place(bcx.ccx.shared(), ty); @@ -438,7 +438,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { let extra_args = &args[sig.inputs().len()..]; let extra_args = extra_args.iter().map(|op_arg| { - let op_ty = op_arg.ty(&self.mir.local_decls, bcx.tcx()); + let op_ty = op_arg.ty(self.mir, bcx.tcx()); self.monomorphize(&op_ty) }).collect::>(); diff --git a/src/librustc_trans/mir/constant.rs b/src/librustc_trans/mir/constant.rs index d2479f1d88378..fcb4b25e6fe88 100644 --- a/src/librustc_trans/mir/constant.rs +++ b/src/librustc_trans/mir/constant.rs @@ -275,7 +275,7 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> { let span = statement.source_info.span; match statement.kind { mir::StatementKind::Assign(ref dest, ref rvalue) => { - let ty = dest.ty(&self.mir.local_decls, tcx); + let ty = dest.ty(self.mir, tcx); let ty = self.monomorphize(&ty).to_ty(tcx); match self.const_rvalue(rvalue, ty, span) { Ok(value) => self.store(dest, value, span), @@ -331,7 +331,7 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> { } mir::TerminatorKind::Call { ref func, ref args, ref destination, .. } => { - let fn_ty = func.ty(&self.mir.local_decls, tcx); + let fn_ty = func.ty(self.mir, tcx); let fn_ty = self.monomorphize(&fn_ty); let (def_id, substs) = match fn_ty.sty { ty::TyFnDef(def_id, substs) => (def_id, substs), diff --git a/src/librustc_trans/mir/lvalue.rs b/src/librustc_trans/mir/lvalue.rs index 40cbb4e6537cb..af8976967a1e7 100644 --- a/src/librustc_trans/mir/lvalue.rs +++ b/src/librustc_trans/mir/lvalue.rs @@ -408,7 +408,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { pub fn monomorphized_lvalue_ty(&self, lvalue: &mir::Lvalue<'tcx>) -> Ty<'tcx> { let tcx = self.ccx.tcx(); - let lvalue_ty = lvalue.ty(&self.mir.local_decls, tcx); + let lvalue_ty = lvalue.ty(self.mir, tcx); self.monomorphize(&lvalue_ty.to_ty(tcx)) } } diff --git a/src/librustc_trans/mir/rvalue.rs b/src/librustc_trans/mir/rvalue.rs index 695dd278bc8e6..4bd5091a4f35f 100644 --- a/src/librustc_trans/mir/rvalue.rs +++ b/src/librustc_trans/mir/rvalue.rs @@ -422,7 +422,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { mir::Rvalue::Discriminant(ref lvalue) => { let discr_lvalue = self.trans_lvalue(&bcx, lvalue); let enum_ty = discr_lvalue.ty.to_ty(bcx.tcx()); - let discr_ty = rvalue.ty(&self.mir.local_decls, bcx.tcx()); + let discr_ty = rvalue.ty(&*self.mir, bcx.tcx()); let discr_type = type_of::immediate_type_of(bcx.ccx, discr_ty); let discr = adt::trans_get_discr(&bcx, enum_ty, discr_lvalue.llval, discr_lvalue.alignment, Some(discr_type), true); @@ -476,7 +476,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { mir::Rvalue::Aggregate(..) => { // According to `rvalue_creates_operand`, only ZST // aggregate rvalues are allowed to be operands. - let ty = rvalue.ty(&self.mir.local_decls, self.ccx.tcx()); + let ty = rvalue.ty(self.mir, self.ccx.tcx()); (bcx, OperandRef::new_zst(self.ccx, self.monomorphize(&ty))) } } @@ -676,7 +676,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { true, mir::Rvalue::Repeat(..) | mir::Rvalue::Aggregate(..) => { - let ty = rvalue.ty(&self.mir.local_decls, self.ccx.tcx()); + let ty = rvalue.ty(self.mir, self.ccx.tcx()); let ty = self.monomorphize(&ty); common::type_is_zero_size(self.ccx, ty) } From e1ad1909db65562c6289bf692722d4b31b555125 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 12 Jul 2017 13:15:29 -0700 Subject: [PATCH 3/4] rename trait to conform with 'getter trait' pattern --- src/librustc/mir/mod.rs | 12 ++++++------ src/librustc/mir/tcx.rs | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index ba38d97d09261..d176ae761e181 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -69,18 +69,18 @@ macro_rules! newtype_index { /// Types for locals type LocalDecls<'tcx> = IndexVec>; -pub trait AsLocalDeclsRef<'tcx> { - fn as_ref(&self) -> &LocalDecls<'tcx>; +pub trait HasLocalDecls<'tcx> { + fn local_decls(&self) -> &LocalDecls<'tcx>; } -impl<'tcx> AsLocalDeclsRef<'tcx> for LocalDecls<'tcx> { - fn as_ref(&self) -> &LocalDecls<'tcx> { +impl<'tcx> HasLocalDecls<'tcx> for LocalDecls<'tcx> { + fn local_decls(&self) -> &LocalDecls<'tcx> { self } } -impl<'tcx> AsLocalDeclsRef<'tcx> for Mir<'tcx> { - fn as_ref(&self) -> &LocalDecls<'tcx> { +impl<'tcx> HasLocalDecls<'tcx> for Mir<'tcx> { + fn local_decls(&self) -> &LocalDecls<'tcx> { &self.local_decls } } diff --git a/src/librustc/mir/tcx.rs b/src/librustc/mir/tcx.rs index c99fffe2198b8..d3b87c1201dcf 100644 --- a/src/librustc/mir/tcx.rs +++ b/src/librustc/mir/tcx.rs @@ -121,10 +121,10 @@ impl<'tcx> TypeFoldable<'tcx> for LvalueTy<'tcx> { } impl<'tcx> Lvalue<'tcx> { - pub fn ty<'a, 'gcx, D: AsLocalDeclsRef<'tcx>>(&self, local_decls: &D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> LvalueTy<'tcx> { + pub fn ty<'a, 'gcx, D: HasLocalDecls<'tcx>>(&self, local_decls: &D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> LvalueTy<'tcx> { match *self { Lvalue::Local(index) => - LvalueTy::Ty { ty: local_decls.as_ref()[index].ty }, + LvalueTy::Ty { ty: local_decls.local_decls()[index].ty }, Lvalue::Static(ref data) => LvalueTy::Ty { ty: data.ty }, Lvalue::Projection(ref proj) => @@ -134,7 +134,7 @@ impl<'tcx> Lvalue<'tcx> { } impl<'tcx> Rvalue<'tcx> { - pub fn ty<'a, 'gcx, D: AsLocalDeclsRef<'tcx>>(&self, local_decls: &D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> + pub fn ty<'a, 'gcx, D: HasLocalDecls<'tcx>>(&self, local_decls: &D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> { match *self { Rvalue::Use(ref operand) => operand.ty(local_decls, tcx), @@ -206,7 +206,7 @@ impl<'tcx> Rvalue<'tcx> { } impl<'tcx> Operand<'tcx> { - pub fn ty<'a, 'gcx, D: AsLocalDeclsRef<'tcx>>(&self, local_decls: &D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> { + pub fn ty<'a, 'gcx, D: HasLocalDecls<'tcx>>(&self, local_decls: &D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> { match self { &Operand::Consume(ref l) => l.ty(local_decls, tcx).to_ty(tcx), &Operand::Constant(ref c) => c.ty, From 0bbc3158300452dbb45931ab8d6740faa840d486 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 12 Jul 2017 13:19:58 -0700 Subject: [PATCH 4/4] please tidy by shortening lines --- src/librustc/mir/tcx.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/librustc/mir/tcx.rs b/src/librustc/mir/tcx.rs index d3b87c1201dcf..1af80771fb952 100644 --- a/src/librustc/mir/tcx.rs +++ b/src/librustc/mir/tcx.rs @@ -121,7 +121,9 @@ impl<'tcx> TypeFoldable<'tcx> for LvalueTy<'tcx> { } impl<'tcx> Lvalue<'tcx> { - pub fn ty<'a, 'gcx, D: HasLocalDecls<'tcx>>(&self, local_decls: &D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> LvalueTy<'tcx> { + pub fn ty<'a, 'gcx, D>(&self, local_decls: &D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> LvalueTy<'tcx> + where D: HasLocalDecls<'tcx> + { match *self { Lvalue::Local(index) => LvalueTy::Ty { ty: local_decls.local_decls()[index].ty }, @@ -134,7 +136,8 @@ impl<'tcx> Lvalue<'tcx> { } impl<'tcx> Rvalue<'tcx> { - pub fn ty<'a, 'gcx, D: HasLocalDecls<'tcx>>(&self, local_decls: &D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> + pub fn ty<'a, 'gcx, D>(&self, local_decls: &D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> + where D: HasLocalDecls<'tcx> { match *self { Rvalue::Use(ref operand) => operand.ty(local_decls, tcx), @@ -206,7 +209,9 @@ impl<'tcx> Rvalue<'tcx> { } impl<'tcx> Operand<'tcx> { - pub fn ty<'a, 'gcx, D: HasLocalDecls<'tcx>>(&self, local_decls: &D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> { + pub fn ty<'a, 'gcx, D>(&self, local_decls: &D, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> + where D: HasLocalDecls<'tcx> + { match self { &Operand::Consume(ref l) => l.ty(local_decls, tcx).to_ty(tcx), &Operand::Constant(ref c) => c.ty,