]> git.lizzy.rs Git - rust.git/commitdiff
Ensure that macro resolutions in trait positions get finalized.
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Mon, 27 Mar 2017 05:22:18 +0000 (05:22 +0000)
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Mon, 27 Mar 2017 05:22:18 +0000 (05:22 +0000)
src/librustc_resolve/lib.rs
src/librustc_resolve/macros.rs
src/test/compile-fail/issue-40845.rs [new file with mode: 0644]

index 879d8816488b20e8a1e8fc420b4215ee59e986a2..0466e76475da3d1f05069ec0b24edccf45500de3 100644 (file)
@@ -922,6 +922,10 @@ fn is_trait(&self) -> bool {
     fn is_local(&self) -> bool {
         self.normal_ancestor_id.is_local()
     }
+
+    fn nearest_item_scope(&'a self) -> Module<'a> {
+        if self.is_trait() { self.parent.unwrap() } else { self }
+    }
 }
 
 impl<'a> fmt::Debug for ModuleData<'a> {
index 3d6c6896549a4bb8f5996bc7615526b73218f41e..05f30f039c8f0649dd3eaf3bab6fc28c909219ee 100644 (file)
@@ -172,7 +172,6 @@ fn visit_expansion(&mut self, mark: Mark, expansion: &Expansion, derives: &[Mark
             expansion: mark,
         };
         expansion.visit_with(&mut visitor);
-        self.current_module.unresolved_invocations.borrow_mut().remove(&mark);
         invocation.expansion.set(visitor.legacy_scope);
     }
 
@@ -390,7 +389,7 @@ fn resolve_macro_to_def(&mut self, scope: Mark, path: &ast::Path, kind: MacroKin
                     Err(Determinacy::Determined)
                 },
             };
-            self.current_module.macro_resolutions.borrow_mut()
+            self.current_module.nearest_item_scope().macro_resolutions.borrow_mut()
                 .push((path.into_boxed_slice(), span));
             return def;
         }
@@ -410,7 +409,7 @@ fn resolve_macro_to_def(&mut self, scope: Mark, path: &ast::Path, kind: MacroKin
             }
         };
 
-        self.current_module.legacy_macro_resolutions.borrow_mut()
+        self.current_module.nearest_item_scope().legacy_macro_resolutions.borrow_mut()
             .push((scope, path[0], span, kind));
 
         result
diff --git a/src/test/compile-fail/issue-40845.rs b/src/test/compile-fail/issue-40845.rs
new file mode 100644 (file)
index 0000000..c5604a0
--- /dev/null
@@ -0,0 +1,16 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+trait T { m!(); } //~ ERROR cannot find macro `m!` in this scope
+
+struct S;
+impl S { m!(); } //~ ERROR cannot find macro `m!` in this scope
+
+fn main() {}