Skip to content

Commit cfbb60b

Browse files
committed
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.
1 parent 23b82c3 commit cfbb60b

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/librustc_resolve/lib.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1321,13 +1321,15 @@ impl<'a> Resolver<'a> {
13211321
ScopeSet::AbsolutePath(ns) => (ns, true),
13221322
ScopeSet::Macro(_) => (MacroNS, false),
13231323
};
1324+
// Jump out of trait or enum modules, they do not act as scopes.
1325+
let module = parent_scope.module.nearest_item_scope();
13241326
let mut scope = match ns {
13251327
_ if is_absolute_path => Scope::CrateRoot,
1326-
TypeNS | ValueNS => Scope::Module(parent_scope.module),
1328+
TypeNS | ValueNS => Scope::Module(module),
13271329
MacroNS => Scope::DeriveHelpers,
13281330
};
13291331
let mut ident = ident.modern();
1330-
let mut use_prelude = !parent_scope.module.no_implicit_prelude;
1332+
let mut use_prelude = !module.no_implicit_prelude;
13311333

13321334
loop {
13331335
let visit = match scope {
@@ -1360,7 +1362,7 @@ impl<'a> Resolver<'a> {
13601362
LegacyScope::Invocation(invoc) => Scope::MacroRules(
13611363
invoc.output_legacy_scope.get().unwrap_or(invoc.parent_legacy_scope)
13621364
),
1363-
LegacyScope::Empty => Scope::Module(parent_scope.module),
1365+
LegacyScope::Empty => Scope::Module(module),
13641366
}
13651367
Scope::CrateRoot => match ns {
13661368
TypeNS => {

src/librustc_resolve/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl<'a> Resolver<'a> {
258258
fn invoc_parent_scope(&self, invoc_id: ExpnId, derives: Vec<ast::Path>) -> ParentScope<'a> {
259259
let invoc = self.invocations[&invoc_id];
260260
ParentScope {
261-
module: invoc.module.nearest_item_scope(),
261+
module: invoc.module,
262262
expansion: invoc_id.parent(),
263263
legacy: invoc.parent_legacy_scope,
264264
derives,

0 commit comments

Comments
 (0)