resolve: Do not "normalize away" trait/enum modules prematurely
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.
This commit is contained in:
parent
23b82c3229
commit
cfbb60bf6d
2 changed files with 6 additions and 4 deletions
|
|
@ -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 {
|
||||
|
|
@ -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 => {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue