Remove "RibKind" suffix from RibKind
variants
This commit is contained in:
parent
6197e4d209
commit
0fa59204e5
@ -323,7 +323,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
}
|
||||
|
||||
module = match ribs[i].kind {
|
||||
RibKind::ModuleRibKind(module) => module,
|
||||
RibKind::Module(module) => module,
|
||||
RibKind::MacroDefinition(def) if def == self.macro_def(ident.span.ctxt()) => {
|
||||
// If an invocation of this macro created `ident`, give up on `ident`
|
||||
// and switch to `ident`'s source from the macro definition.
|
||||
@ -1083,7 +1083,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
let ribs = &all_ribs[rib_index + 1..];
|
||||
|
||||
// An invalid forward use of a generic parameter from a previous default.
|
||||
if let RibKind::ForwardGenericParamBanRibKind = all_ribs[rib_index].kind {
|
||||
if let RibKind::ForwardGenericParamBan = all_ribs[rib_index].kind {
|
||||
if let Some(span) = finalize {
|
||||
let res_error = if rib_ident.name == kw::SelfUpper {
|
||||
ResolutionError::SelfInGenericParamDefault
|
||||
@ -1103,14 +1103,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
|
||||
for rib in ribs {
|
||||
match rib.kind {
|
||||
RibKind::NormalRibKind
|
||||
| RibKind::ClosureOrAsyncRibKind
|
||||
| RibKind::ModuleRibKind(..)
|
||||
RibKind::Normal
|
||||
| RibKind::ClosureOrAsync
|
||||
| RibKind::Module(..)
|
||||
| RibKind::MacroDefinition(..)
|
||||
| RibKind::ForwardGenericParamBanRibKind => {
|
||||
| RibKind::ForwardGenericParamBan => {
|
||||
// Nothing to do. Continue.
|
||||
}
|
||||
RibKind::ItemRibKind(_) | RibKind::AssocItemRibKind => {
|
||||
RibKind::Item(_) | RibKind::AssocItem => {
|
||||
// This was an attempt to access an upvar inside a
|
||||
// named function item. This is not allowed, so we
|
||||
// report an error.
|
||||
@ -1122,7 +1122,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
res_err = Some((span, CannotCaptureDynamicEnvironmentInFnItem));
|
||||
}
|
||||
}
|
||||
RibKind::ConstantItemRibKind(_, item) => {
|
||||
RibKind::ConstantItem(_, item) => {
|
||||
// Still doesn't deal with upvars
|
||||
if let Some(span) = finalize {
|
||||
let (span, resolution_error) =
|
||||
@ -1151,13 +1151,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
}
|
||||
return Res::Err;
|
||||
}
|
||||
RibKind::ConstParamTyRibKind => {
|
||||
RibKind::ConstParamTy => {
|
||||
if let Some(span) = finalize {
|
||||
self.report_error(span, ParamInTyOfConstParam(rib_ident.name));
|
||||
}
|
||||
return Res::Err;
|
||||
}
|
||||
RibKind::InlineAsmSymRibKind => {
|
||||
RibKind::InlineAsmSym => {
|
||||
if let Some(span) = finalize {
|
||||
self.report_error(span, InvalidAsmSym);
|
||||
}
|
||||
@ -1173,18 +1173,18 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
Res::Def(DefKind::TyParam, _) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } => {
|
||||
for rib in ribs {
|
||||
let has_generic_params: HasGenericParams = match rib.kind {
|
||||
RibKind::NormalRibKind
|
||||
| RibKind::ClosureOrAsyncRibKind
|
||||
| RibKind::ModuleRibKind(..)
|
||||
RibKind::Normal
|
||||
| RibKind::ClosureOrAsync
|
||||
| RibKind::Module(..)
|
||||
| RibKind::MacroDefinition(..)
|
||||
| RibKind::InlineAsmSymRibKind
|
||||
| RibKind::AssocItemRibKind
|
||||
| RibKind::ForwardGenericParamBanRibKind => {
|
||||
| RibKind::InlineAsmSym
|
||||
| RibKind::AssocItem
|
||||
| RibKind::ForwardGenericParamBan => {
|
||||
// Nothing to do. Continue.
|
||||
continue;
|
||||
}
|
||||
|
||||
RibKind::ConstantItemRibKind(trivial, _) => {
|
||||
RibKind::ConstantItem(trivial, _) => {
|
||||
let features = self.tcx.sess.features_untracked();
|
||||
// HACK(min_const_generics): We currently only allow `N` or `{ N }`.
|
||||
if !(trivial == ConstantHasGenerics::Yes
|
||||
@ -1225,8 +1225,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
}
|
||||
|
||||
// This was an attempt to use a type parameter outside its scope.
|
||||
RibKind::ItemRibKind(has_generic_params) => has_generic_params,
|
||||
RibKind::ConstParamTyRibKind => {
|
||||
RibKind::Item(has_generic_params) => has_generic_params,
|
||||
RibKind::ConstParamTy => {
|
||||
if let Some(span) = finalize {
|
||||
self.report_error(
|
||||
span,
|
||||
@ -1252,15 +1252,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
Res::Def(DefKind::ConstParam, _) => {
|
||||
for rib in ribs {
|
||||
let has_generic_params = match rib.kind {
|
||||
RibKind::NormalRibKind
|
||||
| RibKind::ClosureOrAsyncRibKind
|
||||
| RibKind::ModuleRibKind(..)
|
||||
RibKind::Normal
|
||||
| RibKind::ClosureOrAsync
|
||||
| RibKind::Module(..)
|
||||
| RibKind::MacroDefinition(..)
|
||||
| RibKind::InlineAsmSymRibKind
|
||||
| RibKind::AssocItemRibKind
|
||||
| RibKind::ForwardGenericParamBanRibKind => continue,
|
||||
| RibKind::InlineAsmSym
|
||||
| RibKind::AssocItem
|
||||
| RibKind::ForwardGenericParamBan => continue,
|
||||
|
||||
RibKind::ConstantItemRibKind(trivial, _) => {
|
||||
RibKind::ConstantItem(trivial, _) => {
|
||||
let features = self.tcx.sess.features_untracked();
|
||||
// HACK(min_const_generics): We currently only allow `N` or `{ N }`.
|
||||
if !(trivial == ConstantHasGenerics::Yes
|
||||
@ -1283,8 +1283,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
continue;
|
||||
}
|
||||
|
||||
RibKind::ItemRibKind(has_generic_params) => has_generic_params,
|
||||
RibKind::ConstParamTyRibKind => {
|
||||
RibKind::Item(has_generic_params) => has_generic_params,
|
||||
RibKind::ConstParamTy => {
|
||||
if let Some(span) = finalize {
|
||||
self.report_error(
|
||||
span,
|
||||
|
@ -131,28 +131,28 @@ enum RecordPartialRes {
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub(crate) enum RibKind<'a> {
|
||||
/// No restriction needs to be applied.
|
||||
NormalRibKind,
|
||||
Normal,
|
||||
|
||||
/// We passed through an impl or trait and are now in one of its
|
||||
/// methods or associated types. Allow references to ty params that impl or trait
|
||||
/// binds. Disallow any other upvars (including other ty params that are
|
||||
/// upvars).
|
||||
AssocItemRibKind,
|
||||
AssocItem,
|
||||
|
||||
/// We passed through a closure. Disallow labels.
|
||||
ClosureOrAsyncRibKind,
|
||||
ClosureOrAsync,
|
||||
|
||||
/// We passed through an item scope. Disallow upvars.
|
||||
ItemRibKind(HasGenericParams),
|
||||
Item(HasGenericParams),
|
||||
|
||||
/// We're in a constant item. Can't refer to dynamic stuff.
|
||||
///
|
||||
/// The item may reference generic parameters in trivial constant expressions.
|
||||
/// All other constants aren't allowed to use generic params at all.
|
||||
ConstantItemRibKind(ConstantHasGenerics, Option<(Ident, ConstantItemKind)>),
|
||||
ConstantItem(ConstantHasGenerics, Option<(Ident, ConstantItemKind)>),
|
||||
|
||||
/// We passed through a module.
|
||||
ModuleRibKind(Module<'a>),
|
||||
Module(Module<'a>),
|
||||
|
||||
/// We passed through a `macro_rules!` statement
|
||||
MacroDefinition(DefId),
|
||||
@ -160,15 +160,15 @@ pub(crate) enum RibKind<'a> {
|
||||
/// All bindings in this rib are generic parameters that can't be used
|
||||
/// from the default of a generic parameter because they're not declared
|
||||
/// before said generic parameter. Also see the `visit_generics` override.
|
||||
ForwardGenericParamBanRibKind,
|
||||
ForwardGenericParamBan,
|
||||
|
||||
/// We are inside of the type of a const parameter. Can't refer to any
|
||||
/// parameters.
|
||||
ConstParamTyRibKind,
|
||||
ConstParamTy,
|
||||
|
||||
/// We are inside a `sym` inline assembly operand. Can only refer to
|
||||
/// globals.
|
||||
InlineAsmSymRibKind,
|
||||
InlineAsmSym,
|
||||
}
|
||||
|
||||
impl RibKind<'_> {
|
||||
@ -176,32 +176,30 @@ impl RibKind<'_> {
|
||||
/// variables.
|
||||
pub(crate) fn contains_params(&self) -> bool {
|
||||
match self {
|
||||
RibKind::NormalRibKind
|
||||
| RibKind::ClosureOrAsyncRibKind
|
||||
| RibKind::ConstantItemRibKind(..)
|
||||
| RibKind::ModuleRibKind(_)
|
||||
RibKind::Normal
|
||||
| RibKind::ClosureOrAsync
|
||||
| RibKind::ConstantItem(..)
|
||||
| RibKind::Module(_)
|
||||
| RibKind::MacroDefinition(_)
|
||||
| RibKind::ConstParamTyRibKind
|
||||
| RibKind::InlineAsmSymRibKind => false,
|
||||
RibKind::AssocItemRibKind
|
||||
| RibKind::ItemRibKind(_)
|
||||
| RibKind::ForwardGenericParamBanRibKind => true,
|
||||
| RibKind::ConstParamTy
|
||||
| RibKind::InlineAsmSym => false,
|
||||
RibKind::AssocItem | RibKind::Item(_) | RibKind::ForwardGenericParamBan => true,
|
||||
}
|
||||
}
|
||||
|
||||
/// This rib forbids referring to labels defined in upwards ribs.
|
||||
fn is_label_barrier(self) -> bool {
|
||||
match self {
|
||||
RibKind::NormalRibKind | RibKind::MacroDefinition(..) => false,
|
||||
RibKind::Normal | RibKind::MacroDefinition(..) => false,
|
||||
|
||||
RibKind::AssocItemRibKind
|
||||
| RibKind::ClosureOrAsyncRibKind
|
||||
| RibKind::ItemRibKind(..)
|
||||
| RibKind::ConstantItemRibKind(..)
|
||||
| RibKind::ModuleRibKind(..)
|
||||
| RibKind::ForwardGenericParamBanRibKind
|
||||
| RibKind::ConstParamTyRibKind
|
||||
| RibKind::InlineAsmSymRibKind => true,
|
||||
RibKind::AssocItem
|
||||
| RibKind::ClosureOrAsync
|
||||
| RibKind::Item(..)
|
||||
| RibKind::ConstantItem(..)
|
||||
| RibKind::Module(..)
|
||||
| RibKind::ForwardGenericParamBan
|
||||
| RibKind::ConstParamTy
|
||||
| RibKind::InlineAsmSym => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -705,7 +703,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
||||
let span = ty.span.shrink_to_lo().to(path.span.shrink_to_lo());
|
||||
self.with_generic_param_rib(
|
||||
&[],
|
||||
RibKind::NormalRibKind,
|
||||
RibKind::Normal,
|
||||
LifetimeRibKind::Generics {
|
||||
binder: ty.id,
|
||||
kind: LifetimeBinderKind::PolyTrait,
|
||||
@ -743,7 +741,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
||||
let span = ty.span.shrink_to_lo().to(bare_fn.decl_span.shrink_to_lo());
|
||||
self.with_generic_param_rib(
|
||||
&bare_fn.generic_params,
|
||||
RibKind::NormalRibKind,
|
||||
RibKind::Normal,
|
||||
LifetimeRibKind::Generics {
|
||||
binder: ty.id,
|
||||
kind: LifetimeBinderKind::BareFnType,
|
||||
@ -783,7 +781,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
||||
let span = tref.span.shrink_to_lo().to(tref.trait_ref.path.span.shrink_to_lo());
|
||||
self.with_generic_param_rib(
|
||||
&tref.bound_generic_params,
|
||||
RibKind::NormalRibKind,
|
||||
RibKind::Normal,
|
||||
LifetimeRibKind::Generics {
|
||||
binder: tref.trait_ref.ref_id,
|
||||
kind: LifetimeBinderKind::PolyTrait,
|
||||
@ -807,7 +805,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
||||
ForeignItemKind::TyAlias(box TyAlias { ref generics, .. }) => {
|
||||
self.with_generic_param_rib(
|
||||
&generics.params,
|
||||
RibKind::ItemRibKind(HasGenericParams::Yes(generics.span)),
|
||||
RibKind::Item(HasGenericParams::Yes(generics.span)),
|
||||
LifetimeRibKind::Generics {
|
||||
binder: foreign_item.id,
|
||||
kind: LifetimeBinderKind::Item,
|
||||
@ -819,7 +817,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
||||
ForeignItemKind::Fn(box Fn { ref generics, .. }) => {
|
||||
self.with_generic_param_rib(
|
||||
&generics.params,
|
||||
RibKind::ItemRibKind(HasGenericParams::Yes(generics.span)),
|
||||
RibKind::Item(HasGenericParams::Yes(generics.span)),
|
||||
LifetimeRibKind::Generics {
|
||||
binder: foreign_item.id,
|
||||
kind: LifetimeBinderKind::Function,
|
||||
@ -873,9 +871,9 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
||||
debug!("(resolving function) entering function");
|
||||
|
||||
// Create a value rib for the function.
|
||||
self.with_rib(ValueNS, RibKind::ClosureOrAsyncRibKind, |this| {
|
||||
self.with_rib(ValueNS, RibKind::ClosureOrAsync, |this| {
|
||||
// Create a label rib for the function.
|
||||
this.with_label_rib(RibKind::ClosureOrAsyncRibKind, |this| {
|
||||
this.with_label_rib(RibKind::ClosureOrAsync, |this| {
|
||||
match fn_kind {
|
||||
FnKind::Fn(_, _, sig, _, generics, body) => {
|
||||
this.visit_generics(generics);
|
||||
@ -1132,7 +1130,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
||||
let span = predicate_span.shrink_to_lo().to(bounded_ty.span.shrink_to_lo());
|
||||
this.with_generic_param_rib(
|
||||
&bound_generic_params,
|
||||
RibKind::NormalRibKind,
|
||||
RibKind::Normal,
|
||||
LifetimeRibKind::Generics {
|
||||
binder: bounded_ty.id,
|
||||
kind: LifetimeBinderKind::WhereBound,
|
||||
@ -1178,9 +1176,9 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
||||
|
||||
fn visit_inline_asm_sym(&mut self, sym: &'ast InlineAsmSym) {
|
||||
// This is similar to the code for AnonConst.
|
||||
self.with_rib(ValueNS, RibKind::InlineAsmSymRibKind, |this| {
|
||||
this.with_rib(TypeNS, RibKind::InlineAsmSymRibKind, |this| {
|
||||
this.with_label_rib(RibKind::InlineAsmSymRibKind, |this| {
|
||||
self.with_rib(ValueNS, RibKind::InlineAsmSym, |this| {
|
||||
this.with_rib(TypeNS, RibKind::InlineAsmSym, |this| {
|
||||
this.with_label_rib(RibKind::InlineAsmSym, |this| {
|
||||
this.smart_resolve_path(sym.id, &sym.qself, &sym.path, PathSource::Expr(None));
|
||||
visit::walk_inline_asm_sym(this, sym);
|
||||
});
|
||||
@ -1205,7 +1203,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
// although it may be useful to track other components as well for diagnostics.
|
||||
let graph_root = resolver.graph_root;
|
||||
let parent_scope = ParentScope::module(graph_root, resolver);
|
||||
let start_rib_kind = RibKind::ModuleRibKind(graph_root);
|
||||
let start_rib_kind = RibKind::Module(graph_root);
|
||||
LateResolutionVisitor {
|
||||
r: resolver,
|
||||
parent_scope,
|
||||
@ -1309,8 +1307,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
if let Some(module) = self.r.get_module(self.r.local_def_id(id).to_def_id()) {
|
||||
// Move down in the graph.
|
||||
let orig_module = replace(&mut self.parent_scope.module, module);
|
||||
self.with_rib(ValueNS, RibKind::ModuleRibKind(module), |this| {
|
||||
this.with_rib(TypeNS, RibKind::ModuleRibKind(module), |this| {
|
||||
self.with_rib(ValueNS, RibKind::Module(module), |this| {
|
||||
this.with_rib(TypeNS, RibKind::Module(module), |this| {
|
||||
let ret = f(this);
|
||||
this.parent_scope.module = orig_module;
|
||||
ret
|
||||
@ -1327,8 +1325,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
// provide previous type parameters as they're built. We
|
||||
// put all the parameters on the ban list and then remove
|
||||
// them one by one as they are processed and become available.
|
||||
let mut forward_ty_ban_rib = Rib::new(RibKind::ForwardGenericParamBanRibKind);
|
||||
let mut forward_const_ban_rib = Rib::new(RibKind::ForwardGenericParamBanRibKind);
|
||||
let mut forward_ty_ban_rib = Rib::new(RibKind::ForwardGenericParamBan);
|
||||
let mut forward_const_ban_rib = Rib::new(RibKind::ForwardGenericParamBan);
|
||||
for param in params.iter() {
|
||||
match param.kind {
|
||||
GenericParamKind::Type { .. } => {
|
||||
@ -1389,8 +1387,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
// Const parameters can't have param bounds.
|
||||
assert!(param.bounds.is_empty());
|
||||
|
||||
this.ribs[TypeNS].push(Rib::new(RibKind::ConstParamTyRibKind));
|
||||
this.ribs[ValueNS].push(Rib::new(RibKind::ConstParamTyRibKind));
|
||||
this.ribs[TypeNS].push(Rib::new(RibKind::ConstParamTy));
|
||||
this.ribs[ValueNS].push(Rib::new(RibKind::ConstParamTy));
|
||||
this.with_lifetime_rib(LifetimeRibKind::ConstGeneric, |this| {
|
||||
this.visit_ty(ty)
|
||||
});
|
||||
@ -2160,7 +2158,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
self.with_current_self_item(item, |this| {
|
||||
this.with_generic_param_rib(
|
||||
&generics.params,
|
||||
RibKind::ItemRibKind(HasGenericParams::Yes(generics.span)),
|
||||
RibKind::Item(HasGenericParams::Yes(generics.span)),
|
||||
LifetimeRibKind::Generics {
|
||||
binder: item.id,
|
||||
kind: LifetimeBinderKind::Item,
|
||||
@ -2241,7 +2239,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
ItemKind::TyAlias(box TyAlias { ref generics, .. }) => {
|
||||
self.with_generic_param_rib(
|
||||
&generics.params,
|
||||
RibKind::ItemRibKind(HasGenericParams::Yes(generics.span)),
|
||||
RibKind::Item(HasGenericParams::Yes(generics.span)),
|
||||
LifetimeRibKind::Generics {
|
||||
binder: item.id,
|
||||
kind: LifetimeBinderKind::Item,
|
||||
@ -2254,7 +2252,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
ItemKind::Fn(box Fn { ref generics, .. }) => {
|
||||
self.with_generic_param_rib(
|
||||
&generics.params,
|
||||
RibKind::ItemRibKind(HasGenericParams::Yes(generics.span)),
|
||||
RibKind::Item(HasGenericParams::Yes(generics.span)),
|
||||
LifetimeRibKind::Generics {
|
||||
binder: item.id,
|
||||
kind: LifetimeBinderKind::Function,
|
||||
@ -2293,7 +2291,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
// Create a new rib for the trait-wide type parameters.
|
||||
self.with_generic_param_rib(
|
||||
&generics.params,
|
||||
RibKind::ItemRibKind(HasGenericParams::Yes(generics.span)),
|
||||
RibKind::Item(HasGenericParams::Yes(generics.span)),
|
||||
LifetimeRibKind::Generics {
|
||||
binder: item.id,
|
||||
kind: LifetimeBinderKind::Item,
|
||||
@ -2314,7 +2312,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
// Create a new rib for the trait-wide type parameters.
|
||||
self.with_generic_param_rib(
|
||||
&generics.params,
|
||||
RibKind::ItemRibKind(HasGenericParams::Yes(generics.span)),
|
||||
RibKind::Item(HasGenericParams::Yes(generics.span)),
|
||||
LifetimeRibKind::Generics {
|
||||
binder: item.id,
|
||||
kind: LifetimeBinderKind::Item,
|
||||
@ -2417,11 +2415,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
let mut seen_lifetimes = FxHashSet::default();
|
||||
|
||||
// We also can't shadow bindings from the parent item
|
||||
if let RibKind::AssocItemRibKind = kind {
|
||||
if let RibKind::AssocItem = kind {
|
||||
let mut add_bindings_for_ns = |ns| {
|
||||
let parent_rib = self.ribs[ns]
|
||||
.iter()
|
||||
.rfind(|r| matches!(r.kind, RibKind::ItemRibKind(_)))
|
||||
.rfind(|r| matches!(r.kind, RibKind::Item(_)))
|
||||
.expect("associated item outside of an item");
|
||||
seen_bindings.extend(parent_rib.bindings.keys().map(|ident| (*ident, ident.span)));
|
||||
};
|
||||
@ -2510,10 +2508,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
};
|
||||
|
||||
let res = match kind {
|
||||
RibKind::ItemRibKind(..) | RibKind::AssocItemRibKind => {
|
||||
Res::Def(def_kind, def_id.to_def_id())
|
||||
}
|
||||
RibKind::NormalRibKind => {
|
||||
RibKind::Item(..) | RibKind::AssocItem => Res::Def(def_kind, def_id.to_def_id()),
|
||||
RibKind::Normal => {
|
||||
if self.r.tcx.sess.features_untracked().non_lifetime_binders {
|
||||
Res::Def(def_kind, def_id.to_def_id())
|
||||
} else {
|
||||
@ -2559,7 +2555,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
}
|
||||
|
||||
fn with_static_rib(&mut self, f: impl FnOnce(&mut Self)) {
|
||||
let kind = RibKind::ItemRibKind(HasGenericParams::No);
|
||||
let kind = RibKind::Item(HasGenericParams::No);
|
||||
self.with_rib(ValueNS, kind, |this| this.with_rib(TypeNS, kind, f))
|
||||
}
|
||||
|
||||
@ -2579,15 +2575,15 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
item: Option<(Ident, ConstantItemKind)>,
|
||||
f: impl FnOnce(&mut Self),
|
||||
) {
|
||||
self.with_rib(ValueNS, RibKind::ConstantItemRibKind(may_use_generics, item), |this| {
|
||||
self.with_rib(ValueNS, RibKind::ConstantItem(may_use_generics, item), |this| {
|
||||
this.with_rib(
|
||||
TypeNS,
|
||||
RibKind::ConstantItemRibKind(
|
||||
RibKind::ConstantItem(
|
||||
may_use_generics.force_yes_if(is_repeat == IsRepeatExpr::Yes),
|
||||
item,
|
||||
),
|
||||
|this| {
|
||||
this.with_label_rib(RibKind::ConstantItemRibKind(may_use_generics, item), f);
|
||||
this.with_label_rib(RibKind::ConstantItem(may_use_generics, item), f);
|
||||
},
|
||||
)
|
||||
});
|
||||
@ -2619,7 +2615,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
|this: &mut Self, generics: &Generics, kind, item: &'ast AssocItem| {
|
||||
this.with_generic_param_rib(
|
||||
&generics.params,
|
||||
RibKind::AssocItemRibKind,
|
||||
RibKind::AssocItem,
|
||||
LifetimeRibKind::Generics { binder: item.id, span: generics.span, kind },
|
||||
|this| visit::walk_assoc_item(this, item, AssocCtxt::Trait),
|
||||
);
|
||||
@ -2700,7 +2696,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
}
|
||||
|
||||
fn with_self_rib_ns(&mut self, ns: Namespace, self_res: Res, f: impl FnOnce(&mut Self)) {
|
||||
let mut self_type_rib = Rib::new(RibKind::NormalRibKind);
|
||||
let mut self_type_rib = Rib::new(RibKind::Normal);
|
||||
|
||||
// Plain insert (no renaming, since types are not currently hygienic)
|
||||
self_type_rib.bindings.insert(Ident::with_dummy_span(kw::SelfUpper), self_res);
|
||||
@ -2726,7 +2722,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
// If applicable, create a rib for the type parameters.
|
||||
self.with_generic_param_rib(
|
||||
&generics.params,
|
||||
RibKind::ItemRibKind(HasGenericParams::Yes(generics.span)),
|
||||
RibKind::Item(HasGenericParams::Yes(generics.span)),
|
||||
LifetimeRibKind::Generics {
|
||||
span: generics.span,
|
||||
binder: item_id,
|
||||
@ -2840,7 +2836,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
// We also need a new scope for the impl item type parameters.
|
||||
self.with_generic_param_rib(
|
||||
&generics.params,
|
||||
RibKind::AssocItemRibKind,
|
||||
RibKind::AssocItem,
|
||||
LifetimeRibKind::Generics {
|
||||
binder: item.id,
|
||||
span: generics.span,
|
||||
@ -2868,7 +2864,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
// We also need a new scope for the impl item type parameters.
|
||||
self.with_generic_param_rib(
|
||||
&generics.params,
|
||||
RibKind::AssocItemRibKind,
|
||||
RibKind::AssocItem,
|
||||
LifetimeRibKind::Generics {
|
||||
binder: item.id,
|
||||
span: generics.span,
|
||||
@ -3140,7 +3136,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
}
|
||||
|
||||
fn resolve_arm(&mut self, arm: &'ast Arm) {
|
||||
self.with_rib(ValueNS, RibKind::NormalRibKind, |this| {
|
||||
self.with_rib(ValueNS, RibKind::Normal, |this| {
|
||||
this.resolve_pattern_top(&arm.pat, PatternSource::Match);
|
||||
walk_list!(this, visit_expr, &arm.guard);
|
||||
this.visit_expr(&arm.body);
|
||||
@ -3862,7 +3858,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
diagnostics::signal_label_shadowing(self.r.tcx.sess, orig_span, label.ident)
|
||||
}
|
||||
|
||||
self.with_label_rib(RibKind::NormalRibKind, |this| {
|
||||
self.with_label_rib(RibKind::Normal, |this| {
|
||||
let ident = label.ident.normalize_to_macro_rules();
|
||||
this.label_ribs.last_mut().unwrap().bindings.insert(ident, id);
|
||||
f(this);
|
||||
@ -3885,11 +3881,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
let mut num_macro_definition_ribs = 0;
|
||||
if let Some(anonymous_module) = anonymous_module {
|
||||
debug!("(resolving block) found anonymous module, moving down");
|
||||
self.ribs[ValueNS].push(Rib::new(RibKind::ModuleRibKind(anonymous_module)));
|
||||
self.ribs[TypeNS].push(Rib::new(RibKind::ModuleRibKind(anonymous_module)));
|
||||
self.ribs[ValueNS].push(Rib::new(RibKind::Module(anonymous_module)));
|
||||
self.ribs[TypeNS].push(Rib::new(RibKind::Module(anonymous_module)));
|
||||
self.parent_scope.module = anonymous_module;
|
||||
} else {
|
||||
self.ribs[ValueNS].push(Rib::new(RibKind::NormalRibKind));
|
||||
self.ribs[ValueNS].push(Rib::new(RibKind::Normal));
|
||||
}
|
||||
|
||||
let prev = self.diagnostic_metadata.current_block_could_be_bare_struct_literal.take();
|
||||
@ -3994,7 +3990,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
}
|
||||
|
||||
ExprKind::If(ref cond, ref then, ref opt_else) => {
|
||||
self.with_rib(ValueNS, RibKind::NormalRibKind, |this| {
|
||||
self.with_rib(ValueNS, RibKind::Normal, |this| {
|
||||
let old = this.diagnostic_metadata.in_if_condition.replace(cond);
|
||||
this.visit_expr(cond);
|
||||
this.diagnostic_metadata.in_if_condition = old;
|
||||
@ -4011,7 +4007,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
|
||||
ExprKind::While(ref cond, ref block, label) => {
|
||||
self.with_resolved_label(label, expr.id, |this| {
|
||||
this.with_rib(ValueNS, RibKind::NormalRibKind, |this| {
|
||||
this.with_rib(ValueNS, RibKind::Normal, |this| {
|
||||
let old = this.diagnostic_metadata.in_if_condition.replace(cond);
|
||||
this.visit_expr(cond);
|
||||
this.diagnostic_metadata.in_if_condition = old;
|
||||
@ -4022,7 +4018,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
|
||||
ExprKind::ForLoop(ref pat, ref iter_expr, ref block, label) => {
|
||||
self.visit_expr(iter_expr);
|
||||
self.with_rib(ValueNS, RibKind::NormalRibKind, |this| {
|
||||
self.with_rib(ValueNS, RibKind::Normal, |this| {
|
||||
this.resolve_pattern_top(pat, PatternSource::For);
|
||||
this.resolve_labeled_block(label, expr.id, block);
|
||||
});
|
||||
@ -4087,8 +4083,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
ref body,
|
||||
..
|
||||
}) => {
|
||||
self.with_rib(ValueNS, RibKind::NormalRibKind, |this| {
|
||||
this.with_label_rib(RibKind::ClosureOrAsyncRibKind, |this| {
|
||||
self.with_rib(ValueNS, RibKind::Normal, |this| {
|
||||
this.with_label_rib(RibKind::ClosureOrAsync, |this| {
|
||||
// Resolve arguments:
|
||||
this.resolve_params(&fn_decl.inputs);
|
||||
// No need to resolve return type --
|
||||
@ -4112,7 +4108,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
}) => {
|
||||
self.with_generic_param_rib(
|
||||
&generic_params,
|
||||
RibKind::NormalRibKind,
|
||||
RibKind::Normal,
|
||||
LifetimeRibKind::Generics {
|
||||
binder: expr.id,
|
||||
kind: LifetimeBinderKind::Closure,
|
||||
@ -4123,9 +4119,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
}
|
||||
ExprKind::Closure(..) => visit::walk_expr(self, expr),
|
||||
ExprKind::Async(..) => {
|
||||
self.with_label_rib(RibKind::ClosureOrAsyncRibKind, |this| {
|
||||
visit::walk_expr(this, expr)
|
||||
});
|
||||
self.with_label_rib(RibKind::ClosureOrAsync, |this| visit::walk_expr(this, expr));
|
||||
}
|
||||
ExprKind::Repeat(ref elem, ref ct) => {
|
||||
self.visit_expr(elem);
|
||||
|
@ -623,7 +623,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||
}
|
||||
|
||||
// Try to find in last block rib
|
||||
if let Some(rib) = &self.last_block_rib && let RibKind::NormalRibKind = rib.kind {
|
||||
if let Some(rib) = &self.last_block_rib && let RibKind::Normal = rib.kind {
|
||||
for (ident, &res) in &rib.bindings {
|
||||
if let Res::Local(_) = res && path.len() == 1 &&
|
||||
ident.span.eq_ctxt(path[0].ident.span) &&
|
||||
@ -1728,7 +1728,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||
}
|
||||
|
||||
// Items in scope
|
||||
if let RibKind::ModuleRibKind(module) = rib.kind {
|
||||
if let RibKind::Module(module) = rib.kind {
|
||||
// Items from this module
|
||||
self.r.add_module_candidates(module, &mut names, &filter_fn, Some(ctxt));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user