@@ -345,27 +345,28 @@ fn extract_hole_spans_from_hir<'tcx>(
345345 body_span : Span , // Usually `hir_body.value.span`, but not always
346346 hir_body : & hir:: Body < ' tcx > ,
347347) -> 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 > ,
351352 }
352353
353- impl < ' hir , F : FnMut ( Span ) > Visitor < ' hir > for HolesVisitor < ' hir , F > {
354+ impl < ' tcx > Visitor < ' tcx > for HolesVisitor < ' tcx > {
354355 /// We override `visit_nested_item` instead of `visit_item` because we
355356 /// only need the item's span, not the item itself.
356357 fn visit_nested_item ( & mut self , id : hir:: ItemId ) -> Self :: Result {
357358 let span = self . tcx . def_span ( id. owner_id . def_id ) ;
358- ( self . visit_hole_span ) ( span) ;
359+ self . visit_hole_span ( span) ;
359360 // Having visited this item, we don't care about its children,
360361 // so don't call `walk_item`.
361362 }
362363
363364 // We override `visit_expr` instead of the more specific expression
364365 // 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 > ) {
366367 match expr. kind {
367368 hir:: ExprKind :: Closure ( _) | hir:: ExprKind :: ConstBlock ( _) => {
368- ( self . visit_hole_span ) ( expr. span ) ;
369+ self . visit_hole_span ( expr. span ) ;
369370 // Having visited this expression, we don't care about its
370371 // children, so don't call `walk_expr`.
371372 }
@@ -375,18 +376,17 @@ fn extract_hole_spans_from_hir<'tcx>(
375376 }
376377 }
377378 }
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 ) {
383381 // 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) ;
386384 }
387- } ,
388- } ;
385+ }
386+ }
387+
388+ let mut visitor = HolesVisitor { tcx, body_span, hole_spans : vec ! [ ] } ;
389389
390390 visitor. visit_body ( hir_body) ;
391- hole_spans
391+ visitor . hole_spans
392392}
0 commit comments