@@ -192,6 +192,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
192
192
hir_map : & self . tcx . hir ,
193
193
bound_region : * br,
194
194
found_type : None ,
195
+ depth : 0 ,
195
196
} ;
196
197
nested_visitor. visit_ty ( arg) ;
197
198
nested_visitor. found_type
@@ -214,6 +215,7 @@ struct FindNestedTypeVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
214
215
// The type where the anonymous lifetime appears
215
216
// for e.g. Vec<`&u8`> and <`&u8`>
216
217
found_type : Option < & ' gcx hir:: Ty > ,
218
+ depth : u32 ,
217
219
}
218
220
219
221
impl < ' a , ' gcx , ' tcx > Visitor < ' gcx > for FindNestedTypeVisitor < ' a , ' gcx , ' tcx > {
@@ -263,11 +265,35 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> {
263
265
self . found_type = Some ( arg) ;
264
266
}
265
267
}
268
+
269
+ hir:: TyBareFn ( ref fndecl) => {
270
+ fndecl. lifetimes . iter ( ) . filter_map ( |lf| {
271
+ match self . infcx . tcx . named_region_map . defs . get ( & lf. lifetime . id ) {
272
+
273
+ Some ( & rl:: Region :: LateBoundAnon ( debuijn_index, anon_index) ) => {
274
+ if debuijn_index. depth == self . depth && anon_index == br_index {
275
+ self . found_type = Some ( arg) ;
276
+ return ; // we can stop visiting now
277
+ } else { }
278
+ }
279
+ Some ( & rl:: Region :: Static ) |
280
+ Some ( & rl:: Region :: EarlyBound ( _, _) ) |
281
+ Some ( & rl:: Region :: LateBound ( _, _) ) |
282
+ Some ( & rl:: Region :: Free ( _, _) ) |
283
+ None => {
284
+ debug ! ( "no arg found" ) ;
285
+ }
286
+ }
287
+
288
+ } ) . next ( ) ; }
289
+
266
290
_ => { }
267
291
}
268
292
// walk the embedded contents: e.g., if we are visiting `Vec<&Foo>`,
269
293
// go on to visit `&Foo`
294
+ self . depth += 1 ;
270
295
intravisit:: walk_ty ( self , arg) ;
296
+ self . depth += 1 ;
271
297
}
272
298
}
273
299
0 commit comments