File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ extern crate proc_macro;
2+
3+ use proc_macro:: TokenStream ;
4+
5+ #[ proc_macro_attribute]
6+ pub fn my_proc_macro ( _: TokenStream , input : TokenStream ) -> TokenStream {
7+ if format ! ( "{input:#?}" ) . contains ( "my_attr1" ) {
8+ panic ! ( "found gated attribute my_attr1" ) ;
9+ }
10+ if format ! ( "{input:#?}" ) . contains ( "placeholder" ) {
11+ panic ! ( "found placeholder attribute" ) ;
12+ }
13+ if !format ! ( "{input:#?}" ) . contains ( "my_attr2" ) {
14+ panic ! ( "didn't if gated my_attr2" ) ;
15+ }
16+ input
17+ }
18+
19+ #[ proc_macro_attribute]
20+ pub fn my_attr1 ( _: TokenStream , input : TokenStream ) -> TokenStream {
21+ panic ! ( "my_attr1 was called" ) ;
22+ input
23+ }
24+
25+ #[ proc_macro_attribute]
26+ pub fn my_attr2 ( _: TokenStream , input : TokenStream ) -> TokenStream {
27+ if format ! ( "{input:#?}" ) . contains ( "my_attr1" ) {
28+ panic ! ( "found gated attribute my_attr1" ) ;
29+ }
30+ input
31+ }
Original file line number Diff line number Diff line change 1+ // Ensure that `rustc-cfg-placeholder` isn't visible to proc-macros.
2+ //@proc-macro: cfg-placeholder.rs
3+ //@check-pass
4+ #![ feature( cfg_eval) ]
5+ #[ macro_use] extern crate cfg_placeholder;
6+
7+ #[ cfg_eval]
8+ #[ my_proc_macro]
9+ #[ cfg_attr( FALSE , my_attr1) ]
10+ #[ cfg_attr( all( ) , my_attr2) ]
11+ struct S { }
12+
13+ fn main ( ) { }
You can’t perform that action at this time.
0 commit comments