@@ -345,27 +345,28 @@ fn extract_hole_spans_from_hir<'tcx>(
345
345
body_span : Span , // Usually `hir_body.value.span`, but not always
346
346
hir_body : & hir:: Body < ' tcx > ,
347
347
) -> Vec < Span > {
348
- struct HolesVisitor < ' hir , F > {
349
- tcx : TyCtxt < ' hir > ,
350
- visit_hole_span : F ,
348
+ struct HolesVisitor < ' tcx > {
349
+ tcx : TyCtxt < ' tcx > ,
350
+ body_span : Span ,
351
+ hole_spans : Vec < Span > ,
351
352
}
352
353
353
- impl < ' hir , F : FnMut ( Span ) > Visitor < ' hir > for HolesVisitor < ' hir , F > {
354
+ impl < ' tcx > Visitor < ' tcx > for HolesVisitor < ' tcx > {
354
355
/// We override `visit_nested_item` instead of `visit_item` because we
355
356
/// only need the item's span, not the item itself.
356
357
fn visit_nested_item ( & mut self , id : hir:: ItemId ) -> Self :: Result {
357
358
let span = self . tcx . def_span ( id. owner_id . def_id ) ;
358
- ( self . visit_hole_span ) ( span) ;
359
+ self . visit_hole_span ( span) ;
359
360
// Having visited this item, we don't care about its children,
360
361
// so don't call `walk_item`.
361
362
}
362
363
363
364
// We override `visit_expr` instead of the more specific expression
364
365
// visitors, so that we have direct access to the expression span.
365
- fn visit_expr ( & mut self , expr : & ' hir hir:: Expr < ' hir > ) {
366
+ fn visit_expr ( & mut self , expr : & ' tcx hir:: Expr < ' tcx > ) {
366
367
match expr. kind {
367
368
hir:: ExprKind :: Closure ( _) | hir:: ExprKind :: ConstBlock ( _) => {
368
- ( self . visit_hole_span ) ( expr. span ) ;
369
+ self . visit_hole_span ( expr. span ) ;
369
370
// Having visited this expression, we don't care about its
370
371
// children, so don't call `walk_expr`.
371
372
}
@@ -375,18 +376,17 @@ fn extract_hole_spans_from_hir<'tcx>(
375
376
}
376
377
}
377
378
}
378
-
379
- let mut hole_spans = vec ! [ ] ;
380
- let mut visitor = HolesVisitor {
381
- tcx,
382
- visit_hole_span : |hole_span| {
379
+ impl HolesVisitor < ' _ > {
380
+ fn visit_hole_span ( & mut self , hole_span : Span ) {
383
381
// Discard any holes that aren't directly visible within the body span.
384
- if body_span. contains ( hole_span) && body_span. eq_ctxt ( hole_span) {
385
- hole_spans. push ( hole_span) ;
382
+ if self . body_span . contains ( hole_span) && self . body_span . eq_ctxt ( hole_span) {
383
+ self . hole_spans . push ( hole_span) ;
386
384
}
387
- } ,
388
- } ;
385
+ }
386
+ }
387
+
388
+ let mut visitor = HolesVisitor { tcx, body_span, hole_spans : vec ! [ ] } ;
389
389
390
390
visitor. visit_body ( hir_body) ;
391
- hole_spans
391
+ visitor . hole_spans
392
392
}
0 commit comments