-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for rustc-cfg-placeholder interaction with proc-macro
Ensure that the cfg-placeholder isn't visible by proc-macros.
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/ui/proc-macro/cfg-attr-placeholder-invisible-to-proc-macro.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |