@@ -21,17 +21,18 @@ use borrow_check::nll::renumber;
2121use borrow_check:: nll:: universal_regions:: UniversalRegions ;
2222use rustc:: hir:: def_id:: DefId ;
2323use rustc:: infer:: InferOk ;
24- use rustc:: ty:: Ty ;
25- use rustc:: ty:: subst:: Subst ;
26- use rustc:: mir:: * ;
2724use rustc:: mir:: visit:: TyContext ;
25+ use rustc:: mir:: * ;
2826use rustc:: traits:: PredicateObligations ;
27+ use rustc:: ty:: subst:: Subst ;
28+ use rustc:: ty:: Ty ;
2929
3030use rustc_data_structures:: indexed_vec:: Idx ;
3131
3232use super :: { Locations , TypeChecker } ;
3333
3434impl < ' a , ' gcx , ' tcx > TypeChecker < ' a , ' gcx , ' tcx > {
35+ #[ inline( never) ]
3536 pub ( super ) fn equate_inputs_and_outputs (
3637 & mut self ,
3738 mir : & Mir < ' tcx > ,
@@ -56,8 +57,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
5657 }
5758
5859 assert ! (
59- mir. yield_ty. is_some( ) && universal_regions. yield_ty. is_some( ) ||
60- mir. yield_ty. is_none( ) && universal_regions. yield_ty. is_none( )
60+ mir. yield_ty. is_some( ) && universal_regions. yield_ty. is_some( )
61+ || mir. yield_ty. is_none( ) && universal_regions. yield_ty. is_none( )
6162 ) ;
6263 if let Some ( mir_yield_ty) = mir. yield_ty {
6364 let ur_yield_ty = universal_regions. yield_ty . unwrap ( ) ;
@@ -76,57 +77,66 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
7677 output_ty
7778 ) ;
7879 let mir_output_ty = mir. local_decls [ RETURN_PLACE ] . ty ;
79- let anon_type_map = self . fully_perform_op ( Locations :: All , |cx| {
80- let mut obligations = ObligationAccumulator :: default ( ) ;
81-
82- let ( output_ty, anon_type_map) = obligations. add ( infcx. instantiate_anon_types (
83- mir_def_id,
84- cx. body_id ,
85- cx. param_env ,
86- & output_ty,
87- ) ) ;
88- debug ! (
89- "equate_inputs_and_outputs: instantiated output_ty={:?}" ,
90- output_ty
91- ) ;
92- debug ! (
93- "equate_inputs_and_outputs: anon_type_map={:#?}" ,
94- anon_type_map
95- ) ;
96-
97- debug ! (
98- "equate_inputs_and_outputs: mir_output_ty={:?}" ,
99- mir_output_ty
100- ) ;
101- obligations. add ( infcx
102- . at ( & cx. misc ( cx. last_span ) , cx. param_env )
103- . eq ( output_ty, mir_output_ty) ?) ;
104-
105- for ( & anon_def_id, anon_decl) in & anon_type_map {
106- let anon_defn_ty = tcx. type_of ( anon_def_id) ;
107- let anon_defn_ty = anon_defn_ty. subst ( tcx, anon_decl. substs ) ;
108- let anon_defn_ty = renumber:: renumber_regions (
109- cx. infcx ,
110- TyContext :: Location ( Location :: START ) ,
111- & anon_defn_ty,
112- ) ;
113- debug ! (
114- "equate_inputs_and_outputs: concrete_ty={:?}" ,
115- anon_decl. concrete_ty
116- ) ;
117- debug ! ( "equate_inputs_and_outputs: anon_defn_ty={:?}" , anon_defn_ty) ;
118- obligations. add ( infcx
119- . at ( & cx. misc ( cx. last_span ) , cx. param_env )
120- . eq ( anon_decl. concrete_ty , anon_defn_ty) ?) ;
121- }
122-
123- debug ! ( "equate_inputs_and_outputs: equated" ) ;
124-
125- Ok ( InferOk {
126- value : Some ( anon_type_map) ,
127- obligations : obligations. into_vec ( ) ,
128- } )
129- } ) . unwrap_or_else ( |terr| {
80+ let anon_type_map =
81+ self . fully_perform_op (
82+ Locations :: All ,
83+ || format ! ( "input_output" ) ,
84+ |cx| {
85+ let mut obligations = ObligationAccumulator :: default ( ) ;
86+
87+ let ( output_ty, anon_type_map) = obligations. add ( infcx. instantiate_anon_types (
88+ mir_def_id,
89+ cx. body_id ,
90+ cx. param_env ,
91+ & output_ty,
92+ ) ) ;
93+ debug ! (
94+ "equate_inputs_and_outputs: instantiated output_ty={:?}" ,
95+ output_ty
96+ ) ;
97+ debug ! (
98+ "equate_inputs_and_outputs: anon_type_map={:#?}" ,
99+ anon_type_map
100+ ) ;
101+
102+ debug ! (
103+ "equate_inputs_and_outputs: mir_output_ty={:?}" ,
104+ mir_output_ty
105+ ) ;
106+ obligations. add (
107+ infcx
108+ . at ( & cx. misc ( cx. last_span ) , cx. param_env )
109+ . eq ( output_ty, mir_output_ty) ?,
110+ ) ;
111+
112+ for ( & anon_def_id, anon_decl) in & anon_type_map {
113+ let anon_defn_ty = tcx. type_of ( anon_def_id) ;
114+ let anon_defn_ty = anon_defn_ty. subst ( tcx, anon_decl. substs ) ;
115+ let anon_defn_ty = renumber:: renumber_regions (
116+ cx. infcx ,
117+ TyContext :: Location ( Location :: START ) ,
118+ & anon_defn_ty,
119+ ) ;
120+ debug ! (
121+ "equate_inputs_and_outputs: concrete_ty={:?}" ,
122+ anon_decl. concrete_ty
123+ ) ;
124+ debug ! ( "equate_inputs_and_outputs: anon_defn_ty={:?}" , anon_defn_ty) ;
125+ obligations. add (
126+ infcx
127+ . at ( & cx. misc ( cx. last_span ) , cx. param_env )
128+ . eq ( anon_decl. concrete_ty , anon_defn_ty) ?,
129+ ) ;
130+ }
131+
132+ debug ! ( "equate_inputs_and_outputs: equated" ) ;
133+
134+ Ok ( InferOk {
135+ value : Some ( anon_type_map) ,
136+ obligations : obligations. into_vec ( ) ,
137+ } )
138+ } ,
139+ ) . unwrap_or_else ( |terr| {
130140 span_mirbug ! (
131141 self ,
132142 Location :: START ,
@@ -143,13 +153,17 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
143153 // prove that `T: Iterator` where `T` is the type we
144154 // instantiated it with).
145155 if let Some ( anon_type_map) = anon_type_map {
146- self . fully_perform_op ( Locations :: All , |_cx| {
147- infcx. constrain_anon_types ( & anon_type_map, universal_regions) ;
148- Ok ( InferOk {
149- value : ( ) ,
150- obligations : vec ! [ ] ,
151- } )
152- } ) . unwrap ( ) ;
156+ self . fully_perform_op (
157+ Locations :: All ,
158+ || format ! ( "anon_type_map" ) ,
159+ |_cx| {
160+ infcx. constrain_anon_types ( & anon_type_map, universal_regions) ;
161+ Ok ( InferOk {
162+ value : ( ) ,
163+ obligations : vec ! [ ] ,
164+ } )
165+ } ,
166+ ) . unwrap ( ) ;
153167 }
154168 }
155169
0 commit comments