Skip to content

Commit f16060f

Browse files
committed
Add UI test where annotated_files count is > 1 #64205
1 parent e9c78db commit f16060f

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// aux-build:multispan.rs
2+
// compile-flags: --error-format human-annotate-rs
3+
4+
#![feature(proc_macro_hygiene)]
5+
6+
extern crate multispan;
7+
8+
use multispan::hello;
9+
10+
fn main() {
11+
// This one emits no error.
12+
hello!();
13+
14+
// Exactly one 'hi'.
15+
hello!(hi); //~ ERROR hello to you, too!
16+
17+
// Now two, back to back.
18+
hello!(hi hi); //~ ERROR hello to you, too!
19+
20+
// Now three, back to back.
21+
hello!(hi hi hi); //~ ERROR hello to you, too!
22+
23+
// Now several, with spacing.
24+
hello!(hi hey hi yo hi beep beep hi hi); //~ ERROR hello to you, too!
25+
hello!(hi there, hi how are you? hi... hi.); //~ ERROR hello to you, too!
26+
hello!(whoah. hi di hi di ho); //~ ERROR hello to you, too!
27+
hello!(hi good hi and good bye); //~ ERROR hello to you, too!
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
error: hello to you, too!
2+
--> $DIR/multispan.rs:15:5
3+
|
4+
LL | hello!(hi);
5+
| ^^^^^^^^^^^
6+
|
7+
error: hello to you, too!
8+
--> $DIR/multispan.rs:18:5
9+
|
10+
LL | hello!(hi hi);
11+
| ^^^^^^^^^^^^^^
12+
|
13+
error: hello to you, too!
14+
--> $DIR/multispan.rs:21:5
15+
|
16+
LL | hello!(hi hi hi);
17+
| ^^^^^^^^^^^^^^^^^
18+
|
19+
error: hello to you, too!
20+
--> $DIR/multispan.rs:24:5
21+
|
22+
LL | hello!(hi hey hi yo hi beep beep hi hi);
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24+
|
25+
error: hello to you, too!
26+
--> $DIR/multispan.rs:25:5
27+
|
28+
LL | hello!(hi there, hi how are you? hi... hi.);
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
|
31+
error: hello to you, too!
32+
--> $DIR/multispan.rs:26:5
33+
|
34+
LL | hello!(whoah. hi di hi di ho);
35+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36+
|
37+
error: hello to you, too!
38+
--> $DIR/multispan.rs:27:5
39+
|
40+
LL | hello!(hi good hi and good bye);
41+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42+
|

0 commit comments

Comments
 (0)