Skip to content

Commit

Permalink
resolve: Do not "normalize away" trait/enum modules prematurely
Browse files Browse the repository at this point in the history
The previous approach was brittle - what would happen if `ParentScope` wasn't created by `invoc_parent_scope`?
That's exactly the case for various uses of `ParentScope` in diagnostics and in built-in attribute validation.
  • Loading branch information
petrochenkov committed Aug 15, 2019
1 parent 23b82c3 commit cfbb60b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/librustc_resolve/lib.rs
Expand Up @@ -1321,13 +1321,15 @@ impl<'a> Resolver<'a> {
ScopeSet::AbsolutePath(ns) => (ns, true),
ScopeSet::Macro(_) => (MacroNS, false),
};
// Jump out of trait or enum modules, they do not act as scopes.
let module = parent_scope.module.nearest_item_scope();
let mut scope = match ns {
_ if is_absolute_path => Scope::CrateRoot,
TypeNS | ValueNS => Scope::Module(parent_scope.module),
TypeNS | ValueNS => Scope::Module(module),
MacroNS => Scope::DeriveHelpers,
};
let mut ident = ident.modern();
let mut use_prelude = !parent_scope.module.no_implicit_prelude;
let mut use_prelude = !module.no_implicit_prelude;

loop {
let visit = match scope {
Expand Down Expand Up @@ -1360,7 +1362,7 @@ impl<'a> Resolver<'a> {
LegacyScope::Invocation(invoc) => Scope::MacroRules(
invoc.output_legacy_scope.get().unwrap_or(invoc.parent_legacy_scope)
),
LegacyScope::Empty => Scope::Module(parent_scope.module),
LegacyScope::Empty => Scope::Module(module),
}
Scope::CrateRoot => match ns {
TypeNS => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/macros.rs
Expand Up @@ -258,7 +258,7 @@ impl<'a> Resolver<'a> {
fn invoc_parent_scope(&self, invoc_id: ExpnId, derives: Vec<ast::Path>) -> ParentScope<'a> {
let invoc = self.invocations[&invoc_id];
ParentScope {
module: invoc.module.nearest_item_scope(),
module: invoc.module,
expansion: invoc_id.parent(),
legacy: invoc.parent_legacy_scope,
derives,
Expand Down

0 comments on commit cfbb60b

Please sign in to comment.