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