diff --git a/tests/ui/proc-macro/auxiliary/cfg-placeholder.rs b/tests/ui/proc-macro/auxiliary/cfg-placeholder.rs new file mode 100644 index 0000000000000..f28dff50e2f6b --- /dev/null +++ b/tests/ui/proc-macro/auxiliary/cfg-placeholder.rs @@ -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 +} diff --git a/tests/ui/proc-macro/cfg-attr-placeholder-invisible-to-proc-macro.rs b/tests/ui/proc-macro/cfg-attr-placeholder-invisible-to-proc-macro.rs new file mode 100644 index 0000000000000..62cac78788367 --- /dev/null +++ b/tests/ui/proc-macro/cfg-attr-placeholder-invisible-to-proc-macro.rs @@ -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() {}