@@ -27,13 +27,12 @@ use rustc::mir::tcx::PlaceTy;
2727use rustc:: mir:: visit:: { PlaceContext , Visitor } ;
2828use rustc:: mir:: * ;
2929use rustc:: traits:: query:: NoSolution ;
30- use rustc:: traits:: { self , Normalized , TraitEngine } ;
30+ use rustc:: traits:: { self , ObligationCause , Normalized , TraitEngine } ;
3131use rustc:: ty:: error:: TypeError ;
3232use rustc:: ty:: fold:: TypeFoldable ;
3333use rustc:: ty:: { self , ToPolyTraitRef , Ty , TyCtxt , TypeVariants } ;
3434use std:: fmt;
3535use std:: rc:: Rc ;
36- use syntax:: ast;
3736use syntax_pos:: { Span , DUMMY_SP } ;
3837use transform:: { MirPass , MirSource } ;
3938use util:: liveness:: LivenessResults ;
@@ -48,7 +47,7 @@ macro_rules! span_mirbug {
4847 $context. last_span,
4948 & format!(
5049 "broken MIR in {:?} ({:?}): {}" ,
51- $context. body_id ,
50+ $context. mir_def_id ,
5251 $elem,
5352 format_args!( $( $message) * ) ,
5453 ) ,
@@ -110,11 +109,10 @@ pub(crate) fn type_check<'gcx, 'tcx>(
110109 flow_inits : & mut FlowAtLocation < MaybeInitializedPlaces < ' _ , ' gcx , ' tcx > > ,
111110 move_data : & MoveData < ' tcx > ,
112111) -> MirTypeckRegionConstraints < ' tcx > {
113- let body_id = infcx. tcx . hir . as_local_node_id ( mir_def_id) . unwrap ( ) ;
114112 let implicit_region_bound = infcx. tcx . mk_region ( ty:: ReVar ( universal_regions. fr_fn_body ) ) ;
115113 type_check_internal (
116114 infcx,
117- body_id ,
115+ mir_def_id ,
118116 param_env,
119117 mir,
120118 & universal_regions. region_bound_pairs ,
@@ -134,7 +132,7 @@ pub(crate) fn type_check<'gcx, 'tcx>(
134132
135133fn type_check_internal < ' gcx , ' tcx > (
136134 infcx : & InferCtxt < ' _ , ' gcx , ' tcx > ,
137- body_id : ast :: NodeId ,
135+ mir_def_id : DefId ,
138136 param_env : ty:: ParamEnv < ' gcx > ,
139137 mir : & Mir < ' tcx > ,
140138 region_bound_pairs : & [ ( ty:: Region < ' tcx > , GenericKind < ' tcx > ) ] ,
@@ -144,7 +142,7 @@ fn type_check_internal<'gcx, 'tcx>(
144142) -> MirTypeckRegionConstraints < ' tcx > {
145143 let mut checker = TypeChecker :: new (
146144 infcx,
147- body_id ,
145+ mir_def_id ,
148146 param_env,
149147 region_bound_pairs,
150148 implicit_region_bound,
@@ -187,7 +185,7 @@ struct TypeVerifier<'a, 'b: 'a, 'gcx: 'b + 'tcx, 'tcx: 'b> {
187185 cx : & ' a mut TypeChecker < ' b , ' gcx , ' tcx > ,
188186 mir : & ' a Mir < ' tcx > ,
189187 last_span : Span ,
190- body_id : ast :: NodeId ,
188+ mir_def_id : DefId ,
191189 errors_reported : bool ,
192190}
193191
@@ -235,7 +233,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
235233 fn new ( cx : & ' a mut TypeChecker < ' b , ' gcx , ' tcx > , mir : & ' a Mir < ' tcx > ) -> Self {
236234 TypeVerifier {
237235 mir,
238- body_id : cx. body_id ,
236+ mir_def_id : cx. mir_def_id ,
239237 cx,
240238 last_span : mir. span ,
241239 errors_reported : false ,
@@ -595,7 +593,7 @@ struct TypeChecker<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
595593 infcx : & ' a InferCtxt < ' a , ' gcx , ' tcx > ,
596594 param_env : ty:: ParamEnv < ' gcx > ,
597595 last_span : Span ,
598- body_id : ast :: NodeId ,
596+ mir_def_id : DefId ,
599597 region_bound_pairs : & ' a [ ( ty:: Region < ' tcx > , GenericKind < ' tcx > ) ] ,
600598 implicit_region_bound : Option < ty:: Region < ' tcx > > ,
601599 reported_errors : FxHashSet < ( Ty < ' tcx > , Span ) > ,
@@ -699,7 +697,7 @@ impl Locations {
699697impl < ' a , ' gcx , ' tcx > TypeChecker < ' a , ' gcx , ' tcx > {
700698 fn new (
701699 infcx : & ' a InferCtxt < ' a , ' gcx , ' tcx > ,
702- body_id : ast :: NodeId ,
700+ mir_def_id : DefId ,
703701 param_env : ty:: ParamEnv < ' gcx > ,
704702 region_bound_pairs : & ' a [ ( ty:: Region < ' tcx > , GenericKind < ' tcx > ) ] ,
705703 implicit_region_bound : Option < ty:: Region < ' tcx > > ,
@@ -709,7 +707,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
709707 TypeChecker {
710708 infcx,
711709 last_span : DUMMY_SP ,
712- body_id ,
710+ mir_def_id ,
713711 param_env,
714712 region_bound_pairs,
715713 implicit_region_bound,
@@ -720,10 +718,6 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
720718 }
721719 }
722720
723- fn misc ( & self , span : Span ) -> traits:: ObligationCause < ' tcx > {
724- traits:: ObligationCause :: misc ( span, self . body_id )
725- }
726-
727721 /// Given some operation `op` that manipulates types, proves
728722 /// predicates, or otherwise uses the inference context, executes
729723 /// `op` and then executes all the further obligations that `op`
@@ -794,7 +788,9 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
794788 }
795789
796790 let mut fulfill_cx = TraitEngine :: new ( self . infcx . tcx ) ;
791+ let dummy_body_id = ObligationCause :: dummy ( ) . body_id ;
797792 let InferOk { value, obligations } = self . infcx . commit_if_ok ( |_| op ( self ) ) ?;
793+ debug_assert ! ( obligations. iter( ) . all( |o| o. cause. body_id == dummy_body_id) ) ;
798794 fulfill_cx. register_predicate_obligations ( self . infcx , obligations) ;
799795 if let Err ( e) = fulfill_cx. select_all_or_error ( self . infcx ) {
800796 span_mirbug ! ( self , "" , "errors selecting obligation: {:?}" , e) ;
@@ -804,7 +800,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
804800 self . region_bound_pairs ,
805801 self . implicit_region_bound ,
806802 self . param_env ,
807- self . body_id ,
803+ dummy_body_id ,
808804 ) ;
809805
810806 let data = self . infcx . take_and_reset_region_constraints ( ) ;
@@ -832,7 +828,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
832828 || format ! ( "sub_types({:?} <: {:?})" , sub, sup) ,
833829 |this| {
834830 this. infcx
835- . at ( & this . misc ( this . last_span ) , this. param_env )
831+ . at ( & ObligationCause :: dummy ( ) , this. param_env )
836832 . sup ( sup, sub)
837833 } ,
838834 )
@@ -850,7 +846,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
850846 || format ! ( "eq_types({:?} = {:?})" , a, b) ,
851847 |this| {
852848 this. infcx
853- . at ( & this . misc ( this . last_span ) , this. param_env )
849+ . at ( & ObligationCause :: dummy ( ) , this. param_env )
854850 . eq ( b, a)
855851 } ,
856852 )
@@ -1575,9 +1571,10 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
15751571 if let Some ( closure_region_requirements) =
15761572 tcx. mir_borrowck ( * def_id) . closure_requirements
15771573 {
1574+ let dummy_body_id = ObligationCause :: dummy ( ) . body_id ;
15781575 closure_region_requirements. apply_requirements (
15791576 self . infcx ,
1580- self . body_id ,
1577+ dummy_body_id ,
15811578 location,
15821579 * def_id,
15831580 * substs,
@@ -1613,7 +1610,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
16131610 where
16141611 T : IntoIterator < Item = ty:: Predicate < ' tcx > > + Clone ,
16151612 {
1616- let cause = self . misc ( self . last_span ) ;
1613+ let cause = ObligationCause :: dummy ( ) ;
16171614 let obligations: Vec < _ > = predicates
16181615 . into_iter ( )
16191616 . map ( |p| traits:: Obligation :: new ( cause. clone ( ) , self . param_env , p) )
@@ -1694,7 +1691,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
16941691 |this| {
16951692 let Normalized { value, obligations } = this
16961693 . infcx
1697- . at ( & this . misc ( this . last_span ) , this. param_env )
1694+ . at ( & ObligationCause :: dummy ( ) , this. param_env )
16981695 . normalize ( value)
16991696 . unwrap_or_else ( |NoSolution | {
17001697 span_bug ! (
@@ -1715,7 +1712,6 @@ pub struct TypeckMir;
17151712impl MirPass for TypeckMir {
17161713 fn run_pass < ' a , ' tcx > ( & self , tcx : TyCtxt < ' a , ' tcx , ' tcx > , src : MirSource , mir : & mut Mir < ' tcx > ) {
17171714 let def_id = src. def_id ;
1718- let id = tcx. hir . as_local_node_id ( def_id) . unwrap ( ) ;
17191715 debug ! ( "run_pass: {:?}" , def_id) ;
17201716
17211717 // When NLL is enabled, the borrow checker runs the typeck
@@ -1731,7 +1727,16 @@ impl MirPass for TypeckMir {
17311727 }
17321728 let param_env = tcx. param_env ( def_id) ;
17331729 tcx. infer_ctxt ( ) . enter ( |infcx| {
1734- let _ = type_check_internal ( & infcx, id, param_env, mir, & [ ] , None , None , & mut |_| ( ) ) ;
1730+ let _ = type_check_internal (
1731+ & infcx,
1732+ def_id,
1733+ param_env,
1734+ mir,
1735+ & [ ] ,
1736+ None ,
1737+ None ,
1738+ & mut |_| ( ) ,
1739+ ) ;
17351740
17361741 // For verification purposes, we just ignore the resulting
17371742 // region constraint sets. Not our problem. =)
0 commit comments