Skip to content

Commit e7907a9

Browse files
committed
Auto merge of #38793 - jseyfried:fix_macro_export_duplicates, r=nrc
Fix regression with duplicate `#[macro_export] macro_rules!` Fixes #38715. r? @nrc
2 parents 6f1ae66 + 927408d commit e7907a9

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

src/librustc_resolve/resolve_imports.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rustc::ty;
2121
use rustc::lint::builtin::PRIVATE_IN_PUBLIC;
2222
use rustc::hir::def_id::DefId;
2323
use rustc::hir::def::*;
24+
use rustc::util::nodemap::FxHashSet;
2425

2526
use syntax::ast::{Ident, NodeId};
2627
use syntax::ext::base::Determinacy::{self, Determined, Undetermined};
@@ -728,7 +729,12 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
728729

729730
let mut reexports = Vec::new();
730731
if module as *const _ == self.graph_root as *const _ {
731-
reexports = mem::replace(&mut self.macro_exports, Vec::new());
732+
let mut exported_macro_names = FxHashSet();
733+
for export in mem::replace(&mut self.macro_exports, Vec::new()).into_iter().rev() {
734+
if exported_macro_names.insert(export.name) {
735+
reexports.push(export);
736+
}
737+
}
732738
}
733739

734740
for (&(ident, ns), resolution) in module.resolutions.borrow().iter() {
+15
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

+20
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)