]>
Commit | Line | Data |
---|---|---|
ea8adc8c XL |
1 | // force-host |
2 | // no-prefer-dynamic | |
3 | ||
4 | #![crate_type = "proc-macro"] | |
8faf50e0 | 5 | #![feature(proc_macro_span)] |
ea8adc8c XL |
6 | |
7 | extern crate proc_macro; | |
8 | ||
9 | use proc_macro::*; | |
10 | ||
11 | // Re-emits the input tokens by parsing them from strings | |
12 | #[proc_macro] | |
13 | pub fn reemit(input: TokenStream) -> TokenStream { | |
14 | input.to_string().parse().unwrap() | |
15 | } | |
16 | ||
17 | #[proc_macro] | |
18 | pub fn assert_fake_source_file(input: TokenStream) -> TokenStream { | |
19 | for tk in input { | |
83c7162d | 20 | let source_file = tk.span().source_file(); |
ea8adc8c XL |
21 | assert!(!source_file.is_real(), "Source file is real: {:?}", source_file); |
22 | } | |
23 | ||
24 | "".parse().unwrap() | |
25 | } | |
26 | ||
27 | #[proc_macro] | |
28 | pub fn assert_source_file(input: TokenStream) -> TokenStream { | |
29 | for tk in input { | |
83c7162d | 30 | let source_file = tk.span().source_file(); |
ea8adc8c XL |
31 | assert!(source_file.is_real(), "Source file is not real: {:?}", source_file); |
32 | } | |
33 | ||
34 | "".parse().unwrap() | |
35 | } | |
532ac7d7 XL |
36 | |
37 | #[proc_macro] | |
38 | pub fn macro_stringify(input: TokenStream) -> TokenStream { | |
39 | let mut tokens = input.into_iter(); | |
40 | let first_span = tokens.next().expect("first token").span(); | |
41 | let last_span = tokens.last().map(|x| x.span()).unwrap_or(first_span); | |
42 | let span = first_span.join(last_span).expect("joined span"); | |
43 | let src = span.source_text().expect("source_text"); | |
44 | TokenTree::Literal(Literal::string(&src)).into() | |
45 | } |