Skip to content

Commit 78b23f6

Browse files
committed
Add test for rustc-cfg-placeholder interaction with proc-macro
Ensure that the cfg-placeholder isn't visible by proc-macros.
1 parent f7905ea commit 78b23f6

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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() {}

0 commit comments

Comments
 (0)