Skip to content

Commit da9ccc2

Browse files
committed
Remove FnItemRibKind.
1 parent 6e88d73 commit da9ccc2

File tree

2 files changed

+10
-27
lines changed

2 files changed

+10
-27
lines changed

compiler/rustc_resolve/src/ident.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ impl<'a> Resolver<'a> {
11051105
| ForwardGenericParamBanRibKind => {
11061106
// Nothing to do. Continue.
11071107
}
1108-
ItemRibKind(_) | FnItemRibKind | AssocItemRibKind => {
1108+
ItemRibKind(_) | AssocItemRibKind => {
11091109
// This was an attempt to access an upvar inside a
11101110
// named function item. This is not allowed, so we
11111111
// report an error.
@@ -1173,7 +1173,6 @@ impl<'a> Resolver<'a> {
11731173
| ModuleRibKind(..)
11741174
| MacroDefinition(..)
11751175
| InlineAsmSymRibKind
1176-
| FnItemRibKind
11771176
| AssocItemRibKind
11781177
| ForwardGenericParamBanRibKind => {
11791178
// Nothing to do. Continue.
@@ -1236,22 +1235,13 @@ impl<'a> Resolver<'a> {
12361235
}
12371236
}
12381237
Res::Def(DefKind::ConstParam, _) => {
1239-
let mut ribs = ribs.iter().peekable();
1240-
if let Some(Rib { kind: FnItemRibKind, .. }) = ribs.peek() {
1241-
// When declaring const parameters inside function signatures, the first rib
1242-
// is always a `FnItemRibKind`. In this case, we can skip it, to avoid it
1243-
// (spuriously) conflicting with the const param.
1244-
ribs.next();
1245-
}
1246-
12471238
for rib in ribs {
12481239
let has_generic_params = match rib.kind {
12491240
NormalRibKind
12501241
| ClosureOrAsyncRibKind
12511242
| ModuleRibKind(..)
12521243
| MacroDefinition(..)
12531244
| InlineAsmSymRibKind
1254-
| FnItemRibKind
12551245
| AssocItemRibKind
12561246
| ForwardGenericParamBanRibKind => continue,
12571247

compiler/rustc_resolve/src/late.rs

+9-16
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)