Skip to content

Commit 4662500

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

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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!(" //~ ERROR type annotations needed
23+
{:?} {:?}
24+
{a}
25+
{a:?}",
26+
[],
27+
[],
28+
a = 1 + 1);
29+
}
30+
31+
fn main() {}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/span-format_args-issue-140578.rs:2:3
3+
|
4+
LL | print!("{:?} {a} {a:?}", [], a = 1 + 1);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
6+
|
7+
= note: this error originates in 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:3
11+
|
12+
LL | println!("{:?} {a} {a:?}", [], a = 1 + 1);
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
14+
|
15+
= note: this error originates in 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:3
19+
|
20+
LL | println!("{:?} {:?} {a} {a:?}", [], [], a = 1 + 1);
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
22+
|
23+
= note: this error originates in 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:3
27+
|
28+
LL | println!("{:?} {:?} {a} {a:?} {b:?}", [], [], a = 1 + 1, b = []);
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
30+
|
31+
= note: this error originates in 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:22:3
35+
|
36+
LL | / println!("
37+
LL | | {:?} {:?}
38+
LL | | {a}
39+
LL | | {a:?}",
40+
LL | | [],
41+
LL | | [],
42+
LL | | a = 1 + 1);
43+
| |__________^ cannot infer type
44+
|
45+
= note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
46+
47+
error: aborting due to 5 previous errors
48+
49+
For more information about this error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)