Skip to content

Commit

Permalink
Add test for rustc-cfg-placeholder interaction with proc-macro
Browse files Browse the repository at this point in the history
Ensure that the cfg-placeholder isn't visible by proc-macros.
  • Loading branch information
estebank committed Dec 12, 2024
1 parent 7a9565b commit 5ebcd19
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/ui/proc-macro/auxiliary/cfg-placeholder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
extern crate proc_macro;

use proc_macro::TokenStream;

#[proc_macro_attribute]
pub fn my_proc_macro(_: TokenStream, input: TokenStream) -> TokenStream {
if format!("{input:#?}").contains("my_attr1") {
panic!("found gated attribute my_attr1");
}
if !format!("{input:#?}").contains("my_attr2") {
panic!("didn't if gated my_attr2");
}
input
}

#[proc_macro_attribute]
pub fn my_attr1(_: TokenStream, input: TokenStream) -> TokenStream {
panic!("my_attr1 was called");
input
}

#[proc_macro_attribute]
pub fn my_attr2(_: TokenStream, input: TokenStream) -> TokenStream {
if format!("{input:#?}").contains("my_attr1") {
panic!("found gated attribute my_attr1");
}
input
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Ensure that `rustc-cfg-placeholder` isn't visible to proc-macros.
//@proc-macro: cfg-placeholder.rs
//@check-pass
#![feature(cfg_eval)]
#[macro_use] extern crate cfg_placeholder;

#[cfg_eval]
#[my_proc_macro]
#[cfg_attr(FALSE, my_attr1)]
#[cfg_attr(all(), my_attr2)]
struct S {}

fn main() {}

0 comments on commit 5ebcd19

Please sign in to comment.