Skip to content

Commit 2e5e91b

Browse files
author
Keegan McAllister
committed
---
yaml --- r: 171983 b: refs/heads/beta c: 0816255 h: refs/heads/master i: 171981: f1ee613 171979: daf4011 171975: 175816e 171967: 65c0517 v: v3
1 parent e3a4bde commit 2e5e91b

File tree

14 files changed

+54
-72
lines changed

14 files changed

+54
-72
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3131
refs/heads/issue-18208-method-dispatch-3-quick-reject: 2009f85b9f99dedcec4404418eda9ddba90258a2
3232
refs/heads/batch: b5571ed71a5879c0495a982506258d5d267744ed
3333
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
34-
refs/heads/beta: 60be2f52d2434dfbf2df7728454d572d76f58bf8
34+
refs/heads/beta: 0816255c80ee3f2a8870ee5e4379e3739d8ed72e
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ 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
555556
body: body,
556557
});
557558
true

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ use plugin::registry::Registry;
1717
use std::mem;
1818
use std::os;
1919
use std::dynamic_lib::DynamicLibrary;
20+
use std::collections::HashSet;
2021
use syntax::ast;
2122
use syntax::attr;
23+
use syntax::parse::token;
2224
use syntax::visit;
2325
use syntax::visit::Visitor;
2426
use syntax::attr::AttrMetaMethods;
@@ -87,6 +89,7 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> {
8789
// Parse the attributes relating to macro / plugin loading.
8890
let mut load_macros = false;
8991
let mut load_registrar = false;
92+
let mut reexport = HashSet::new();
9093
for attr in vi.attrs.iter() {
9194
let mut used = true;
9295
match attr.name().get() {
@@ -96,6 +99,23 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> {
9699
}
97100
"plugin" => load_registrar = true,
98101
"macro_use" => load_macros = true,
102+
"macro_reexport" => {
103+
let names = match attr.meta_item_list() {
104+
Some(names) => names,
105+
None => {
106+
self.sess.span_err(attr.span, "bad macro reexport");
107+
continue;
108+
}
109+
};
110+
111+
for name in names.iter() {
112+
if let ast::MetaWord(ref name) = name.node {
113+
reexport.insert(name.clone());
114+
} else {
115+
self.sess.span_err(name.span, "bad macro reexport");
116+
}
117+
}
118+
}
99119
_ => used = false,
100120
}
101121
if used {
@@ -116,7 +136,13 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> {
116136
}
117137
}
118138

119-
self.plugins.macros.extend(macros.into_iter());
139+
for mut def in macros.into_iter() {
140+
if reexport.contains(&token::get_ident(def.ident)) {
141+
def.export = true;
142+
}
143+
self.plugins.macros.push(def);
144+
}
145+
120146
if let Some((lib, symbol)) = registrar {
121147
self.dylink_registrar(vi, lib, symbol);
122148
}

branches/beta/src/librustc_driver/driver.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,6 @@ pub fn phase_2_configure_and_expand(sess: &Session,
275275
deriving_hash_type_parameter: sess.features.borrow().default_type_params,
276276
enable_quotes: sess.features.borrow().quote,
277277
recursion_limit: sess.recursion_limit.get(),
278-
reexported_macros: syntax::ext::tt::reexport::gather(sess.diagnostic(),
279-
&krate),
280278
};
281279
let ret = syntax::ext::expand::expand_crate(&sess.parse_sess,
282280
cfg,

branches/beta/src/libstd/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@
117117

118118
#![reexport_test_harness_main = "test_main"]
119119

120-
#![macro_reexport(assert, assert_eq, debug_assert, debug_assert_eq,
121-
unreachable, unimplemented, write, writeln, vec)]
122-
123120
#[cfg(all(test, stage0))]
124121
#[phase(plugin, link)]
125122
extern crate log;
@@ -134,6 +131,8 @@ extern crate core;
134131

135132
#[cfg(not(stage0))]
136133
#[macro_use]
134+
#[macro_reexport(assert, assert_eq, debug_assert, debug_assert_eq,
135+
unreachable, unimplemented, write, writeln)]
137136
extern crate core;
138137

139138
#[cfg(stage0)]
@@ -142,6 +141,7 @@ extern crate "collections" as core_collections;
142141

143142
#[cfg(not(stage0))]
144143
#[macro_use]
144+
#[macro_reexport(vec)]
145145
extern crate "collections" as core_collections;
146146

147147
extern crate "rand" as core_rand;

branches/beta/src/libsyntax/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,7 @@ pub struct MacroDef {
17081708
pub id: NodeId,
17091709
pub span: Span,
17101710
pub imported_from: Option<Ident>,
1711+
pub export: bool,
17111712
pub body: Vec<TokenTree>,
17121713
}
17131714

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use codemap;
1616
use codemap::{CodeMap, Span, ExpnId, ExpnInfo, NO_EXPANSION};
1717
use ext;
1818
use ext::expand;
19+
use ext::tt::macro_rules;
1920
use parse;
2021
use parse::parser;
2122
use parse::token;
@@ -568,6 +569,15 @@ impl<'a> ExtCtxt<'a> {
568569
}
569570
}
570571
}
572+
573+
pub fn insert_macro(&mut self, def: ast::MacroDef) {
574+
if def.export {
575+
self.exported_macros.push(def.clone());
576+
}
577+
let ext = macro_rules::compile(self, &def);
578+
self.syntax_env.insert(def.ident.name, ext);
579+
}
580+
571581
/// Emit `msg` attached to `sp`, and stop compilation immediately.
572582
///
573583
/// `span_err` should be strongly preferred where-ever possible:

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

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use ast;
1717
use ast_util::path_to_ident;
1818
use ext::mtwt;
1919
use ext::build::AstBuilder;
20-
use ext::tt::macro_rules;
2120
use attr;
2221
use attr::AttrMetaMethods;
2322
use codemap;
@@ -636,14 +635,10 @@ pub fn expand_item_mac(it: P<ast::Item>,
636635
id: ast::DUMMY_NODE_ID,
637636
span: it.span,
638637
imported_from: None,
638+
export: attr::contains_name(it.attrs.as_slice(), "macro_export"),
639639
body: tts,
640640
};
641-
let ext = macro_rules::compile(fld.cx, &def);
642-
fld.cx.syntax_env.insert(def.ident.name, ext);
643-
644-
if attr::contains_name(def.attrs.as_slice(), "macro_export") {
645-
fld.cx.exported_macros.push(def);
646-
}
641+
fld.cx.insert_macro(def);
647642

648643
// macro_rules! has a side effect but expands to nothing.
649644
fld.cx.bt_pop();
@@ -1178,7 +1173,6 @@ pub struct ExpansionConfig {
11781173
pub deriving_hash_type_parameter: bool,
11791174
pub enable_quotes: bool,
11801175
pub recursion_limit: uint,
1181-
pub reexported_macros: Vec<String>,
11821176
}
11831177

11841178
impl ExpansionConfig {
@@ -1188,7 +1182,6 @@ impl ExpansionConfig {
11881182
deriving_hash_type_parameter: false,
11891183
enable_quotes: false,
11901184
recursion_limit: 64,
1191-
reexported_macros: vec![],
11921185
}
11931186
}
11941187
}
@@ -1202,15 +1195,8 @@ pub fn expand_crate(parse_sess: &parse::ParseSess,
12021195
let mut cx = ExtCtxt::new(parse_sess, c.config.clone(), cfg);
12031196
let mut expander = MacroExpander::new(&mut cx);
12041197

1205-
for def in imported_macros.iter() {
1206-
let ext = macro_rules::compile(expander.cx, def);
1207-
expander.cx.syntax_env.insert(def.ident.name, ext);
1208-
1209-
if expander.cx.ecfg.reexported_macros.iter()
1210-
.any(|e| e[] == token::get_ident(def.ident).get()) {
1211-
1212-
expander.cx.exported_macros.push(def.clone());
1213-
}
1198+
for def in imported_macros.into_iter() {
1199+
expander.cx.insert_macro(def);
12141200
}
12151201

12161202
for (name, extension) in user_exts.into_iter() {

branches/beta/src/libsyntax/ext/tt/reexport.rs

Lines changed: 0 additions & 41 deletions
This file was deleted.

branches/beta/src/libsyntax/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,5 @@ pub mod ext {
111111
pub mod transcribe;
112112
pub mod macro_parser;
113113
pub mod macro_rules;
114-
pub mod reexport;
115114
}
116115
}

branches/beta/src/test/auxiliary/macro_reexport_2.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#![crate_type = "dylib"]
1212

13-
#![macro_reexport(reexported)]
14-
13+
#[macro_reexport(reexported)]
1514
#[macro_use] #[no_link]
1615
extern crate macro_reexport_1;

branches/beta/src/test/compile-fail/macro-reexport-malformed-1.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![macro_reexport] //~ ERROR malformed macro_reexport attribute
11+
#[macro_reexport] //~ ERROR bad macro reexport
12+
extern crate std;
1213

1314
fn main() { }

branches/beta/src/test/compile-fail/macro-reexport-malformed-2.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![macro_reexport="foo"] //~ ERROR malformed macro_reexport attribute
11+
#[macro_reexport="foo"] //~ ERROR bad macro reexport
12+
extern crate std;
1213

1314
fn main() { }

branches/beta/src/test/compile-fail/macro-reexport-malformed-3.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![macro_reexport(foo="bar")] //~ ERROR malformed macro_reexport attribute
11+
#[macro_reexport(foo="bar")] //~ ERROR bad macro reexport
12+
extern crate std;
1213

1314
fn main() { }

0 commit comments

Comments
 (0)