@@ -27,13 +27,12 @@ use rustc::mir::tcx::PlaceTy;
27
27
use rustc:: mir:: visit:: { PlaceContext , Visitor } ;
28
28
use rustc:: mir:: * ;
29
29
use rustc:: traits:: query:: NoSolution ;
30
- use rustc:: traits:: { self , Normalized , TraitEngine } ;
30
+ use rustc:: traits:: { self , ObligationCause , Normalized , TraitEngine } ;
31
31
use rustc:: ty:: error:: TypeError ;
32
32
use rustc:: ty:: fold:: TypeFoldable ;
33
33
use rustc:: ty:: { self , ToPolyTraitRef , Ty , TyCtxt , TypeVariants } ;
34
34
use std:: fmt;
35
35
use std:: rc:: Rc ;
36
- use syntax:: ast;
37
36
use syntax_pos:: { Span , DUMMY_SP } ;
38
37
use transform:: { MirPass , MirSource } ;
39
38
use util:: liveness:: LivenessResults ;
@@ -48,7 +47,7 @@ macro_rules! span_mirbug {
48
47
$context. last_span,
49
48
& format!(
50
49
"broken MIR in {:?} ({:?}): {}" ,
51
- $context. body_id ,
50
+ $context. mir_def_id ,
52
51
$elem,
53
52
format_args!( $( $message) * ) ,
54
53
) ,
@@ -110,11 +109,10 @@ pub(crate) fn type_check<'gcx, 'tcx>(
110
109
flow_inits : & mut FlowAtLocation < MaybeInitializedPlaces < ' _ , ' gcx , ' tcx > > ,
111
110
move_data : & MoveData < ' tcx > ,
112
111
) -> MirTypeckRegionConstraints < ' tcx > {
113
- let body_id = infcx. tcx . hir . as_local_node_id ( mir_def_id) . unwrap ( ) ;
114
112
let implicit_region_bound = infcx. tcx . mk_region ( ty:: ReVar ( universal_regions. fr_fn_body ) ) ;
115
113
type_check_internal (
116
114
infcx,
117
- body_id ,
115
+ mir_def_id ,
118
116
param_env,
119
117
mir,
120
118
& universal_regions. region_bound_pairs ,
@@ -134,7 +132,7 @@ pub(crate) fn type_check<'gcx, 'tcx>(
134
132
135
133
fn type_check_internal < ' gcx , ' tcx > (
136
134
infcx : & InferCtxt < ' _ , ' gcx , ' tcx > ,
137
- body_id : ast :: NodeId ,
135
+ mir_def_id : DefId ,
138
136
param_env : ty:: ParamEnv < ' gcx > ,
139
137
mir : & Mir < ' tcx > ,
140
138
region_bound_pairs : & [ ( ty:: Region < ' tcx > , GenericKind < ' tcx > ) ] ,
@@ -144,7 +142,7 @@ fn type_check_internal<'gcx, 'tcx>(
144
142
) -> MirTypeckRegionConstraints < ' tcx > {
145
143
let mut checker = TypeChecker :: new (
146
144
infcx,
147
- body_id ,
145
+ mir_def_id ,
148
146
param_env,
149
147
region_bound_pairs,
150
148
implicit_region_bound,
@@ -187,7 +185,7 @@ struct TypeVerifier<'a, 'b: 'a, 'gcx: 'b + 'tcx, 'tcx: 'b> {
187
185
cx : & ' a mut TypeChecker < ' b , ' gcx , ' tcx > ,
188
186
mir : & ' a Mir < ' tcx > ,
189
187
last_span : Span ,
190
- body_id : ast :: NodeId ,
188
+ mir_def_id : DefId ,
191
189
errors_reported : bool ,
192
190
}
193
191
@@ -235,7 +233,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
235
233
fn new ( cx : & ' a mut TypeChecker < ' b , ' gcx , ' tcx > , mir : & ' a Mir < ' tcx > ) -> Self {
236
234
TypeVerifier {
237
235
mir,
238
- body_id : cx. body_id ,
236
+ mir_def_id : cx. mir_def_id ,
239
237
cx,
240
238
last_span : mir. span ,
241
239
errors_reported : false ,
@@ -595,7 +593,7 @@ struct TypeChecker<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
595
593
infcx : & ' a InferCtxt < ' a , ' gcx , ' tcx > ,
596
594
param_env : ty:: ParamEnv < ' gcx > ,
597
595
last_span : Span ,
598
- body_id : ast :: NodeId ,
596
+ mir_def_id : DefId ,
599
597
region_bound_pairs : & ' a [ ( ty:: Region < ' tcx > , GenericKind < ' tcx > ) ] ,
600
598
implicit_region_bound : Option < ty:: Region < ' tcx > > ,
601
599
reported_errors : FxHashSet < ( Ty < ' tcx > , Span ) > ,
@@ -699,7 +697,7 @@ impl Locations {
699
697
impl < ' a , ' gcx , ' tcx > TypeChecker < ' a , ' gcx , ' tcx > {
700
698
fn new (
701
699
infcx : & ' a InferCtxt < ' a , ' gcx , ' tcx > ,
702
- body_id : ast :: NodeId ,
700
+ mir_def_id : DefId ,
703
701
param_env : ty:: ParamEnv < ' gcx > ,
704
702
region_bound_pairs : & ' a [ ( ty:: Region < ' tcx > , GenericKind < ' tcx > ) ] ,
705
703
implicit_region_bound : Option < ty:: Region < ' tcx > > ,
@@ -709,7 +707,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
709
707
TypeChecker {
710
708
infcx,
711
709
last_span : DUMMY_SP ,
712
- body_id ,
710
+ mir_def_id ,
713
711
param_env,
714
712
region_bound_pairs,
715
713
implicit_region_bound,
@@ -720,10 +718,6 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
720
718
}
721
719
}
722
720
723
- fn misc ( & self , span : Span ) -> traits:: ObligationCause < ' tcx > {
724
- traits:: ObligationCause :: misc ( span, self . body_id )
725
- }
726
-
727
721
/// Given some operation `op` that manipulates types, proves
728
722
/// predicates, or otherwise uses the inference context, executes
729
723
/// `op` and then executes all the further obligations that `op`
@@ -794,7 +788,9 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
794
788
}
795
789
796
790
let mut fulfill_cx = TraitEngine :: new ( self . infcx . tcx ) ;
791
+ let dummy_body_id = ObligationCause :: dummy ( ) . body_id ;
797
792
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) ) ;
798
794
fulfill_cx. register_predicate_obligations ( self . infcx , obligations) ;
799
795
if let Err ( e) = fulfill_cx. select_all_or_error ( self . infcx ) {
800
796
span_mirbug ! ( self , "" , "errors selecting obligation: {:?}" , e) ;
@@ -804,7 +800,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
804
800
self . region_bound_pairs ,
805
801
self . implicit_region_bound ,
806
802
self . param_env ,
807
- self . body_id ,
803
+ dummy_body_id ,
808
804
) ;
809
805
810
806
let data = self . infcx . take_and_reset_region_constraints ( ) ;
@@ -832,7 +828,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
832
828
|| format ! ( "sub_types({:?} <: {:?})" , sub, sup) ,
833
829
|this| {
834
830
this. infcx
835
- . at ( & this . misc ( this . last_span ) , this. param_env )
831
+ . at ( & ObligationCause :: dummy ( ) , this. param_env )
836
832
. sup ( sup, sub)
837
833
} ,
838
834
)
@@ -850,7 +846,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
850
846
|| format ! ( "eq_types({:?} = {:?})" , a, b) ,
851
847
|this| {
852
848
this. infcx
853
- . at ( & this . misc ( this . last_span ) , this. param_env )
849
+ . at ( & ObligationCause :: dummy ( ) , this. param_env )
854
850
. eq ( b, a)
855
851
} ,
856
852
)
@@ -1575,9 +1571,10 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1575
1571
if let Some ( closure_region_requirements) =
1576
1572
tcx. mir_borrowck ( * def_id) . closure_requirements
1577
1573
{
1574
+ let dummy_body_id = ObligationCause :: dummy ( ) . body_id ;
1578
1575
closure_region_requirements. apply_requirements (
1579
1576
self . infcx ,
1580
- self . body_id ,
1577
+ dummy_body_id ,
1581
1578
location,
1582
1579
* def_id,
1583
1580
* substs,
@@ -1613,7 +1610,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1613
1610
where
1614
1611
T : IntoIterator < Item = ty:: Predicate < ' tcx > > + Clone ,
1615
1612
{
1616
- let cause = self . misc ( self . last_span ) ;
1613
+ let cause = ObligationCause :: dummy ( ) ;
1617
1614
let obligations: Vec < _ > = predicates
1618
1615
. into_iter ( )
1619
1616
. map ( |p| traits:: Obligation :: new ( cause. clone ( ) , self . param_env , p) )
@@ -1694,7 +1691,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1694
1691
|this| {
1695
1692
let Normalized { value, obligations } = this
1696
1693
. infcx
1697
- . at ( & this . misc ( this . last_span ) , this. param_env )
1694
+ . at ( & ObligationCause :: dummy ( ) , this. param_env )
1698
1695
. normalize ( value)
1699
1696
. unwrap_or_else ( |NoSolution | {
1700
1697
span_bug ! (
@@ -1715,7 +1712,6 @@ pub struct TypeckMir;
1715
1712
impl MirPass for TypeckMir {
1716
1713
fn run_pass < ' a , ' tcx > ( & self , tcx : TyCtxt < ' a , ' tcx , ' tcx > , src : MirSource , mir : & mut Mir < ' tcx > ) {
1717
1714
let def_id = src. def_id ;
1718
- let id = tcx. hir . as_local_node_id ( def_id) . unwrap ( ) ;
1719
1715
debug ! ( "run_pass: {:?}" , def_id) ;
1720
1716
1721
1717
// When NLL is enabled, the borrow checker runs the typeck
@@ -1731,7 +1727,16 @@ impl MirPass for TypeckMir {
1731
1727
}
1732
1728
let param_env = tcx. param_env ( def_id) ;
1733
1729
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
+ ) ;
1735
1740
1736
1741
// For verification purposes, we just ignore the resulting
1737
1742
// region constraint sets. Not our problem. =)
0 commit comments