@@ -132,10 +132,6 @@ pub(crate) enum RibKind<'a> {
132132 /// We passed through a closure. Disallow labels.
133133 ClosureOrAsyncRibKind ,
134134
135- /// We passed through a function definition. Disallow upvars.
136- /// Permit only those const parameters that are specified in the function's generics.
137- FnItemRibKind ,
138-
139135 /// We passed through an item scope. Disallow upvars.
140136 ItemRibKind ( HasGenericParams ) ,
141137
@@ -172,7 +168,6 @@ impl RibKind<'_> {
172168 match self {
173169 NormalRibKind
174170 | ClosureOrAsyncRibKind
175- | FnItemRibKind
176171 | ConstantItemRibKind ( ..)
177172 | ModuleRibKind ( _)
178173 | MacroDefinition ( _)
@@ -189,7 +184,6 @@ impl RibKind<'_> {
189184
190185 AssocItemRibKind
191186 | ClosureOrAsyncRibKind
192- | FnItemRibKind
193187 | ItemRibKind ( ..)
194188 | ConstantItemRibKind ( ..)
195189 | ModuleRibKind ( ..)
@@ -793,7 +787,8 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
793787 }
794788 }
795789 fn visit_fn ( & mut self , fn_kind : FnKind < ' ast > , sp : Span , fn_id : NodeId ) {
796- let rib_kind = match fn_kind {
790+ let previous_value = self . diagnostic_metadata . current_function ;
791+ match fn_kind {
797792 // Bail if the function is foreign, and thus cannot validly have
798793 // a body, or if there's no body for some other reason.
799794 FnKind :: Fn ( FnCtxt :: Foreign , _, sig, _, generics, _)
@@ -816,20 +811,18 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
816811 ) ;
817812 return ;
818813 }
819- FnKind :: Fn ( FnCtxt :: Free , ..) => FnItemRibKind ,
820- FnKind :: Fn ( FnCtxt :: Assoc ( _) , ..) => NormalRibKind ,
821- FnKind :: Closure ( ..) => ClosureOrAsyncRibKind ,
814+ FnKind :: Fn ( ..) => {
815+ self . diagnostic_metadata . current_function = Some ( ( fn_kind, sp) ) ;
816+ }
817+ // Do not update `current_function` for closures: it suggests `self` parameters.
818+ FnKind :: Closure ( ..) => { }
822819 } ;
823- let previous_value = self . diagnostic_metadata . current_function ;
824- if matches ! ( fn_kind, FnKind :: Fn ( ..) ) {
825- self . diagnostic_metadata . current_function = Some ( ( fn_kind, sp) ) ;
826- }
827820 debug ! ( "(resolving function) entering function" ) ;
828821
829822 // Create a value rib for the function.
830- self . with_rib ( ValueNS , rib_kind , |this| {
823+ self . with_rib ( ValueNS , ClosureOrAsyncRibKind , |this| {
831824 // Create a label rib for the function.
832- this. with_label_rib ( FnItemRibKind , |this| {
825+ this. with_label_rib ( ClosureOrAsyncRibKind , |this| {
833826 match fn_kind {
834827 FnKind :: Fn ( _, _, sig, _, generics, body) => {
835828 this. visit_generics ( generics) ;
0 commit comments