]> git.lizzy.rs Git - rust.git/blob - src/test/ui/proc-macro/auxiliary/resolved-located-at.rs
Add a test for `Span::resolved_at` and `Span::located_at`
[rust.git] / src / test / ui / proc-macro / auxiliary / resolved-located-at.rs
1 // force-host
2 // no-prefer-dynamic
3
4 #![feature(proc_macro_def_site)]
5 #![feature(proc_macro_diagnostic)]
6 #![feature(proc_macro_hygiene)]
7 #![feature(proc_macro_quote)]
8 #![crate_type = "proc-macro"]
9
10 extern crate proc_macro;
11 use proc_macro::*;
12
13 #[proc_macro]
14 pub fn resolve_located_at(input: TokenStream) -> TokenStream {
15     match &*input.into_iter().collect::<Vec<_>>() {
16         [a, b, ..] => {
17             // The error is reported at input `a`.
18             let mut diag = Diagnostic::new(Level::Error, "expected error");
19             diag.set_spans(Span::def_site().located_at(a.span()));
20             diag.emit();
21
22             // Resolves to `struct S;` at def site, but the error is reported at input `b`.
23             let s = TokenTree::Ident(Ident::new("S", b.span().resolved_at(Span::def_site())));
24             quote!({
25                 struct S;
26
27                 $s
28             })
29         }
30         _ => panic!("unexpected input"),
31     }
32 }