about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-08-12 21:55:42 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-08-15 20:39:27 +0300
commitcfbb60bf6d83fbcfcca1f2919131aa39fb997b53 (patch)
treec7d3183678416be345c6f8ef000b7af68dfcdc0b /src
parent23b82c32298002f80724a244c2483fd1e8ec1d54 (diff)
downloadrust-cfbb60bf6d83fbcfcca1f2919131aa39fb997b53.tar.gz
rust-cfbb60bf6d83fbcfcca1f2919131aa39fb997b53.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_resolve/lib.rs8
-rw-r--r--src/librustc_resolve/macros.rs2
2 files changed, 6 insertions, 4 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index 3d82ef3d580..6bb2cd03770 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -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 => {
diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs
index f54f395063c..6d882a6e194 100644
--- a/src/librustc_resolve/macros.rs
+++ b/src/librustc_resolve/macros.rs
@@ -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,