Skip to content

Commit 210be0d

Browse files
committed
Add test for unuseful span in type error in some format_args!() invocations
1 parent 9311767 commit 210be0d

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
fn check_format_args() {
2+
print!("{:?} {a} {a:?}", [], a = 1 + 1);
3+
//~^ ERROR type annotations needed
4+
}
5+
6+
fn check_format_args_nl() {
7+
println!("{:?} {a} {a:?}", [], a = 1 + 1);
8+
//~^ ERROR type annotations needed
9+
}
10+
11+
fn check_multi1() {
12+
println!("{:?} {:?} {a} {a:?}", [], [], a = 1 + 1);
13+
//~^ ERROR type annotations needed
14+
}
15+
16+
fn check_multi2() {
17+
println!("{:?} {:?} {a} {a:?} {b:?}", [], [], a = 1 + 1, b = []);
18+
//~^ ERROR type annotations needed
19+
}
20+
21+
fn check_unformatted() {
22+
println!("
23+
{:?} {:?}
24+
{a}
25+
{a:?}",
26+
[],
27+
//~^ ERROR type annotations needed
28+
[],
29+
a = 1 + 1);
30+
}
31+
32+
fn main() {}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/span-format_args-issue-140578.rs:2:28
3+
|
4+
LL | print!("{:?} {a} {a:?}", [], a = 1 + 1);
5+
| ^^ cannot infer type
6+
|
7+
= note: this error originates in the macro `$crate::format_args` which comes from the expansion of the macro `print` (in Nightly builds, run with -Z macro-backtrace for more info)
8+
9+
error[E0282]: type annotations needed
10+
--> $DIR/span-format_args-issue-140578.rs:7:30
11+
|
12+
LL | println!("{:?} {a} {a:?}", [], a = 1 + 1);
13+
| ^^ cannot infer type
14+
|
15+
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
16+
17+
error[E0282]: type annotations needed
18+
--> $DIR/span-format_args-issue-140578.rs:12:35
19+
|
20+
LL | println!("{:?} {:?} {a} {a:?}", [], [], a = 1 + 1);
21+
| ^^ cannot infer type
22+
|
23+
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
24+
25+
error[E0282]: type annotations needed
26+
--> $DIR/span-format_args-issue-140578.rs:17:41
27+
|
28+
LL | println!("{:?} {:?} {a} {a:?} {b:?}", [], [], a = 1 + 1, b = []);
29+
| ^^ cannot infer type
30+
|
31+
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
32+
33+
error[E0282]: type annotations needed
34+
--> $DIR/span-format_args-issue-140578.rs:26:9
35+
|
36+
LL | [],
37+
| ^^ cannot infer type
38+
|
39+
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
40+
41+
error: aborting due to 5 previous errors
42+
43+
For more information about this error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)