@@ -132,10 +132,6 @@ pub(crate) enum RibKind<'a> {
132
132
/// We passed through a closure. Disallow labels.
133
133
ClosureOrAsyncRibKind ,
134
134
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
-
139
135
/// We passed through an item scope. Disallow upvars.
140
136
ItemRibKind ( HasGenericParams ) ,
141
137
@@ -172,7 +168,6 @@ impl RibKind<'_> {
172
168
match self {
173
169
NormalRibKind
174
170
| ClosureOrAsyncRibKind
175
- | FnItemRibKind
176
171
| ConstantItemRibKind ( ..)
177
172
| ModuleRibKind ( _)
178
173
| MacroDefinition ( _)
@@ -189,7 +184,6 @@ impl RibKind<'_> {
189
184
190
185
AssocItemRibKind
191
186
| ClosureOrAsyncRibKind
192
- | FnItemRibKind
193
187
| ItemRibKind ( ..)
194
188
| ConstantItemRibKind ( ..)
195
189
| ModuleRibKind ( ..)
@@ -793,7 +787,8 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
793
787
}
794
788
}
795
789
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 {
797
792
// Bail if the function is foreign, and thus cannot validly have
798
793
// a body, or if there's no body for some other reason.
799
794
FnKind :: Fn ( FnCtxt :: Foreign , _, sig, _, generics, _)
@@ -816,20 +811,18 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
816
811
) ;
817
812
return ;
818
813
}
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 ( ..) => { }
822
819
} ;
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
- }
827
820
debug ! ( "(resolving function) entering function" ) ;
828
821
829
822
// Create a value rib for the function.
830
- self . with_rib ( ValueNS , rib_kind , |this| {
823
+ self . with_rib ( ValueNS , ClosureOrAsyncRibKind , |this| {
831
824
// Create a label rib for the function.
832
- this. with_label_rib ( FnItemRibKind , |this| {
825
+ this. with_label_rib ( ClosureOrAsyncRibKind , |this| {
833
826
match fn_kind {
834
827
FnKind :: Fn ( _, _, sig, _, generics, body) => {
835
828
this. visit_generics ( generics) ;
0 commit comments