11use core:: ops:: ControlFlow ;
22
33use rustc_hir as hir;
4- use rustc_hir:: def_id:: LocalDefId ;
4+ use rustc_hir:: def_id:: { DefId , LocalDefId } ;
55use rustc_hir:: intravisit:: { self , Visitor } ;
66use rustc_middle:: hir:: map:: Map ;
77use rustc_middle:: hir:: nested_filter;
@@ -28,16 +28,15 @@ pub fn find_anon_type<'tcx>(
2828 tcx : TyCtxt < ' tcx > ,
2929 generic_param_scope : LocalDefId ,
3030 region : Region < ' tcx > ,
31- br : & ty:: BoundRegionKind ,
3231) -> Option < ( & ' tcx hir:: Ty < ' tcx > , & ' tcx hir:: FnSig < ' tcx > ) > {
3332 let anon_reg = tcx. is_suitable_region ( generic_param_scope, region) ?;
34- let fn_sig = tcx. hir_node_by_def_id ( anon_reg. def_id ) . fn_sig ( ) ?;
33+ let fn_sig = tcx. hir_node_by_def_id ( anon_reg. scope ) . fn_sig ( ) ?;
3534
3635 fn_sig
3736 . decl
3837 . inputs
3938 . iter ( )
40- . find_map ( |arg| find_component_for_bound_region ( tcx, arg, br ) )
39+ . find_map ( |arg| find_component_for_bound_region ( tcx, arg, anon_reg . region_def_id ) )
4140 . map ( |ty| ( ty, fn_sig) )
4241}
4342
@@ -46,9 +45,9 @@ pub fn find_anon_type<'tcx>(
4645fn find_component_for_bound_region < ' tcx > (
4746 tcx : TyCtxt < ' tcx > ,
4847 arg : & ' tcx hir:: Ty < ' tcx > ,
49- br : & ty :: BoundRegionKind ,
48+ region_def_id : DefId ,
5049) -> Option < & ' tcx hir:: Ty < ' tcx > > {
51- FindNestedTypeVisitor { tcx, bound_region : * br , current_index : ty:: INNERMOST }
50+ FindNestedTypeVisitor { tcx, region_def_id , current_index : ty:: INNERMOST }
5251 . visit_ty ( arg)
5352 . break_value ( )
5453}
@@ -62,9 +61,8 @@ fn find_component_for_bound_region<'tcx>(
6261// specific part of the type in the error message.
6362struct FindNestedTypeVisitor < ' tcx > {
6463 tcx : TyCtxt < ' tcx > ,
65- // The bound_region corresponding to the Refree(freeregion)
66- // associated with the anonymous region we are looking for.
67- bound_region : ty:: BoundRegionKind ,
64+ // The `DefId` of the region we're looking for.
65+ region_def_id : DefId ,
6866 current_index : ty:: DebruijnIndex ,
6967}
7068
@@ -96,48 +94,39 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
9694 hir:: TyKind :: Ref ( lifetime, _) => {
9795 // the lifetime of the Ref
9896 let hir_id = lifetime. hir_id ;
99- match ( self . tcx . named_bound_var ( hir_id) , self . bound_region ) {
97+ match self . tcx . named_bound_var ( hir_id) {
10098 // Find the index of the named region that was part of the
10199 // error. We will then search the function parameters for a bound
102100 // region at the right depth with the same index
103- (
104- Some ( rbv:: ResolvedArg :: EarlyBound ( id) ) ,
105- ty:: BoundRegionKind :: Named ( def_id, _) ,
106- ) => {
107- debug ! ( "EarlyBound id={:?} def_id={:?}" , id, def_id) ;
108- if id. to_def_id ( ) == def_id {
101+ Some ( rbv:: ResolvedArg :: EarlyBound ( id) ) => {
102+ debug ! ( "EarlyBound id={:?}" , id) ;
103+ if id. to_def_id ( ) == self . region_def_id {
109104 return ControlFlow :: Break ( arg) ;
110105 }
111106 }
112107
113108 // Find the index of the named region that was part of the
114109 // error. We will then search the function parameters for a bound
115110 // region at the right depth with the same index
116- (
117- Some ( rbv:: ResolvedArg :: LateBound ( debruijn_index, _, id) ) ,
118- ty:: BoundRegionKind :: Named ( def_id, _) ,
119- ) => {
111+ Some ( rbv:: ResolvedArg :: LateBound ( debruijn_index, _, id) ) => {
120112 debug ! (
121113 "FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}" ,
122114 debruijn_index
123115 ) ;
124- debug ! ( "LateBound id={:?} def_id={:?}" , id, def_id) ;
125- if debruijn_index == self . current_index && id. to_def_id ( ) == def_id {
116+ debug ! ( "LateBound id={:?}" , id) ;
117+ if debruijn_index == self . current_index
118+ && id. to_def_id ( ) == self . region_def_id
119+ {
126120 return ControlFlow :: Break ( arg) ;
127121 }
128122 }
129123
130- (
131- Some (
132- rbv:: ResolvedArg :: StaticLifetime
133- | rbv:: ResolvedArg :: Free ( _, _)
134- | rbv:: ResolvedArg :: EarlyBound ( _)
135- | rbv:: ResolvedArg :: LateBound ( _, _, _)
136- | rbv:: ResolvedArg :: Error ( _) ,
137- )
138- | None ,
139- _,
140- ) => {
124+ Some (
125+ rbv:: ResolvedArg :: StaticLifetime
126+ | rbv:: ResolvedArg :: Free ( _, _)
127+ | rbv:: ResolvedArg :: Error ( _) ,
128+ )
129+ | None => {
141130 debug ! ( "no arg found" ) ;
142131 }
143132 }
@@ -151,7 +140,7 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
151140 return if intravisit:: walk_ty (
152141 & mut TyPathVisitor {
153142 tcx : self . tcx ,
154- bound_region : self . bound_region ,
143+ region_def_id : self . region_def_id ,
155144 current_index : self . current_index ,
156145 } ,
157146 arg,
@@ -179,7 +168,7 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
179168// specific part of the type in the error message.
180169struct TyPathVisitor < ' tcx > {
181170 tcx : TyCtxt < ' tcx > ,
182- bound_region : ty :: BoundRegionKind ,
171+ region_def_id : DefId ,
183172 current_index : ty:: DebruijnIndex ,
184173}
185174
@@ -192,38 +181,29 @@ impl<'tcx> Visitor<'tcx> for TyPathVisitor<'tcx> {
192181 }
193182
194183 fn visit_lifetime ( & mut self , lifetime : & hir:: Lifetime ) -> Self :: Result {
195- match ( self . tcx . named_bound_var ( lifetime. hir_id ) , self . bound_region ) {
184+ match self . tcx . named_bound_var ( lifetime. hir_id ) {
196185 // the lifetime of the TyPath!
197- ( Some ( rbv:: ResolvedArg :: EarlyBound ( id) ) , ty :: BoundRegionKind :: Named ( def_id , _ ) ) => {
198- debug ! ( "EarlyBound id={:?} def_id={:?} " , id, def_id ) ;
199- if id. to_def_id ( ) == def_id {
186+ Some ( rbv:: ResolvedArg :: EarlyBound ( id) ) => {
187+ debug ! ( "EarlyBound id={:?}" , id) ;
188+ if id. to_def_id ( ) == self . region_def_id {
200189 return ControlFlow :: Break ( ( ) ) ;
201190 }
202191 }
203192
204- (
205- Some ( rbv:: ResolvedArg :: LateBound ( debruijn_index, _, id) ) ,
206- ty:: BoundRegionKind :: Named ( def_id, _) ,
207- ) => {
193+ Some ( rbv:: ResolvedArg :: LateBound ( debruijn_index, _, id) ) => {
208194 debug ! ( "FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}" , debruijn_index, ) ;
209195 debug ! ( "id={:?}" , id) ;
210- debug ! ( "def_id={:?}" , def_id) ;
211- if debruijn_index == self . current_index && id. to_def_id ( ) == def_id {
196+ if debruijn_index == self . current_index && id. to_def_id ( ) == self . region_def_id {
212197 return ControlFlow :: Break ( ( ) ) ;
213198 }
214199 }
215200
216- (
217- Some (
218- rbv:: ResolvedArg :: StaticLifetime
219- | rbv:: ResolvedArg :: EarlyBound ( _)
220- | rbv:: ResolvedArg :: LateBound ( _, _, _)
221- | rbv:: ResolvedArg :: Free ( _, _)
222- | rbv:: ResolvedArg :: Error ( _) ,
223- )
224- | None ,
225- _,
226- ) => {
201+ Some (
202+ rbv:: ResolvedArg :: StaticLifetime
203+ | rbv:: ResolvedArg :: Free ( _, _)
204+ | rbv:: ResolvedArg :: Error ( _) ,
205+ )
206+ | None => {
227207 debug ! ( "no arg found" ) ;
228208 }
229209 }
0 commit comments