]> git.lizzy.rs Git - rust.git/blob - tests/ui/annotate-snippet/auxiliary/multispan.rs
Add regression test for #42114
[rust.git] / tests / ui / annotate-snippet / auxiliary / multispan.rs
1 // force-host
2 // no-prefer-dynamic
3
4 #![crate_type = "proc-macro"]
5 #![feature(proc_macro_diagnostic, proc_macro_span, proc_macro_def_site)]
6
7 extern crate proc_macro;
8
9 use proc_macro::{TokenStream, TokenTree, Span, Diagnostic};
10
11 fn parse(input: TokenStream) -> Result<(), Diagnostic> {
12     let mut hi_spans = vec![];
13     for tree in input {
14         if let TokenTree::Ident(ref ident) = tree {
15             if ident.to_string() == "hi" {
16                 hi_spans.push(ident.span());
17             }
18         }
19     }
20
21     if !hi_spans.is_empty() {
22         return Err(Span::def_site()
23                        .error("hello to you, too!")
24                        .span_note(hi_spans, "found these 'hi's"));
25     }
26
27     Ok(())
28 }
29
30 #[proc_macro]
31 pub fn hello(input: TokenStream) -> TokenStream {
32     if let Err(diag) = parse(input) {
33         diag.emit();
34     }
35
36     TokenStream::new()
37 }