]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/proc-macro/auxiliary/span-api-tests.rs
4 #![crate_type = "proc-macro"]
5 #![feature(proc_macro_span)]
7 extern crate proc_macro
;
11 // Re-emits the input tokens by parsing them from strings
13 pub fn reemit(input
: TokenStream
) -> TokenStream
{
14 input
.to_string().parse().unwrap()
18 pub fn assert_fake_source_file(input
: TokenStream
) -> TokenStream
{
20 let source_file
= tk
.span().source_file();
21 assert
!(!source_file
.is_real(), "Source file is real: {:?}", source_file
);
28 pub fn assert_source_file(input
: TokenStream
) -> TokenStream
{
30 let source_file
= tk
.span().source_file();
31 assert
!(source_file
.is_real(), "Source file is not real: {:?}", source_file
);
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()