Skip to content

Commit fafa0b2

Browse files
author
Keegan McAllister
committed
---
yaml --- r: 170879 b: refs/heads/try c: 5382881 h: refs/heads/master i: 170877: 444ff33 170875: d56f54b 170871: 1192857 170863: e570f98 170847: 6a7e903 170815: c787ae5 170751: 0924e0c v: v3
1 parent 5aa21c1 commit fafa0b2

File tree

11 files changed

+148
-2
lines changed

11 files changed

+148
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 73a25f55ad748b4d3516417c711b99ce446591af
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 5b3cd3900ceda838f5798c30ab96ceb41f962534
5-
refs/heads/try: e2a9c04e192926fde1a8e886b55e4c2b6e0e56cb
5+
refs/heads/try: 538288176a22b4d3755df085783f84d476386019
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/librustc_driver/driver.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ 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),
278280
};
279281
let ret = syntax::ext::expand::expand_crate(&sess.parse_sess,
280282
cfg,

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,12 @@ pub fn expand_item_mac(it: P<ast::Item>,
616616
imported_from, tts);
617617

618618
fld.cx.syntax_env.insert(intern(name.as_slice()), ext);
619-
if attr::contains_name(it.attrs.as_slice(), "macro_export") {
619+
620+
if match imported_from {
621+
None => attr::contains_name(it.attrs.as_slice(), "macro_export"),
622+
Some(_) => fld.cx.ecfg.reexported_macros.iter()
623+
.any(|e| e.as_slice() == name.as_slice()),
624+
} {
620625
fld.cx.exported_macros.push(it);
621626
}
622627

@@ -1156,6 +1161,7 @@ pub struct ExpansionConfig {
11561161
pub deriving_hash_type_parameter: bool,
11571162
pub enable_quotes: bool,
11581163
pub recursion_limit: uint,
1164+
pub reexported_macros: Vec<String>,
11591165
}
11601166

11611167
impl ExpansionConfig {
@@ -1165,6 +1171,7 @@ impl ExpansionConfig {
11651171
deriving_hash_type_parameter: false,
11661172
enable_quotes: false,
11671173
recursion_limit: 64,
1174+
reexported_macros: vec![],
11681175
}
11691176
}
11701177
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2014 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+
//! Defines the crate attribute syntax for macro re-export.
12+
13+
use ast;
14+
use attr::AttrMetaMethods;
15+
use diagnostic::SpanHandler;
16+
17+
/// Return a vector of the names of all macros re-exported from the crate.
18+
pub fn gather(diag: &SpanHandler, krate: &ast::Crate) -> Vec<String> {
19+
let usage = "malformed macro_reexport attribute, expected \
20+
#![macro_reexport(ident, ident, ...)]";
21+
22+
let mut reexported: Vec<String> = vec!();
23+
for attr in krate.attrs.iter() {
24+
if !attr.check_name("macro_reexport") {
25+
continue;
26+
}
27+
28+
match attr.meta_item_list() {
29+
None => diag.span_err(attr.span, usage),
30+
Some(list) => for mi in list.iter() {
31+
match mi.node {
32+
ast::MetaWord(ref word)
33+
=> reexported.push(word.to_string()),
34+
_ => diag.span_err(mi.span, usage),
35+
}
36+
}
37+
}
38+
}
39+
40+
reexported
41+
}

branches/try/src/libsyntax/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,6 @@ pub mod ext {
104104
pub mod transcribe;
105105
pub mod macro_parser;
106106
pub mod macro_rules;
107+
pub mod reexport;
107108
}
108109
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2014 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+
#![feature(macro_rules)]
13+
14+
#[macro_export]
15+
macro_rules! reexported {
16+
() => ( 3u )
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2014 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+
#![feature(phase)]
13+
14+
#![macro_reexport(reexported)]
15+
16+
#[phase(plugin)]
17+
extern crate macro_reexport_1;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2014 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_reexport] //~ ERROR malformed macro_reexport attribute
12+
13+
fn main() { }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2014 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_reexport="foo"] //~ ERROR malformed macro_reexport attribute
12+
13+
fn main() { }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2014 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_reexport(foo="bar")] //~ ERROR malformed macro_reexport attribute
12+
13+
fn main() { }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2014 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.rs
13+
// ignore-stage1
14+
15+
#![feature(phase)]
16+
17+
#[phase(plugin)]
18+
extern crate macro_reexport_2;
19+
20+
fn main() {
21+
assert_eq!(reexported!(), 3u);
22+
}

0 commit comments

Comments
 (0)