@@ -287,6 +287,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> {
287
287
found_it : false ,
288
288
bound_region : self . bound_region ,
289
289
hir_map : self . hir_map ,
290
+ depth : self . depth ,
290
291
} ;
291
292
intravisit:: walk_ty ( subvisitor, arg) ; // call walk_ty; as visit_ty is empty,
292
293
// this will visit only outermost type
@@ -313,6 +314,7 @@ struct TyPathVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
313
314
hir_map : & ' a hir:: map:: Map < ' gcx > ,
314
315
found_it : bool ,
315
316
bound_region : ty:: BoundRegion ,
317
+ depth : u32 ,
316
318
}
317
319
318
320
impl < ' a , ' gcx , ' tcx > Visitor < ' gcx > for TyPathVisitor < ' a , ' gcx , ' tcx > {
@@ -321,24 +323,47 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for TyPathVisitor<'a, 'gcx, 'tcx> {
321
323
}
322
324
323
325
fn visit_lifetime ( & mut self , lifetime : & hir:: Lifetime ) {
324
- let br_index = match self . bound_region {
325
- ty:: BrAnon ( index) => index,
326
- _ => return ,
327
- } ;
328
326
329
327
let hir_id = self . infcx . tcx . hir . node_to_hir_id ( lifetime. id ) ;
330
- match self . infcx . tcx . named_region ( hir_id) {
328
+ match ( self . infcx . tcx . named_region ( hir_id) , self . bound_region ) {
331
329
// the lifetime of the TyPath!
332
- Some ( rl:: Region :: LateBoundAnon ( debruijn_index, anon_index) ) => {
333
- if debruijn_index. depth == 1 && anon_index == br_index {
330
+ ( Some ( rl:: Region :: LateBoundAnon ( debruijn_index, anon_index) ) , ty:: BrAnon ( br_index) ) => {
331
+ if debruijn_index. depth == self . depth && anon_index == br_index {
332
+ self . found_it = true ;
333
+ return ;
334
+ }
335
+ }
336
+
337
+ ( Some ( rl:: Region :: EarlyBound ( _, id) ) , ty:: BrNamed ( def_id, _) ) => {
338
+ debug ! ( "EarlyBound self.infcx.tcx.hir.local_def_id(id)={:?} \
339
+ def_id={:?}",
340
+ self . infcx. tcx. hir. local_def_id( id) ,
341
+ def_id) ;
342
+ if self . infcx . tcx . hir . local_def_id ( id) == def_id {
343
+ self . found_it = true ;
344
+ return ; // we can stop visiting now
345
+ }
346
+ }
347
+
348
+ ( Some ( rl:: Region :: LateBound ( debruijn_index, id) ) , ty:: BrNamed ( def_id, _) ) => {
349
+ debug ! ( "FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}" ,
350
+ debruijn_index. depth) ;
351
+ debug ! ( "self.infcx.tcx.hir.local_def_id(id)={:?}" ,
352
+ self . infcx. tcx. hir. local_def_id( id) ) ;
353
+ debug ! ( "def_id={:?}" , def_id) ;
354
+ if debruijn_index. depth == self . depth &&
355
+ self . infcx . tcx . hir . local_def_id ( id) == def_id {
334
356
self . found_it = true ;
357
+ return ; // we can stop visiting now
335
358
}
336
359
}
337
- Some ( rl:: Region :: Static ) |
338
- Some ( rl:: Region :: EarlyBound ( _, _) ) |
339
- Some ( rl:: Region :: LateBound ( _, _) ) |
340
- Some ( rl:: Region :: Free ( _, _) ) |
341
- None => {
360
+
361
+ ( Some ( rl:: Region :: Static ) , _) |
362
+ ( Some ( rl:: Region :: EarlyBound ( _, _) ) , _) |
363
+ ( Some ( rl:: Region :: LateBound ( _, _) ) , _) |
364
+ ( Some ( rl:: Region :: LateBoundAnon ( _, _) ) , _) |
365
+ ( Some ( rl:: Region :: Free ( _, _) ) , _) |
366
+ ( None , _) => {
342
367
debug ! ( "no arg found" ) ;
343
368
}
344
369
}
0 commit comments