@@ -346,36 +346,37 @@ fn extract_hole_spans_from_hir<'tcx>(
346346 body_span : Span , // Usually `hir_body.value.span`, but not always
347347 hir_body : & hir:: Body < ' tcx > ,
348348) -> 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 > ,
352353 }
353354
354- impl < ' hir , F : FnMut ( Span ) > Visitor < ' hir > for HolesVisitor < ' hir , F > {
355+ impl < ' tcx > Visitor < ' tcx > for HolesVisitor < ' tcx > {
355356 /// We have special handling for nested items, but we still want to
356357 /// traverse into nested bodies of things that are not considered items,
357358 /// such as "anon consts" (e.g. array lengths).
358359 type NestedFilter = nested_filter:: OnlyBodies ;
359360
360- fn maybe_tcx ( & mut self ) -> Self :: MaybeTyCtxt {
361+ fn maybe_tcx ( & mut self ) -> TyCtxt < ' tcx > {
361362 self . tcx
362363 }
363364
364365 /// We override `visit_nested_item` instead of `visit_item` because we
365366 /// only need the item's span, not the item itself.
366367 fn visit_nested_item ( & mut self , id : hir:: ItemId ) -> Self :: Result {
367368 let span = self . tcx . def_span ( id. owner_id . def_id ) ;
368- ( self . visit_hole_span ) ( span) ;
369+ self . visit_hole_span ( span) ;
369370 // Having visited this item, we don't care about its children,
370371 // so don't call `walk_item`.
371372 }
372373
373374 // We override `visit_expr` instead of the more specific expression
374375 // 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 > ) {
376377 match expr. kind {
377378 hir:: ExprKind :: Closure ( _) | hir:: ExprKind :: ConstBlock ( _) => {
378- ( self . visit_hole_span ) ( expr. span ) ;
379+ self . visit_hole_span ( expr. span ) ;
379380 // Having visited this expression, we don't care about its
380381 // children, so don't call `walk_expr`.
381382 }
@@ -385,18 +386,17 @@ fn extract_hole_spans_from_hir<'tcx>(
385386 }
386387 }
387388 }
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 ) {
393391 // 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) ;
396394 }
397- } ,
398- } ;
395+ }
396+ }
397+
398+ let mut visitor = HolesVisitor { tcx, body_span, hole_spans : vec ! [ ] } ;
399399
400400 visitor. visit_body ( hir_body) ;
401- hole_spans
401+ visitor . hole_spans
402402}
0 commit comments