Skip to content

Commit 2d32335

Browse files
jseyfriednikomatsakis
authored andcommitted
Fix regression with duplicate #[macro_export] macro_rules!.
1 parent a0fba3e commit 2d32335

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

src/librustc_resolve/resolve_imports.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use {resolve_error, ResolutionError};
2020
use rustc::ty;
2121
use rustc::lint::builtin::PRIVATE_IN_PUBLIC;
2222
use rustc::hir::def::*;
23+
use rustc::util::nodemap::FxHashSet;
2324

2425
use syntax::ast::{Ident, NodeId, Name};
2526
use syntax::ext::base::Determinacy::{self, Determined, Undetermined};
@@ -723,7 +724,12 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
723724

724725
let mut reexports = Vec::new();
725726
if module as *const _ == self.graph_root as *const _ {
726-
reexports = mem::replace(&mut self.macro_exports, Vec::new());
727+
let mut exported_macro_names = FxHashSet();
728+
for export in mem::replace(&mut self.macro_exports, Vec::new()).into_iter().rev() {
729+
if exported_macro_names.insert(export.name) {
730+
reexports.push(export);
731+
}
732+
}
727733
}
728734

729735
for (&(name, ns), resolution) in module.resolutions.borrow().iter() {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[macro_export]
12+
macro_rules! foo { ($i:ident) => {} }
13+
14+
#[macro_export]
15+
macro_rules! foo { () => {} }

src/test/run-pass/issue-38715.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:issue_38715.rs
12+
13+
// Test that `#[macro_export] macro_rules!` shadow earlier `#[macro_export] macro_rules!`
14+
15+
#[macro_use]
16+
extern crate issue_38715;
17+
18+
fn main() {
19+
foo!();
20+
}

0 commit comments

Comments
 (0)