File tree Expand file tree Collapse file tree 3 files changed +126
-0
lines changed Expand file tree Collapse file tree 3 files changed +126
-0
lines changed Original file line number Diff line number Diff line change 1+ //@ run-pass
2+ //@ check-run-results
3+ #![ feature( macro_attr) ]
4+ #![ warn( unused) ]
5+
6+ #[ macro_export]
7+ macro_rules! exported_attr {
8+ attr( $( $args: tt) * ) { $( $body: tt) * } => {
9+ println!(
10+ "exported_attr: args={:?}, body={:?}" ,
11+ stringify!( $( $args) * ) ,
12+ stringify!( $( $body) * ) ,
13+ ) ;
14+ } ;
15+ { $( $args: tt) * } => {
16+ println!( "exported_attr!({:?})" , stringify!( $( $args) * ) ) ;
17+ } ;
18+ attr( ) { } => {
19+ unused_rule( ) ;
20+ } ;
21+ attr( ) { } => {
22+ compile_error!( ) ;
23+ } ;
24+ { } => {
25+ unused_rule( ) ;
26+ } ;
27+ { } => {
28+ compile_error!( ) ;
29+ } ;
30+ }
31+
32+ macro_rules! local_attr {
33+ attr( $( $args: tt) * ) { $( $body: tt) * } => {
34+ println!(
35+ "local_attr: args={:?}, body={:?}" ,
36+ stringify!( $( $args) * ) ,
37+ stringify!( $( $body) * ) ,
38+ ) ;
39+ } ;
40+ { $( $args: tt) * } => {
41+ println!( "local_attr!({:?})" , stringify!( $( $args) * ) ) ;
42+ } ;
43+ attr( ) { } => { //~ WARN: never used
44+ unused_rule( ) ;
45+ } ;
46+ attr( ) { } => {
47+ compile_error!( ) ;
48+ } ;
49+ { } => { //~ WARN: never used
50+ unused_rule( ) ;
51+ } ;
52+ { } => {
53+ compile_error!( ) ;
54+ } ;
55+ }
56+
57+ fn main( ) {
58+ #[ crate :: exported_attr]
59+ struct S ;
60+ #[ :: exported_attr( arguments, key = "value" ) ]
61+ fn func( _arg: u32 ) { }
62+ #[ self :: exported_attr( 1 ) ]
63+ #[ self :: exported_attr( 2 ) ]
64+ struct Twice ;
65+
66+ crate :: exported_attr!( ) ;
67+ crate :: exported_attr!( invoked, arguments) ;
68+
69+ #[ exported_attr]
70+ struct S ;
71+ #[ exported_attr( arguments, key = "value" ) ]
72+ fn func( _arg: u32 ) { }
73+ #[ exported_attr( 1 ) ]
74+ #[ exported_attr( 2 ) ]
75+ struct Twice ;
76+
77+ exported_attr!( ) ;
78+ exported_attr!( invoked, arguments) ;
79+
80+ #[ local_attr]
81+ struct S ;
82+ #[ local_attr( arguments, key = "value" ) ]
83+ fn func( _arg: u32 ) { }
84+ #[ local_attr( 1 ) ]
85+ #[ local_attr( 2 ) ]
86+ struct Twice ;
87+
88+ local_attr!( ) ;
89+ local_attr!( invoked, arguments) ;
90+ }
Original file line number Diff line number Diff line change 1+ exported_attr: args="", body="struct S;"
2+ exported_attr: args="arguments, key = \"value\"", body="fn func(_arg: u32) {}"
3+ exported_attr: args="1", body="#[self::exported_attr(2)] struct Twice;"
4+ exported_attr!("")
5+ exported_attr!("invoked, arguments")
6+ exported_attr: args="", body="struct S;"
7+ exported_attr: args="arguments, key = \"value\"", body="fn func(_arg: u32) {}"
8+ exported_attr: args="1", body="#[exported_attr(2)] struct Twice;"
9+ exported_attr!("")
10+ exported_attr!("invoked, arguments")
11+ local_attr: args="", body="struct S;"
12+ local_attr: args="arguments, key = \"value\"", body="fn func(_arg: u32) {}"
13+ local_attr: args="1", body="#[local_attr(2)] struct Twice;"
14+ local_attr!("")
15+ local_attr!("invoked, arguments")
Original file line number Diff line number Diff line change 1+ warning: rule #3 of macro `local_attr` is never used
2+ --> $DIR/macro-rules-attr.rs:43:9
3+ |
4+ LL | attr() {} => {
5+ | ^^^^^
6+ |
7+ note: the lint level is defined here
8+ --> $DIR/macro-rules-attr.rs:4:9
9+ |
10+ LL | #![warn(unused)]
11+ | ^^^^^^
12+ = note: `#[warn(unused_macro_rules)]` implied by `#[warn(unused)]`
13+
14+ warning: rule #5 of macro `local_attr` is never used
15+ --> $DIR/macro-rules-attr.rs:49:5
16+ |
17+ LL | {} => {
18+ | ^^
19+
20+ warning: 2 warnings emitted
21+
You can’t perform that action at this time.
0 commit comments