File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-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 ( "my_attr2" ) {
11
+ panic ! ( "didn't if gated my_attr2" ) ;
12
+ }
13
+ input
14
+ }
15
+
16
+ #[ proc_macro_attribute]
17
+ pub fn my_attr1 ( _: TokenStream , input : TokenStream ) -> TokenStream {
18
+ panic ! ( "my_attr1 was called" ) ;
19
+ input
20
+ }
21
+
22
+ #[ proc_macro_attribute]
23
+ pub fn my_attr2 ( _: TokenStream , input : TokenStream ) -> TokenStream {
24
+ if format ! ( "{input:#?}" ) . contains ( "my_attr1" ) {
25
+ panic ! ( "found gated attribute my_attr1" ) ;
26
+ }
27
+ input
28
+ }
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