Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/rustc_resolve/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

module = match rib.kind {
RibKind::Module(module) => module,
RibKind::Block { module } if let Some(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.
Expand Down Expand Up @@ -1149,6 +1150,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
RibKind::Normal
| RibKind::FnOrCoroutine
| RibKind::Module(..)
| RibKind::Block { .. }
| RibKind::MacroDefinition(..)
| RibKind::ForwardGenericParamBan(_) => {
// Nothing to do. Continue.
Expand Down Expand Up @@ -1241,6 +1243,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
RibKind::Normal
| RibKind::FnOrCoroutine
| RibKind::Module(..)
| RibKind::Block { .. }
| RibKind::MacroDefinition(..)
| RibKind::InlineAsmSym
| RibKind::AssocItem
Expand Down Expand Up @@ -1334,6 +1337,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
RibKind::Normal
| RibKind::FnOrCoroutine
| RibKind::Module(..)
| RibKind::Block { .. }
| RibKind::MacroDefinition(..)
| RibKind::InlineAsmSym
| RibKind::AssocItem
Expand Down
21 changes: 16 additions & 5 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ pub(crate) enum RibKind<'ra> {
/// All other constants aren't allowed to use generic params at all.
ConstantItem(ConstantHasGenerics, Option<(Ident, ConstantItemKind)>),

Block {
module: Option<Module<'ra>>,
},

/// We passed through a module.
Module(Module<'ra>),

Expand Down Expand Up @@ -243,6 +247,7 @@ impl RibKind<'_> {
pub(crate) fn contains_params(&self) -> bool {
match self {
RibKind::Normal
| RibKind::Block { .. }
| RibKind::FnOrCoroutine
| RibKind::ConstantItem(..)
| RibKind::Module(_)
Expand All @@ -258,13 +263,16 @@ impl RibKind<'_> {
/// This rib forbids referring to labels defined in upwards ribs.
fn is_label_barrier(self) -> bool {
match self {
RibKind::Normal | RibKind::MacroDefinition(..) => false,
RibKind::Normal | RibKind::MacroDefinition(..) | RibKind::Block { module: None } => {
false
}

RibKind::AssocItem
| RibKind::FnOrCoroutine
| RibKind::Item(..)
| RibKind::ConstantItem(..)
| RibKind::Module(..)
| RibKind::Block { module: Some(_) }
| RibKind::ForwardGenericParamBan(_)
| RibKind::ConstParamTy
| RibKind::InlineAsmSym => true,
Expand Down Expand Up @@ -2822,7 +2830,10 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
for parent_rib in self.ribs[ns].iter().rev() {
// Break at mod level, to account for nested items which are
// allowed to shadow generic param names.
if matches!(parent_rib.kind, RibKind::Module(..)) {
if matches!(
parent_rib.kind,
RibKind::Module(..) | RibKind::Block { module: Some(_) }
) {
break;
}

Expand Down Expand Up @@ -4662,11 +4673,11 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, '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::Module(anonymous_module)));
self.ribs[TypeNS].push(Rib::new(RibKind::Module(anonymous_module)));
self.ribs[ValueNS].push(Rib::new(RibKind::Block { module: Some(anonymous_module) }));
self.ribs[TypeNS].push(Rib::new(RibKind::Block { module: Some(anonymous_module) }));
self.parent_scope.module = anonymous_module;
} else {
self.ribs[ValueNS].push(Rib::new(RibKind::Normal));
self.ribs[ValueNS].push(Rib::new(RibKind::Block { module: None }));
}

// Descend into the block.
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {

// Try to find in last block rib
if let Some(rib) = &self.last_block_rib
&& let RibKind::Normal = rib.kind
&& let RibKind::Block { module: None } = rib.kind
{
for (ident, &res) in &rib.bindings {
if let Res::Local(_) = res
Expand Down Expand Up @@ -2467,7 +2467,8 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
}

// Items in scope
if let RibKind::Module(module) = rib.kind {
if let RibKind::Module(module) | RibKind::Block { module: Some(module) } = rib.kind
{
// Items from this module
self.r.add_module_candidates(module, &mut names, &filter_fn, Some(ctxt));

Expand Down
Loading