]> git.lizzy.rs Git - rust.git/blob - src/test/ui/proc-macro/auxiliary/raw-ident.rs
Stabilize Ident::new_raw
[rust.git] / src / test / ui / proc-macro / auxiliary / raw-ident.rs
1 // force-host
2 // no-prefer-dynamic
3
4 #![crate_type = "proc-macro"]
5
6 extern crate proc_macro;
7 use proc_macro::{TokenStream, TokenTree, Ident, Punct, Spacing, Span};
8
9 #[proc_macro]
10 pub fn make_struct(input: TokenStream) -> TokenStream {
11     match input.into_iter().next().unwrap() {
12         TokenTree::Ident(ident) => {
13             vec![
14                 TokenTree::Ident(Ident::new("struct", Span::call_site())),
15                 TokenTree::Ident(Ident::new_raw(&ident.to_string(), Span::call_site())),
16                 TokenTree::Punct(Punct::new(';', Spacing::Alone))
17             ].into_iter().collect()
18         }
19         _ => panic!()
20     }
21 }
22
23 #[proc_macro]
24 pub fn make_bad_struct(input: TokenStream) -> TokenStream {
25     match input.into_iter().next().unwrap() {
26         TokenTree::Ident(ident) => {
27             vec![
28                 TokenTree::Ident(Ident::new_raw("struct", Span::call_site())),
29                 TokenTree::Ident(Ident::new(&ident.to_string(), Span::call_site())),
30                 TokenTree::Punct(Punct::new(';', Spacing::Alone))
31             ].into_iter().collect()
32         }
33         _ => panic!()
34     }
35 }