diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2022-07-14 17:40:43 +0200 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2022-08-23 00:08:42 +0200 |
| commit | da9ccc2c98ac4d88e5f2b940b9b61ec6d25facaa (patch) | |
| tree | acb95f981a854824b26c07c626dc5a8a89a9a08b | |
| parent | 6e88d738be05637824f581fc9cb59990406bf2ba (diff) | |
| download | rust-da9ccc2c98ac4d88e5f2b940b9b61ec6d25facaa.tar.gz rust-da9ccc2c98ac4d88e5f2b940b9b61ec6d25facaa.zip | |
Remove FnItemRibKind.
| -rw-r--r-- | compiler/rustc_resolve/src/ident.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/late.rs | 25 |
2 files changed, 10 insertions, 27 deletions
diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 0d8f1cf3656..41a0c76d83a 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -1105,7 +1105,7 @@ impl<'a> Resolver<'a> { | ForwardGenericParamBanRibKind => { // Nothing to do. Continue. } - ItemRibKind(_) | FnItemRibKind | AssocItemRibKind => { + ItemRibKind(_) | AssocItemRibKind => { // This was an attempt to access an upvar inside a // named function item. This is not allowed, so we // report an error. @@ -1173,7 +1173,6 @@ impl<'a> Resolver<'a> { | ModuleRibKind(..) | MacroDefinition(..) | InlineAsmSymRibKind - | FnItemRibKind | AssocItemRibKind | ForwardGenericParamBanRibKind => { // Nothing to do. Continue. @@ -1236,14 +1235,6 @@ impl<'a> Resolver<'a> { } } Res::Def(DefKind::ConstParam, _) => { - let mut ribs = ribs.iter().peekable(); - if let Some(Rib { kind: FnItemRibKind, .. }) = ribs.peek() { - // When declaring const parameters inside function signatures, the first rib - // is always a `FnItemRibKind`. In this case, we can skip it, to avoid it - // (spuriously) conflicting with the const param. - ribs.next(); - } - for rib in ribs { let has_generic_params = match rib.kind { NormalRibKind @@ -1251,7 +1242,6 @@ impl<'a> Resolver<'a> { | ModuleRibKind(..) | MacroDefinition(..) | InlineAsmSymRibKind - | FnItemRibKind | AssocItemRibKind | ForwardGenericParamBanRibKind => continue, diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 748a0781c4f..693ec86616e 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -132,10 +132,6 @@ pub(crate) enum RibKind<'a> { /// We passed through a closure. Disallow labels. ClosureOrAsyncRibKind, - /// We passed through a function definition. Disallow upvars. - /// Permit only those const parameters that are specified in the function's generics. - FnItemRibKind, - /// We passed through an item scope. Disallow upvars. ItemRibKind(HasGenericParams), @@ -172,7 +168,6 @@ impl RibKind<'_> { match self { NormalRibKind | ClosureOrAsyncRibKind - | FnItemRibKind | ConstantItemRibKind(..) | ModuleRibKind(_) | MacroDefinition(_) @@ -189,7 +184,6 @@ impl RibKind<'_> { AssocItemRibKind | ClosureOrAsyncRibKind - | FnItemRibKind | ItemRibKind(..) | ConstantItemRibKind(..) | ModuleRibKind(..) @@ -793,7 +787,8 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> { } } fn visit_fn(&mut self, fn_kind: FnKind<'ast>, sp: Span, fn_id: NodeId) { - let rib_kind = match fn_kind { + let previous_value = self.diagnostic_metadata.current_function; + match fn_kind { // Bail if the function is foreign, and thus cannot validly have // a body, or if there's no body for some other reason. FnKind::Fn(FnCtxt::Foreign, _, sig, _, generics, _) @@ -816,20 +811,18 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> { ); return; } - FnKind::Fn(FnCtxt::Free, ..) => FnItemRibKind, - FnKind::Fn(FnCtxt::Assoc(_), ..) => NormalRibKind, - FnKind::Closure(..) => ClosureOrAsyncRibKind, + FnKind::Fn(..) => { + self.diagnostic_metadata.current_function = Some((fn_kind, sp)); + } + // Do not update `current_function` for closures: it suggests `self` parameters. + FnKind::Closure(..) => {} }; - let previous_value = self.diagnostic_metadata.current_function; - if matches!(fn_kind, FnKind::Fn(..)) { - self.diagnostic_metadata.current_function = Some((fn_kind, sp)); - } debug!("(resolving function) entering function"); // Create a value rib for the function. - self.with_rib(ValueNS, rib_kind, |this| { + self.with_rib(ValueNS, ClosureOrAsyncRibKind, |this| { // Create a label rib for the function. - this.with_label_rib(FnItemRibKind, |this| { + this.with_label_rib(ClosureOrAsyncRibKind, |this| { match fn_kind { FnKind::Fn(_, _, sig, _, generics, body) => { this.visit_generics(generics); |
