about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2017-01-03 00:36:34 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2017-01-04 08:03:23 +0000
commit927408d9c5d4771232e908f2cf4d312ccf0535bd (patch)
tree17a146cbb90f87bfae5ca7d54c4934e9b8d90f85
parentd3a2efa14b5da1fb11eb25496232bb164238d3c2 (diff)
downloadrust-927408d9c5d4771232e908f2cf4d312ccf0535bd.tar.gz
rust-927408d9c5d4771232e908f2cf4d312ccf0535bd.zip
Fix regression with duplicate `#[macro_export] macro_rules!`.
-rw-r--r--src/librustc_resolve/resolve_imports.rs8
-rw-r--r--src/test/run-pass/auxiliary/issue_38715.rs15
-rw-r--r--src/test/run-pass/issue-38715.rs20
3 files changed, 42 insertions, 1 deletions
diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs
index 41d8f16b88d..91197e53d3c 100644
--- a/src/librustc_resolve/resolve_imports.rs
+++ b/src/librustc_resolve/resolve_imports.rs
@@ -21,6 +21,7 @@ use rustc::ty;
 use rustc::lint::builtin::PRIVATE_IN_PUBLIC;
 use rustc::hir::def_id::DefId;
 use rustc::hir::def::*;
+use rustc::util::nodemap::FxHashSet;
 
 use syntax::ast::{Ident, NodeId};
 use syntax::ext::base::Determinacy::{self, Determined, Undetermined};
@@ -728,7 +729,12 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
 
         let mut reexports = Vec::new();
         if module as *const _ == self.graph_root as *const _ {
-            reexports = mem::replace(&mut self.macro_exports, Vec::new());
+            let mut exported_macro_names = FxHashSet();
+            for export in mem::replace(&mut self.macro_exports, Vec::new()).into_iter().rev() {
+                if exported_macro_names.insert(export.name) {
+                    reexports.push(export);
+                }
+            }
         }
 
         for (&(ident, ns), resolution) in module.resolutions.borrow().iter() {
diff --git a/src/test/run-pass/auxiliary/issue_38715.rs b/src/test/run-pass/auxiliary/issue_38715.rs
new file mode 100644
index 00000000000..cad3996eadb
--- /dev/null
+++ b/src/test/run-pass/auxiliary/issue_38715.rs
@@ -0,0 +1,15 @@
+// Copyright 2016 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.
+
+#[macro_export]
+macro_rules! foo { ($i:ident) => {} }
+
+#[macro_export]
+macro_rules! foo { () => {} }
diff --git a/src/test/run-pass/issue-38715.rs b/src/test/run-pass/issue-38715.rs
new file mode 100644
index 00000000000..054785e62b8
--- /dev/null
+++ b/src/test/run-pass/issue-38715.rs
@@ -0,0 +1,20 @@
+// Copyright 2016 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.
+
+// aux-build:issue_38715.rs
+
+// Test that `#[macro_export] macro_rules!` shadow earlier `#[macro_export] macro_rules!`
+
+#[macro_use]
+extern crate issue_38715;
+
+fn main() {
+    foo!();
+}