diff options
Diffstat (limited to 'tests/ui/proc-macro/auxiliary/duplicate.rs')
-rw-r--r-- | tests/ui/proc-macro/auxiliary/duplicate.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/ui/proc-macro/auxiliary/duplicate.rs b/tests/ui/proc-macro/auxiliary/duplicate.rs new file mode 100644 index 000000000..b8f82b46f --- /dev/null +++ b/tests/ui/proc-macro/auxiliary/duplicate.rs @@ -0,0 +1,32 @@ +// force-host +// no-prefer-dynamic + +#![deny(unused)] +#![crate_type = "proc-macro"] + +extern crate proc_macro; +use proc_macro::*; + +#[proc_macro_attribute] +pub fn duplicate(attr: TokenStream, item: TokenStream) -> TokenStream { + let mut new_name = Some(attr.into_iter().nth(0).unwrap()); + let mut encountered_idents = 0; + let input = item.to_string(); + let ret = item + .into_iter() + .map(move |token| match token { + TokenTree::Ident(_) if encountered_idents == 1 => { + encountered_idents += 1; + new_name.take().unwrap() + } + TokenTree::Ident(_) => { + encountered_idents += 1; + token + } + _ => token, + }) + .collect::<TokenStream>(); + let mut input_again = input.parse::<TokenStream>().unwrap(); + input_again.extend(ret); + input_again +} |