diff options
Diffstat (limited to 'src/librustc_mir')
-rw-r--r-- | src/librustc_mir/borrow_check/nll/type_check/mod.rs | 58 | ||||
-rw-r--r-- | src/librustc_mir/transform/const_prop.rs | 2 | ||||
-rw-r--r-- | src/librustc_mir/transform/inline.rs | 11 | ||||
-rw-r--r-- | src/librustc_mir/transform/promote_consts.rs | 15 |
4 files changed, 34 insertions, 52 deletions
diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index c2efd3625c3..2a32b475c79 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -455,6 +455,27 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> { }, Place::Base(PlaceBase::Static(box Static { def_id, ty: sty, promoted })) => { let sty = self.sanitize_type(place, sty); + let check_err = + |verifier: &mut TypeVerifier<'a, 'b, 'gcx, 'tcx> , + place: &Place<'tcx>, + ty, + sty| { + if let Err(terr) = verifier.cx.eq_types( + sty, + ty, + location.to_locations(), + ConstraintCategory::Boring, + ) { + span_mirbug!( + verifier, + place, + "bad promoted type ({:?}: {:?}): {:?}", + ty, + sty, + terr + ); + }; + }; match promoted { Some(pr) => { if !self.errors_reported { @@ -462,45 +483,14 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> { self.sanitize_promoted(promoted_mir, location); let promoted_ty = promoted_mir.return_ty(); - - if let Err(terr) = self.cx.eq_types( - sty, - promoted_ty, - location.to_locations(), - ConstraintCategory::Boring, - ) { - span_mirbug!( - self, - place, - "bad promoted type ({:?}: {:?}): {:?}", - promoted_ty, - sty, - terr - ); - }; + check_err(self, place, promoted_ty, sty); } } None => { let ty = self.tcx().type_of(def_id); let ty = self.cx.normalize(ty, location); - if let Err(terr) = - self.cx - .eq_types( - ty, - sty, - location.to_locations(), - ConstraintCategory::Boring - ) - { - span_mirbug!( - self, - place, - "bad static type ({:?}: {:?}): {:?}", - ty, - sty, - terr - ); - }; + + check_err(self, place, ty, sty); } } PlaceTy::Ty { ty: sty } diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index c5c3a1b8eca..81cdb001005 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -283,7 +283,7 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> { // an `Index` projection would throw us off-track. _ => None, }, - Place::Base(PlaceBase::Static(box Static {promoted: Some(promoted), ty: _, ..})) => { + Place::Base(PlaceBase::Static(box Static {promoted: Some(promoted), ..})) => { let generics = self.tcx.generics_of(self.source.def_id()); if generics.requires_monomorphization(self.tcx) { // FIXME: can't handle code with generics diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 86b7da17879..ec2cf8a4c03 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -692,14 +692,9 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> { // Return pointer; update the place itself *place = self.destination.clone(); }, - Place::Base(PlaceBase::Static(ref mut static_)) => { - match static_.promoted { - Some(promoted) => { - if let Some(p) = self.promoted_map.get(promoted).cloned() { - static_.promoted = Some(p); - } - } - None => self.super_place(place, _ctxt, _location) + Place::Base(PlaceBase::Static(box Static { promoted: Some(promoted), .. })) => { + if let Some(p) = self.promoted_map.get(*promoted).cloned() { + *promoted = p; } }, _ => self.super_place(place, _ctxt, _location) diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index d777a7b362b..2344f070ea6 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -153,7 +153,7 @@ struct Promoter<'a, 'tcx: 'a> { /// If true, all nested temps are also kept in the /// source MIR, not moved to the promoted MIR. keep_original: bool, - def_id: DefId + def_id: DefId, } impl<'a, 'tcx> Promoter<'a, 'tcx> { @@ -291,17 +291,14 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { fn promote_candidate(mut self, candidate: Candidate) { use rustc::mir::Static; let mut operand = { - let def_id = self.def_id.clone(); + let def_id = self.def_id; let promoted = &mut self.promoted; let promoted_id = Promoted::new(self.source.promoted.len()); let mut promoted_place = |ty, span| { promoted.span = span; - promoted.local_decls[RETURN_PLACE] = - LocalDecl::new_return_place(ty, span); - Place::Base(PlaceBase::Static( - Box::new(Static { def_id: def_id, ty, promoted: Some(promoted_id) }) - ) - ) + promoted.local_decls[RETURN_PLACE] = LocalDecl::new_return_place(ty, span); + Place::Base( + PlaceBase::Static(Box::new(Static { def_id, ty, promoted: Some(promoted_id) }))) }; let (blocks, local_decls) = self.source.basic_blocks_and_local_decls_mut(); match candidate { @@ -421,7 +418,7 @@ pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>, source: mir, temps: &mut temps, keep_original: false, - def_id + def_id, }; promoter.promote_candidate(candidate); } |