@@ -440,9 +440,9 @@ pub fn expand_item(it: P<ast::Item>, fld: &mut MacroExpander)
440
440
if valid_ident {
441
441
fld. cx . mod_push ( it. ident ) ;
442
442
}
443
- let macro_escape = contains_macro_escape ( new_attrs[ ] ) ;
443
+ let macro_use = contains_macro_use ( fld , new_attrs[ ] ) ;
444
444
let result = with_exts_frame ! ( fld. cx. syntax_env,
445
- macro_escape ,
445
+ macro_use ,
446
446
noop_fold_item( it, fld) ) ;
447
447
if valid_ident {
448
448
fld. cx . mod_pop ( ) ;
@@ -522,9 +522,28 @@ fn expand_item_underscore(item: ast::Item_, fld: &mut MacroExpander) -> ast::Ite
522
522
}
523
523
}
524
524
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
528
547
}
529
548
530
549
// Support for item-position macro invocations, exactly the same
@@ -1299,7 +1318,7 @@ impl<'a, 'v> Visitor<'v> for MacroExterminator<'a> {
1299
1318
1300
1319
#[ cfg( test) ]
1301
1320
mod test {
1302
- use super :: { pattern_bindings, expand_crate, contains_macro_escape } ;
1321
+ use super :: { pattern_bindings, expand_crate, contains_macro_use } ;
1303
1322
use super :: { PatIdentFinder , IdentRenamer , PatIdentRenamer , ExpansionConfig } ;
1304
1323
use ast;
1305
1324
use ast:: { Attribute_ , AttrOuter , MetaWord , Name } ;
@@ -1396,9 +1415,9 @@ mod test {
1396
1415
expand_crate ( & sess, test_ecfg ( ) , vec ! ( ) , vec ! ( ) , crate_ast) ;
1397
1416
}
1398
1417
1399
- // macro_escape modules should allow macros to escape
1418
+ // macro_use modules should allow macros to escape
1400
1419
#[ 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));}\
1402
1421
fn inty() -> int { z!() }". to_string ( ) ;
1403
1422
let sess = parse:: new_parse_sess ( ) ;
1404
1423
let crate_ast = parse:: parse_crate_from_source_str (
@@ -1408,16 +1427,6 @@ mod test {
1408
1427
expand_crate ( & sess, test_ecfg ( ) , vec ! ( ) , vec ! ( ) , crate_ast) ;
1409
1428
}
1410
1429
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
-
1421
1430
// make a MetaWord outer attribute with the given name
1422
1431
fn make_dummy_attr ( s : & str ) -> ast:: Attribute {
1423
1432
Spanned {
0 commit comments