Skip to content

Commit bdb8547

Browse files
author
Keegan McAllister
committed
---
yaml --- r: 171389 b: refs/heads/batch c: aa69cbd h: refs/heads/master i: 171387: 36e258d v: v3
1 parent 56f71bb commit bdb8547

20 files changed

+300
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
2929
refs/heads/issue-18208-method-dispatch-2: 9e1eae4fb9b6527315b4441cf8a0f5ca911d1671
3030
refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3131
refs/heads/issue-18208-method-dispatch-3-quick-reject: 2009f85b9f99dedcec4404418eda9ddba90258a2
32-
refs/heads/batch: 0816255c80ee3f2a8870ee5e4379e3739d8ed72e
32+
refs/heads/batch: aa69cbde8279cd90457454c3b3f40a36e8a79dff
3333
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3434
refs/heads/beta: 496dc4eae7de9d14cd49511a9acfbf5f11ae6c3f
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928

branches/batch/src/librustc/metadata/creader.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,10 @@ impl<'a> PluginMetadata<'a> {
552552
id: ast::DUMMY_NODE_ID,
553553
span: span,
554554
imported_from: imported_from,
555-
export: false, // overridden in plugin/load.rs
555+
// overridden in plugin/load.rs
556+
export: false,
557+
use_locally: false,
558+
556559
body: body,
557560
});
558561
true

branches/batch/src/librustc/plugin/load.rs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> {
8787
}
8888

8989
// Parse the attributes relating to macro / plugin loading.
90-
let mut load_macros = false;
9190
let mut load_registrar = false;
91+
let mut macro_selection = Some(HashSet::new()); // None => load all
9292
let mut reexport = HashSet::new();
9393
for attr in vi.attrs.iter() {
9494
let mut used = true;
@@ -98,7 +98,22 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> {
9898
#[macro_use], #[plugin], and/or #[no_link]");
9999
}
100100
"plugin" => load_registrar = true,
101-
"macro_use" => load_macros = true,
101+
"macro_use" => {
102+
let names = attr.meta_item_list();
103+
if names.is_none() {
104+
// no names => load all
105+
macro_selection = None;
106+
}
107+
if let (Some(sel), Some(names)) = (macro_selection.as_mut(), names) {
108+
for name in names.iter() {
109+
if let ast::MetaWord(ref name) = name.node {
110+
sel.insert(name.clone());
111+
} else {
112+
self.sess.span_err(name.span, "bad macro import");
113+
}
114+
}
115+
}
116+
}
102117
"macro_reexport" => {
103118
let names = match attr.meta_item_list() {
104119
Some(names) => names,
@@ -126,6 +141,11 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> {
126141
let mut macros = vec![];
127142
let mut registrar = None;
128143

144+
let load_macros = match macro_selection.as_ref() {
145+
Some(sel) => sel.len() != 0 || reexport.len() != 0,
146+
None => true,
147+
};
148+
129149
if load_macros || load_registrar {
130150
let pmd = self.reader.read_plugin_metadata(vi);
131151
if load_macros {
@@ -137,9 +157,12 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> {
137157
}
138158

139159
for mut def in macros.into_iter() {
140-
if reexport.contains(&token::get_ident(def.ident)) {
141-
def.export = true;
142-
}
160+
let name = token::get_ident(def.ident);
161+
def.use_locally = match macro_selection.as_ref() {
162+
None => true,
163+
Some(sel) => sel.contains(&name),
164+
};
165+
def.export = reexport.contains(&name);
143166
self.plugins.macros.push(def);
144167
}
145168

branches/batch/src/libsyntax/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,6 +1709,7 @@ pub struct MacroDef {
17091709
pub span: Span,
17101710
pub imported_from: Option<Ident>,
17111711
pub export: bool,
1712+
pub use_locally: bool,
17121713
pub body: Vec<TokenTree>,
17131714
}
17141715

branches/batch/src/libsyntax/ext/base.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,10 @@ impl<'a> ExtCtxt<'a> {
574574
if def.export {
575575
self.exported_macros.push(def.clone());
576576
}
577-
let ext = macro_rules::compile(self, &def);
578-
self.syntax_env.insert(def.ident.name, ext);
577+
if def.use_locally {
578+
let ext = macro_rules::compile(self, &def);
579+
self.syntax_env.insert(def.ident.name, ext);
580+
}
579581
}
580582

581583
/// Emit `msg` attached to `sp`, and stop compilation immediately.

branches/batch/src/libsyntax/ext/expand.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ pub fn expand_item_mac(it: P<ast::Item>,
636636
span: it.span,
637637
imported_from: None,
638638
export: attr::contains_name(it.attrs.as_slice(), "macro_export"),
639+
use_locally: true,
639640
body: tts,
640641
};
641642
fld.cx.insert_macro(def);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2015 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+
#![crate_type = "dylib"]
12+
13+
#[macro_reexport(reexported)]
14+
#[no_link]
15+
extern crate macro_reexport_1;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 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+
// force-host
12+
13+
#![feature(macro_rules)]
14+
15+
#[macro_export]
16+
macro_rules! macro_one { () => ("one") }
17+
18+
#[macro_export]
19+
macro_rules! macro_two { () => ("two") }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 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:two_macros.rs
12+
// ignore-stage1
13+
14+
#[macro_use()]
15+
extern crate two_macros;
16+
17+
pub fn main() {
18+
macro_two!(); //~ ERROR macro undefined
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2015 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:macro_reexport_1.rs
12+
// ignore-stage1
13+
14+
#[macro_reexport(reexported)]
15+
#[no_link]
16+
extern crate macro_reexport_1;
17+
18+
fn main() {
19+
assert_eq!(reexported!(), 3u); //~ ERROR macro undefined
20+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2015 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_use(foo(bar))] //~ ERROR bad macro import
12+
extern crate std;
13+
14+
fn main() {
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2015 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_use(foo="bar")] //~ ERROR bad macro import
12+
extern crate std;
13+
14+
fn main() {
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 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:two_macros.rs
12+
// ignore-stage1
13+
14+
#[macro_use(macro_one)]
15+
extern crate two_macros;
16+
17+
pub fn main() {
18+
macro_two!(); //~ ERROR macro undefined
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2015 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:two_macros.rs
12+
// ignore-stage1
13+
14+
extern crate two_macros;
15+
16+
pub fn main() {
17+
macro_two!(); //~ ERROR macro undefined
18+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2015 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:macro_reexport_1.rs
12+
// aux-build:macro_reexport_2_no_use.rs
13+
// ignore-stage1
14+
15+
#[macro_use] #[no_link]
16+
extern crate macro_reexport_2_no_use;
17+
18+
fn main() {
19+
assert_eq!(reexported!(), 3u);
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2015 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:two_macros.rs
12+
// ignore-stage1
13+
14+
#[macro_use]
15+
#[macro_use()]
16+
extern crate two_macros;
17+
18+
pub fn main() {
19+
macro_one!();
20+
macro_two!();
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2015 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:two_macros.rs
12+
// ignore-stage1
13+
14+
#[macro_use]
15+
extern crate two_macros;
16+
17+
pub fn main() {
18+
macro_one!();
19+
macro_two!();
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2015 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:two_macros.rs
12+
// ignore-stage1
13+
14+
#[macro_use(macro_one, macro_two)]
15+
extern crate two_macros;
16+
17+
pub fn main() {
18+
macro_one!();
19+
macro_two!();
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 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:two_macros.rs
12+
// ignore-stage1
13+
14+
#[macro_use(macro_two)]
15+
extern crate two_macros;
16+
17+
pub fn main() {
18+
macro_two!();
19+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2015 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:two_macros.rs
12+
// ignore-stage1
13+
14+
#[macro_use(macro_one)]
15+
#[macro_use(macro_two)]
16+
extern crate two_macros;
17+
18+
pub fn main() {
19+
macro_one!();
20+
macro_two!();
21+
}

0 commit comments

Comments
 (0)