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.
This commit is contained in:
Keegan McAllister 2014-12-18 20:48:26 -08:00
parent fc58479323
commit 5bf385be6a
18 changed files with 127 additions and 43 deletions

View File

@ -54,7 +54,8 @@ pub use vec_map::VecMap;
// Needed for the vec! macro // Needed for the vec! macro
pub use alloc::boxed; pub use alloc::boxed;
#[macro_escape] #[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod macros; mod macros;
pub mod binary_heap; pub mod binary_heap;

View File

@ -62,19 +62,23 @@
#![feature(default_type_params, unboxed_closures, associated_types)] #![feature(default_type_params, unboxed_closures, associated_types)]
#![deny(missing_docs)] #![deny(missing_docs)]
#[macro_escape] #[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod macros; mod macros;
#[path = "num/float_macros.rs"] #[path = "num/float_macros.rs"]
#[macro_escape] #[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod float_macros; mod float_macros;
#[path = "num/int_macros.rs"] #[path = "num/int_macros.rs"]
#[macro_escape] #[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod int_macros; mod int_macros;
#[path = "num/uint_macros.rs"] #[path = "num/uint_macros.rs"]
#[macro_escape] #[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod uint_macros; mod uint_macros;
#[path = "num/int.rs"] pub mod int; #[path = "num/int.rs"] pub mod int;

View File

@ -14,7 +14,8 @@ use core::num::{NumCast, cast};
use core::ops::{Add, Sub, Mul, Div, Rem}; use core::ops::{Add, Sub, Mul, Div, Rem};
use core::kinds::Copy; use core::kinds::Copy;
#[macro_escape] #[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod int_macros; mod int_macros;
mod i8; mod i8;
@ -23,7 +24,8 @@ mod i32;
mod i64; mod i64;
mod int; mod int;
#[macro_escape] #[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod uint_macros; mod uint_macros;
mod u8; mod u8;

View File

@ -183,7 +183,8 @@ use regex::Regex;
use directive::LOG_LEVEL_NAMES; use directive::LOG_LEVEL_NAMES;
#[macro_escape] #[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
pub mod macros; pub mod macros;
mod directive; mod directive;

View File

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

View File

@ -16,7 +16,8 @@ pub use self::base::trans_crate;
pub use self::context::CrateContext; pub use self::context::CrateContext;
pub use self::common::gensym_name; pub use self::common::gensym_name;
#[macro_escape] #[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod macros; mod macros;
mod doc; mod doc;

View File

@ -49,7 +49,8 @@ use rustc::session::search_paths::SearchPaths;
// reexported from `clean` so it can be easily updated with the mod itself // reexported from `clean` so it can be easily updated with the mod itself
pub use clean::SCHEMA_VERSION; pub use clean::SCHEMA_VERSION;
#[macro_escape] #[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
pub mod externalfiles; pub mod externalfiles;
pub mod clean; pub mod clean;

View File

@ -285,7 +285,8 @@ pub mod stdio;
pub mod timer; pub mod timer;
pub mod util; pub mod util;
#[macro_escape] #[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
pub mod test; pub mod test;
/// The default buffer size for various I/O operations /// The default buffer size for various I/O operations

View File

@ -173,14 +173,17 @@ pub use unicode::char;
/* Exported macros */ /* Exported macros */
#[cfg(stage0)] #[cfg(stage0)]
#[macro_escape] #[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
pub mod macros_stage0; pub mod macros_stage0;
#[cfg(not(stage0))] #[cfg(not(stage0))]
#[macro_escape] #[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
pub mod macros; pub mod macros;
#[macro_escape] #[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
pub mod bitflags; pub mod bitflags;
mod rtdeps; mod rtdeps;
@ -193,15 +196,18 @@ pub mod prelude;
/* Primitive types */ /* Primitive types */
#[path = "num/float_macros.rs"] #[path = "num/float_macros.rs"]
#[macro_escape] #[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod float_macros; mod float_macros;
#[path = "num/int_macros.rs"] #[path = "num/int_macros.rs"]
#[macro_escape] #[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod int_macros; mod int_macros;
#[path = "num/uint_macros.rs"] #[path = "num/uint_macros.rs"]
#[macro_escape] #[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod uint_macros; mod uint_macros;
#[path = "num/int.rs"] pub mod int; #[path = "num/int.rs"] pub mod int;
@ -229,7 +235,8 @@ pub mod num;
/* Runtime and platform support */ /* Runtime and platform support */
#[macro_escape] #[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
pub mod thread_local; pub mod thread_local;
pub mod c_str; pub mod c_str;

View File

@ -39,6 +39,8 @@ pub use alloc::heap;
pub mod backtrace; pub mod backtrace;
// Internals // Internals
#[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
mod macros; mod macros;
// These should be refactored/moved/made private over time // These should be refactored/moved/made private over time

View File

@ -40,7 +40,8 @@ use prelude::v1::*;
use cell::UnsafeCell; use cell::UnsafeCell;
#[macro_escape] #[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
pub mod scoped; pub mod scoped;
// Sure wish we had macro hygiene, no? // Sure wish we had macro hygiene, no?

View File

@ -440,9 +440,9 @@ pub fn expand_item(it: P<ast::Item>, fld: &mut MacroExpander)
if valid_ident { if valid_ident {
fld.cx.mod_push(it.ident); fld.cx.mod_push(it.ident);
} }
let macro_escape = contains_macro_escape(new_attrs[]); let macro_use = contains_macro_use(fld, new_attrs[]);
let result = with_exts_frame!(fld.cx.syntax_env, let result = with_exts_frame!(fld.cx.syntax_env,
macro_escape, macro_use,
noop_fold_item(it, fld)); noop_fold_item(it, fld));
if valid_ident { if valid_ident {
fld.cx.mod_pop(); fld.cx.mod_pop();
@ -522,9 +522,28 @@ fn expand_item_underscore(item: ast::Item_, fld: &mut MacroExpander) -> ast::Ite
} }
} }
// does this attribute list contain "macro_escape" ? // does this attribute list contain "macro_use" ?
fn contains_macro_escape(attrs: &[ast::Attribute]) -> bool { fn contains_macro_use(fld: &mut MacroExpander, attrs: &[ast::Attribute]) -> bool {
attr::contains_name(attrs, "macro_escape") for attr in attrs.iter() {
let mut is_use = attr.check_name("macro_use");
if attr.check_name("macro_escape") {
fld.cx.span_warn(attr.span, "macro_escape is a deprecated synonym for macro_use");
is_use = true;
if let ast::AttrInner = attr.node.style {
fld.cx.span_help(attr.span, "consider an outer attribute, \
#[macro_use] mod ...");
}
};
if is_use {
match attr.node.value.node {
ast::MetaWord(..) => (),
_ => fld.cx.span_err(attr.span, "arguments to macro_use are not allowed here"),
}
return true;
}
}
false
} }
// Support for item-position macro invocations, exactly the same // Support for item-position macro invocations, exactly the same
@ -1299,7 +1318,7 @@ impl<'a, 'v> Visitor<'v> for MacroExterminator<'a> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::{pattern_bindings, expand_crate, contains_macro_escape}; use super::{pattern_bindings, expand_crate, contains_macro_use};
use super::{PatIdentFinder, IdentRenamer, PatIdentRenamer, ExpansionConfig}; use super::{PatIdentFinder, IdentRenamer, PatIdentRenamer, ExpansionConfig};
use ast; use ast;
use ast::{Attribute_, AttrOuter, MetaWord, Name}; use ast::{Attribute_, AttrOuter, MetaWord, Name};
@ -1396,9 +1415,9 @@ mod test {
expand_crate(&sess,test_ecfg(),vec!(),vec!(),crate_ast); expand_crate(&sess,test_ecfg(),vec!(),vec!(),crate_ast);
} }
// macro_escape modules should allow macros to escape // macro_use modules should allow macros to escape
#[test] fn macros_can_escape_flattened_mods_test () { #[test] fn macros_can_escape_flattened_mods_test () {
let src = "#[macro_escape] mod foo {macro_rules! z (() => (3+4));}\ let src = "#[macro_use] mod foo {macro_rules! z (() => (3+4));}\
fn inty() -> int { z!() }".to_string(); fn inty() -> int { z!() }".to_string();
let sess = parse::new_parse_sess(); let sess = parse::new_parse_sess();
let crate_ast = parse::parse_crate_from_source_str( let crate_ast = parse::parse_crate_from_source_str(
@ -1408,16 +1427,6 @@ mod test {
expand_crate(&sess, test_ecfg(), vec!(), vec!(), crate_ast); expand_crate(&sess, test_ecfg(), vec!(), vec!(), crate_ast);
} }
#[test] fn test_contains_flatten (){
let attr1 = make_dummy_attr ("foo");
let attr2 = make_dummy_attr ("bar");
let escape_attr = make_dummy_attr ("macro_escape");
let attrs1 = vec!(attr1.clone(), escape_attr, attr2.clone());
assert_eq!(contains_macro_escape(attrs1[]),true);
let attrs2 = vec!(attr1,attr2);
assert_eq!(contains_macro_escape(attrs2[]),false);
}
// make a MetaWord outer attribute with the given name // make a MetaWord outer attribute with the given name
fn make_dummy_attr(s: &str) -> ast::Attribute { fn make_dummy_attr(s: &str) -> ast::Attribute {
Spanned { Spanned {

View File

@ -24,7 +24,8 @@ use std::num::Int;
use std::str; use std::str;
use std::iter; use std::iter;
#[macro_escape] #[cfg_attr(stage0, macro_escape)]
#[cfg_attr(not(stage0), macro_use)]
pub mod parser; pub mod parser;
pub mod lexer; pub mod lexer;

View File

@ -0,0 +1,16 @@
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[macro_use(foo, bar)] //~ ERROR arguments to macro_use are not allowed here
mod foo {
}
fn main() {
}

View File

@ -16,7 +16,7 @@
#![feature(macro_rules)] #![feature(macro_rules)]
#[cfg(foo)] #[cfg(foo)]
#[macro_escape] #[macro_use]
mod foo { mod foo {
macro_rules! bar { macro_rules! bar {
() => { true } () => { true }
@ -24,7 +24,7 @@ mod foo {
} }
#[cfg(not(foo))] #[cfg(not(foo))]
#[macro_escape] #[macro_use]
mod foo { mod foo {
macro_rules! bar { macro_rules! bar {
() => { false } () => { false }

View File

@ -16,7 +16,7 @@
#![feature(macro_rules)] #![feature(macro_rules)]
#[cfg(foo)] #[cfg(foo)]
#[macro_escape] #[macro_use]
mod foo { mod foo {
macro_rules! bar { macro_rules! bar {
() => { true } () => { true }
@ -24,7 +24,7 @@ mod foo {
} }
#[cfg(not(foo))] #[cfg(not(foo))]
#[macro_escape] #[macro_use]
mod foo { mod foo {
macro_rules! bar { macro_rules! bar {
() => { false } () => { false }

View File

@ -0,0 +1,19 @@
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-pretty
mod foo {
#![macro_escape] //~ WARNING macro_escape is a deprecated synonym for macro_use
//~^ HELP consider an outer attribute
}
fn main() {
}

View File

@ -0,0 +1,18 @@
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-pretty
#[macro_escape] //~ WARNING macro_escape is a deprecated synonym for macro_use
mod foo {
}
fn main() {
}