Skip to content

Commit e2c6d0f

Browse files
committed
Just suggest positional arg and adjust issue0139104 ui test
Signed-off-by: xizheyin <[email protected]>
1 parent 64867c6 commit e2c6d0f

File tree

3 files changed

+85
-47
lines changed

3 files changed

+85
-47
lines changed

compiler/rustc_parse_format/src/lib.rs

-18
Original file line numberDiff line numberDiff line change
@@ -967,24 +967,6 @@ impl<'a> Parser<'a> {
967967
};
968968
}
969969
}
970-
} else if matches!(arg.position, ArgumentNamed(_) | ArgumentIs(_)) {
971-
let arg_name = match arg.position {
972-
ArgumentNamed(arg_name) => &format!("`{arg_name}`"),
973-
ArgumentIs(arg_index) => &format!("at index `{arg_index}`"),
974-
_ => unreachable!(),
975-
};
976-
977-
self.errors.insert(
978-
0,
979-
ParseError {
980-
description: format!("invalid format string for argument {}", arg_name),
981-
note: None,
982-
label: format!("invalid format specifier for this argument"),
983-
span: InnerSpan::new(arg.position_span.start, arg.position_span.end),
984-
secondary_label: None,
985-
suggestion: Suggestion::None,
986-
},
987-
);
988970
}
989971
}
990972

Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
fn main() {
2-
println!("{foo:_1.4}", foo = 3.14); //~ ERROR invalid format string: invalid format string for argument `foo`
3-
println!("{foo:1.4_1.4}", foo = 3.14); //~ ERROR invalid format string: invalid format string for argument `foo`
4-
println!("xxx{0:_1.4}", 1.11); //~ ERROR invalid format string: invalid format string for argument at index `0`
5-
println!("{foo:_1.4", foo = 3.14); //~ ERROR invalid format string: invalid format string for argument `foo`
6-
println!("xxx{0:_1.4", 1.11); //~ ERROR invalid format string: invalid format string for argument at index `0`
7-
println!("xxx{ 0", 1.11); //~ ERROR invalid format string: expected `}`, found `0`
2+
println!("{foo:_1.4}", foo = 3.14); //~ ERROR invalid format string: expected `}`, found `.`
3+
println!("{0:_1.4}", 1.11); //~ ERROR invalid format string: expected `}`, found `.`
4+
println!("{:_1.4}", 3.14); //~ ERROR invalid format string: expected `}`, found `.`
5+
6+
println!("{foo:_1.4", foo = 3.14); //~ ERROR invalid format string: expected `}`, found `.`
7+
println!("{0:_1.4", 1.11); //~ ERROR invalid format string: expected `}`, found `.`
8+
println!("{:_1.4", 3.14); //~ ERROR invalid format string: expected `}`, found `.`
9+
10+
println!("{ 0", 1.11); //~ ERROR invalid format string: expected `}`, found `0`
11+
println!("{foo:1.4_1.4}", foo = 3.14); //~ ERROR invalid format string: expected `}`, found `.`
12+
println!("{0:1.4_1.4}", 3.14); //~ ERROR invalid format string: expected `}`, found `.`
13+
814
}
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,92 @@
1-
error: invalid format string: invalid format string for argument `foo`
2-
--> $DIR/invalid-parse-format-issue-139104.rs:2:16
1+
error: invalid format string: expected `}`, found `.`
2+
--> $DIR/invalid-parse-format-issue-139104.rs:2:22
33
|
44
LL | println!("{foo:_1.4}", foo = 3.14);
5-
| ^^^ invalid format specifier for this argument in format string
5+
| - ^ expected `}` in format string
6+
| |
7+
| because of this opening brace
8+
|
9+
= note: if you intended to print `{`, you can escape it using `{{`
610

7-
error: invalid format string: invalid format string for argument `foo`
8-
--> $DIR/invalid-parse-format-issue-139104.rs:3:16
11+
error: invalid format string: expected `}`, found `.`
12+
--> $DIR/invalid-parse-format-issue-139104.rs:3:20
913
|
10-
LL | println!("{foo:1.4_1.4}", foo = 3.14);
11-
| ^^^ invalid format specifier for this argument in format string
14+
LL | println!("{0:_1.4}", 1.11);
15+
| - ^ expected `}` in format string
16+
| |
17+
| because of this opening brace
18+
|
19+
= note: if you intended to print `{`, you can escape it using `{{`
1220

13-
error: invalid format string: invalid format string for argument at index `0`
21+
error: invalid format string: expected `}`, found `.`
1422
--> $DIR/invalid-parse-format-issue-139104.rs:4:19
1523
|
16-
LL | println!("xxx{0:_1.4}", 1.11);
17-
| ^ invalid format specifier for this argument in format string
24+
LL | println!("{:_1.4}", 3.14);
25+
| - ^ expected `}` in format string
26+
| |
27+
| because of this opening brace
28+
|
29+
= note: if you intended to print `{`, you can escape it using `{{`
1830

19-
error: invalid format string: invalid format string for argument `foo`
20-
--> $DIR/invalid-parse-format-issue-139104.rs:5:16
31+
error: invalid format string: expected `}`, found `.`
32+
--> $DIR/invalid-parse-format-issue-139104.rs:6:22
2133
|
2234
LL | println!("{foo:_1.4", foo = 3.14);
23-
| ^^^ invalid format specifier for this argument in format string
35+
| - ^ expected `}` in format string
36+
| |
37+
| because of this opening brace
38+
|
39+
= note: if you intended to print `{`, you can escape it using `{{`
40+
41+
error: invalid format string: expected `}`, found `.`
42+
--> $DIR/invalid-parse-format-issue-139104.rs:7:20
43+
|
44+
LL | println!("{0:_1.4", 1.11);
45+
| - ^ expected `}` in format string
46+
| |
47+
| because of this opening brace
48+
|
49+
= note: if you intended to print `{`, you can escape it using `{{`
2450

25-
error: invalid format string: invalid format string for argument at index `0`
26-
--> $DIR/invalid-parse-format-issue-139104.rs:6:19
51+
error: invalid format string: expected `}`, found `.`
52+
--> $DIR/invalid-parse-format-issue-139104.rs:8:19
53+
|
54+
LL | println!("{:_1.4", 3.14);
55+
| - ^ expected `}` in format string
56+
| |
57+
| because of this opening brace
2758
|
28-
LL | println!("xxx{0:_1.4", 1.11);
29-
| ^ invalid format specifier for this argument in format string
59+
= note: if you intended to print `{`, you can escape it using `{{`
3060

3161
error: invalid format string: expected `}`, found `0`
32-
--> $DIR/invalid-parse-format-issue-139104.rs:7:21
62+
--> $DIR/invalid-parse-format-issue-139104.rs:10:18
63+
|
64+
LL | println!("{ 0", 1.11);
65+
| - ^ expected `}` in format string
66+
| |
67+
| because of this opening brace
68+
|
69+
= note: if you intended to print `{`, you can escape it using `{{`
70+
71+
error: invalid format string: expected `}`, found `.`
72+
--> $DIR/invalid-parse-format-issue-139104.rs:11:25
73+
|
74+
LL | println!("{foo:1.4_1.4}", foo = 3.14);
75+
| - ^ expected `}` in format string
76+
| |
77+
| because of this opening brace
78+
|
79+
= note: if you intended to print `{`, you can escape it using `{{`
80+
81+
error: invalid format string: expected `}`, found `.`
82+
--> $DIR/invalid-parse-format-issue-139104.rs:12:23
3383
|
34-
LL | println!("xxx{ 0", 1.11);
35-
| - ^ expected `}` in format string
36-
| |
37-
| because of this opening brace
84+
LL | println!("{0:1.4_1.4}", 3.14);
85+
| - ^ expected `}` in format string
86+
| |
87+
| because of this opening brace
3888
|
3989
= note: if you intended to print `{`, you can escape it using `{{`
4090

41-
error: aborting due to 6 previous errors
91+
error: aborting due to 9 previous errors
4292

0 commit comments

Comments
 (0)