@@ -346,36 +346,37 @@ fn extract_hole_spans_from_hir<'tcx>(
346
346
body_span : Span , // Usually `hir_body.value.span`, but not always
347
347
hir_body : & hir:: Body < ' tcx > ,
348
348
) -> Vec < Span > {
349
- struct HolesVisitor < ' hir , F > {
350
- tcx : TyCtxt < ' hir > ,
351
- visit_hole_span : F ,
349
+ struct HolesVisitor < ' tcx > {
350
+ tcx : TyCtxt < ' tcx > ,
351
+ body_span : Span ,
352
+ hole_spans : Vec < Span > ,
352
353
}
353
354
354
- impl < ' hir , F : FnMut ( Span ) > Visitor < ' hir > for HolesVisitor < ' hir , F > {
355
+ impl < ' tcx > Visitor < ' tcx > for HolesVisitor < ' tcx > {
355
356
/// We have special handling for nested items, but we still want to
356
357
/// traverse into nested bodies of things that are not considered items,
357
358
/// such as "anon consts" (e.g. array lengths).
358
359
type NestedFilter = nested_filter:: OnlyBodies ;
359
360
360
- fn maybe_tcx ( & mut self ) -> Self :: MaybeTyCtxt {
361
+ fn maybe_tcx ( & mut self ) -> TyCtxt < ' tcx > {
361
362
self . tcx
362
363
}
363
364
364
365
/// We override `visit_nested_item` instead of `visit_item` because we
365
366
/// only need the item's span, not the item itself.
366
367
fn visit_nested_item ( & mut self , id : hir:: ItemId ) -> Self :: Result {
367
368
let span = self . tcx . def_span ( id. owner_id . def_id ) ;
368
- ( self . visit_hole_span ) ( span) ;
369
+ self . visit_hole_span ( span) ;
369
370
// Having visited this item, we don't care about its children,
370
371
// so don't call `walk_item`.
371
372
}
372
373
373
374
// We override `visit_expr` instead of the more specific expression
374
375
// visitors, so that we have direct access to the expression span.
375
- fn visit_expr ( & mut self , expr : & ' hir hir:: Expr < ' hir > ) {
376
+ fn visit_expr ( & mut self , expr : & ' tcx hir:: Expr < ' tcx > ) {
376
377
match expr. kind {
377
378
hir:: ExprKind :: Closure ( _) | hir:: ExprKind :: ConstBlock ( _) => {
378
- ( self . visit_hole_span ) ( expr. span ) ;
379
+ self . visit_hole_span ( expr. span ) ;
379
380
// Having visited this expression, we don't care about its
380
381
// children, so don't call `walk_expr`.
381
382
}
@@ -385,18 +386,17 @@ fn extract_hole_spans_from_hir<'tcx>(
385
386
}
386
387
}
387
388
}
388
-
389
- let mut hole_spans = vec ! [ ] ;
390
- let mut visitor = HolesVisitor {
391
- tcx,
392
- visit_hole_span : |hole_span| {
389
+ impl HolesVisitor < ' _ > {
390
+ fn visit_hole_span ( & mut self , hole_span : Span ) {
393
391
// Discard any holes that aren't directly visible within the body span.
394
- if body_span. contains ( hole_span) && body_span. eq_ctxt ( hole_span) {
395
- hole_spans. push ( hole_span) ;
392
+ if self . body_span . contains ( hole_span) && self . body_span . eq_ctxt ( hole_span) {
393
+ self . hole_spans . push ( hole_span) ;
396
394
}
397
- } ,
398
- } ;
395
+ }
396
+ }
397
+
398
+ let mut visitor = HolesVisitor { tcx, body_span, hole_spans : vec ! [ ] } ;
399
399
400
400
visitor. visit_body ( hir_body) ;
401
- hole_spans
401
+ visitor . hole_spans
402
402
}
0 commit comments