Skip to content

Commit 5bf385b

Browse files
author
Keegan McAllister
committed
Rename macro_escape to macro_use
In the future we want to support #[macro_use(foo, bar)] mod macros; but it's not an essential part of macro reform. Reserve the syntax for now.
1 parent fc58479 commit 5bf385b

File tree

18 files changed

+127
-43
lines changed

18 files changed

+127
-43
lines changed

src/libcollections/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ pub use vec_map::VecMap;
5454
// Needed for the vec! macro
5555
pub use alloc::boxed;
5656

57-
#[macro_escape]
57+
#[cfg_attr(stage0, macro_escape)]
58+
#[cfg_attr(not(stage0), macro_use)]
5859
mod macros;
5960

6061
pub mod binary_heap;

src/libcore/lib.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,23 @@
6262
#![feature(default_type_params, unboxed_closures, associated_types)]
6363
#![deny(missing_docs)]
6464

65-
#[macro_escape]
65+
#[cfg_attr(stage0, macro_escape)]
66+
#[cfg_attr(not(stage0), macro_use)]
6667
mod macros;
6768

6869
#[path = "num/float_macros.rs"]
69-
#[macro_escape]
70+
#[cfg_attr(stage0, macro_escape)]
71+
#[cfg_attr(not(stage0), macro_use)]
7072
mod float_macros;
7173

7274
#[path = "num/int_macros.rs"]
73-
#[macro_escape]
75+
#[cfg_attr(stage0, macro_escape)]
76+
#[cfg_attr(not(stage0), macro_use)]
7477
mod int_macros;
7578

7679
#[path = "num/uint_macros.rs"]
77-
#[macro_escape]
80+
#[cfg_attr(stage0, macro_escape)]
81+
#[cfg_attr(not(stage0), macro_use)]
7882
mod uint_macros;
7983

8084
#[path = "num/int.rs"] pub mod int;

src/libcoretest/num/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use core::num::{NumCast, cast};
1414
use core::ops::{Add, Sub, Mul, Div, Rem};
1515
use core::kinds::Copy;
1616

17-
#[macro_escape]
17+
#[cfg_attr(stage0, macro_escape)]
18+
#[cfg_attr(not(stage0), macro_use)]
1819
mod int_macros;
1920

2021
mod i8;
@@ -23,7 +24,8 @@ mod i32;
2324
mod i64;
2425
mod int;
2526

26-
#[macro_escape]
27+
#[cfg_attr(stage0, macro_escape)]
28+
#[cfg_attr(not(stage0), macro_use)]
2729
mod uint_macros;
2830

2931
mod u8;

src/liblog/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ use regex::Regex;
183183

184184
use directive::LOG_LEVEL_NAMES;
185185

186-
#[macro_escape]
186+
#[cfg_attr(stage0, macro_escape)]
187+
#[cfg_attr(not(stage0), macro_use)]
187188
pub mod macros;
188189

189190
mod directive;

src/librustc_driver/driver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
182182
// strip before expansion to allow macros to depend on
183183
// configuration variables e.g/ in
184184
//
185-
// #[macro_escape] #[cfg(foo)]
185+
// #[macro_use] #[cfg(foo)]
186186
// mod bar { macro_rules! baz!(() => {{}}) }
187187
//
188188
// baz! should not use this definition unless foo is enabled.

src/librustc_trans/trans/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ pub use self::base::trans_crate;
1616
pub use self::context::CrateContext;
1717
pub use self::common::gensym_name;
1818

19-
#[macro_escape]
19+
#[cfg_attr(stage0, macro_escape)]
20+
#[cfg_attr(not(stage0), macro_use)]
2021
mod macros;
2122

2223
mod doc;

src/librustdoc/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ use rustc::session::search_paths::SearchPaths;
4949
// reexported from `clean` so it can be easily updated with the mod itself
5050
pub use clean::SCHEMA_VERSION;
5151

52-
#[macro_escape]
52+
#[cfg_attr(stage0, macro_escape)]
53+
#[cfg_attr(not(stage0), macro_use)]
5354
pub mod externalfiles;
5455

5556
pub mod clean;

src/libstd/io/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ pub mod stdio;
285285
pub mod timer;
286286
pub mod util;
287287

288-
#[macro_escape]
288+
#[cfg_attr(stage0, macro_escape)]
289+
#[cfg_attr(not(stage0), macro_use)]
289290
pub mod test;
290291

291292
/// The default buffer size for various I/O operations

src/libstd/lib.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,17 @@ pub use unicode::char;
173173
/* Exported macros */
174174

175175
#[cfg(stage0)]
176-
#[macro_escape]
176+
#[cfg_attr(stage0, macro_escape)]
177+
#[cfg_attr(not(stage0), macro_use)]
177178
pub mod macros_stage0;
178179

179180
#[cfg(not(stage0))]
180-
#[macro_escape]
181+
#[cfg_attr(stage0, macro_escape)]
182+
#[cfg_attr(not(stage0), macro_use)]
181183
pub mod macros;
182184

183-
#[macro_escape]
185+
#[cfg_attr(stage0, macro_escape)]
186+
#[cfg_attr(not(stage0), macro_use)]
184187
pub mod bitflags;
185188

186189
mod rtdeps;
@@ -193,15 +196,18 @@ pub mod prelude;
193196
/* Primitive types */
194197

195198
#[path = "num/float_macros.rs"]
196-
#[macro_escape]
199+
#[cfg_attr(stage0, macro_escape)]
200+
#[cfg_attr(not(stage0), macro_use)]
197201
mod float_macros;
198202

199203
#[path = "num/int_macros.rs"]
200-
#[macro_escape]
204+
#[cfg_attr(stage0, macro_escape)]
205+
#[cfg_attr(not(stage0), macro_use)]
201206
mod int_macros;
202207

203208
#[path = "num/uint_macros.rs"]
204-
#[macro_escape]
209+
#[cfg_attr(stage0, macro_escape)]
210+
#[cfg_attr(not(stage0), macro_use)]
205211
mod uint_macros;
206212

207213
#[path = "num/int.rs"] pub mod int;
@@ -229,7 +235,8 @@ pub mod num;
229235

230236
/* Runtime and platform support */
231237

232-
#[macro_escape]
238+
#[cfg_attr(stage0, macro_escape)]
239+
#[cfg_attr(not(stage0), macro_use)]
233240
pub mod thread_local;
234241

235242
pub mod c_str;

src/libstd/rt/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ pub use alloc::heap;
3939
pub mod backtrace;
4040

4141
// Internals
42+
#[cfg_attr(stage0, macro_escape)]
43+
#[cfg_attr(not(stage0), macro_use)]
4244
mod macros;
4345

4446
// These should be refactored/moved/made private over time

src/libstd/thread_local/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ use prelude::v1::*;
4040

4141
use cell::UnsafeCell;
4242

43-
#[macro_escape]
43+
#[cfg_attr(stage0, macro_escape)]
44+
#[cfg_attr(not(stage0), macro_use)]
4445
pub mod scoped;
4546

4647
// Sure wish we had macro hygiene, no?

src/libsyntax/ext/expand.rs

+27-18
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,9 @@ pub fn expand_item(it: P<ast::Item>, fld: &mut MacroExpander)
440440
if valid_ident {
441441
fld.cx.mod_push(it.ident);
442442
}
443-
let macro_escape = contains_macro_escape(new_attrs[]);
443+
let macro_use = contains_macro_use(fld, new_attrs[]);
444444
let result = with_exts_frame!(fld.cx.syntax_env,
445-
macro_escape,
445+
macro_use,
446446
noop_fold_item(it, fld));
447447
if valid_ident {
448448
fld.cx.mod_pop();
@@ -522,9 +522,28 @@ fn expand_item_underscore(item: ast::Item_, fld: &mut MacroExpander) -> ast::Ite
522522
}
523523
}
524524

525-
// does this attribute list contain "macro_escape" ?
526-
fn contains_macro_escape(attrs: &[ast::Attribute]) -> bool {
527-
attr::contains_name(attrs, "macro_escape")
525+
// does this attribute list contain "macro_use" ?
526+
fn contains_macro_use(fld: &mut MacroExpander, attrs: &[ast::Attribute]) -> bool {
527+
for attr in attrs.iter() {
528+
let mut is_use = attr.check_name("macro_use");
529+
if attr.check_name("macro_escape") {
530+
fld.cx.span_warn(attr.span, "macro_escape is a deprecated synonym for macro_use");
531+
is_use = true;
532+
if let ast::AttrInner = attr.node.style {
533+
fld.cx.span_help(attr.span, "consider an outer attribute, \
534+
#[macro_use] mod ...");
535+
}
536+
};
537+
538+
if is_use {
539+
match attr.node.value.node {
540+
ast::MetaWord(..) => (),
541+
_ => fld.cx.span_err(attr.span, "arguments to macro_use are not allowed here"),
542+
}
543+
return true;
544+
}
545+
}
546+
false
528547
}
529548

530549
// Support for item-position macro invocations, exactly the same
@@ -1299,7 +1318,7 @@ impl<'a, 'v> Visitor<'v> for MacroExterminator<'a> {
12991318

13001319
#[cfg(test)]
13011320
mod test {
1302-
use super::{pattern_bindings, expand_crate, contains_macro_escape};
1321+
use super::{pattern_bindings, expand_crate, contains_macro_use};
13031322
use super::{PatIdentFinder, IdentRenamer, PatIdentRenamer, ExpansionConfig};
13041323
use ast;
13051324
use ast::{Attribute_, AttrOuter, MetaWord, Name};
@@ -1396,9 +1415,9 @@ mod test {
13961415
expand_crate(&sess,test_ecfg(),vec!(),vec!(),crate_ast);
13971416
}
13981417

1399-
// macro_escape modules should allow macros to escape
1418+
// macro_use modules should allow macros to escape
14001419
#[test] fn macros_can_escape_flattened_mods_test () {
1401-
let src = "#[macro_escape] mod foo {macro_rules! z (() => (3+4));}\
1420+
let src = "#[macro_use] mod foo {macro_rules! z (() => (3+4));}\
14021421
fn inty() -> int { z!() }".to_string();
14031422
let sess = parse::new_parse_sess();
14041423
let crate_ast = parse::parse_crate_from_source_str(
@@ -1408,16 +1427,6 @@ mod test {
14081427
expand_crate(&sess, test_ecfg(), vec!(), vec!(), crate_ast);
14091428
}
14101429

1411-
#[test] fn test_contains_flatten (){
1412-
let attr1 = make_dummy_attr ("foo");
1413-
let attr2 = make_dummy_attr ("bar");
1414-
let escape_attr = make_dummy_attr ("macro_escape");
1415-
let attrs1 = vec!(attr1.clone(), escape_attr, attr2.clone());
1416-
assert_eq!(contains_macro_escape(attrs1[]),true);
1417-
let attrs2 = vec!(attr1,attr2);
1418-
assert_eq!(contains_macro_escape(attrs2[]),false);
1419-
}
1420-
14211430
// make a MetaWord outer attribute with the given name
14221431
fn make_dummy_attr(s: &str) -> ast::Attribute {
14231432
Spanned {

src/libsyntax/parse/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ use std::num::Int;
2424
use std::str;
2525
use std::iter;
2626

27-
#[macro_escape]
27+
#[cfg_attr(stage0, macro_escape)]
28+
#[cfg_attr(not(stage0), macro_use)]
2829
pub mod parser;
2930

3031
pub mod lexer;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2013-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_use(foo, bar)] //~ ERROR arguments to macro_use are not allowed here
12+
mod foo {
13+
}
14+
15+
fn main() {
16+
}

src/test/run-pass/cfg-macros-foo.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
#![feature(macro_rules)]
1717

1818
#[cfg(foo)]
19-
#[macro_escape]
19+
#[macro_use]
2020
mod foo {
2121
macro_rules! bar {
2222
() => { true }
2323
}
2424
}
2525

2626
#[cfg(not(foo))]
27-
#[macro_escape]
27+
#[macro_use]
2828
mod foo {
2929
macro_rules! bar {
3030
() => { false }

src/test/run-pass/cfg-macros-notfoo.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
#![feature(macro_rules)]
1717

1818
#[cfg(foo)]
19-
#[macro_escape]
19+
#[macro_use]
2020
mod foo {
2121
macro_rules! bar {
2222
() => { true }
2323
}
2424
}
2525

2626
#[cfg(not(foo))]
27-
#[macro_escape]
27+
#[macro_use]
2828
mod foo {
2929
macro_rules! bar {
3030
() => { false }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2013-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+
// ignore-pretty
12+
13+
mod foo {
14+
#![macro_escape] //~ WARNING macro_escape is a deprecated synonym for macro_use
15+
//~^ HELP consider an outer attribute
16+
}
17+
18+
fn main() {
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2013-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+
// ignore-pretty
12+
13+
#[macro_escape] //~ WARNING macro_escape is a deprecated synonym for macro_use
14+
mod foo {
15+
}
16+
17+
fn main() {
18+
}

0 commit comments

Comments
 (0)