@@ -345,6 +345,9 @@ struct LateResolutionVisitor<'a, 'b> {
345
345
/// The current self item if inside an ADT (used for better errors).
346
346
current_self_item : Option < NodeId > ,
347
347
348
+ /// The current enclosing funciton (used for better errors).
349
+ current_function : Option < Span > ,
350
+
348
351
/// A list of labels as of yet unused. Labels will be removed from this map when
349
352
/// they are used (in a `break` or `continue` statement)
350
353
unused_labels : FxHashMap < NodeId , Span > ,
@@ -415,7 +418,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> {
415
418
}
416
419
}
417
420
}
418
- fn visit_fn ( & mut self , fn_kind : FnKind < ' tcx > , declaration : & ' tcx FnDecl , _: Span , _: NodeId ) {
421
+ fn visit_fn ( & mut self , fn_kind : FnKind < ' tcx > , declaration : & ' tcx FnDecl , sp : Span , _: NodeId ) {
422
+ let previous_value = replace ( & mut self . current_function , Some ( sp) ) ;
419
423
debug ! ( "(resolving function) entering function" ) ;
420
424
let rib_kind = match fn_kind {
421
425
FnKind :: ItemFn ( ..) => FnItemRibKind ,
@@ -441,6 +445,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> {
441
445
debug ! ( "(resolving function) leaving function" ) ;
442
446
} )
443
447
} ) ;
448
+ self . current_function = previous_value;
444
449
}
445
450
446
451
fn visit_generics ( & mut self , generics : & ' tcx Generics ) {
@@ -546,6 +551,7 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> {
546
551
current_trait_assoc_types : Vec :: new ( ) ,
547
552
current_self_type : None ,
548
553
current_self_item : None ,
554
+ current_function : None ,
549
555
unused_labels : Default :: default ( ) ,
550
556
current_type_ascription : Vec :: new ( ) ,
551
557
}
0 commit comments