Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 59e4c2c

Browse files
committedMar 14, 2025
Add test for rustc-cfg-placeholder interaction with proc-macro
Ensure that the cfg-placeholder isn't visible by proc-macros.
1 parent 9985925 commit 59e4c2c

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 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)
Failed to load comments.