@@ -345,6 +345,9 @@ struct LateResolutionVisitor<'a, 'b> {
345345 /// The current self item if inside an ADT (used for better errors).
346346 current_self_item : Option < NodeId > ,
347347
348+ /// The current enclosing funciton (used for better errors).
349+ current_function : Option < Span > ,
350+
348351 /// A list of labels as of yet unused. Labels will be removed from this map when
349352 /// they are used (in a `break` or `continue` statement)
350353 unused_labels : FxHashMap < NodeId , Span > ,
@@ -415,7 +418,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> {
415418 }
416419 }
417420 }
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) ) ;
419423 debug ! ( "(resolving function) entering function" ) ;
420424 let rib_kind = match fn_kind {
421425 FnKind :: ItemFn ( ..) => FnItemRibKind ,
@@ -441,6 +445,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> {
441445 debug ! ( "(resolving function) leaving function" ) ;
442446 } )
443447 } ) ;
448+ self . current_function = previous_value;
444449 }
445450
446451 fn visit_generics ( & mut self , generics : & ' tcx Generics ) {
@@ -546,6 +551,7 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> {
546551 current_trait_assoc_types : Vec :: new ( ) ,
547552 current_self_type : None ,
548553 current_self_item : None ,
554+ current_function : None ,
549555 unused_labels : Default :: default ( ) ,
550556 current_type_ascription : Vec :: new ( ) ,
551557 }
0 commit comments