Skip to content

Commit d5cb474

Browse files
committed
Add tests for new format! error message
1 parent 82d5ea4 commit d5cb474

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

src/test/compile-fail/ifmt-bad-arg.rs

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,39 @@
1111
fn main() {
1212
// bad arguments to the format! call
1313

14-
format!("{}"); //~ ERROR: invalid reference to argument
14+
// bad number of arguments, see #44954 (originally #15780)
1515

16-
format!("{1}", 1); //~ ERROR: invalid reference to argument `1`
17-
//~^ ERROR: argument never used
18-
format!("{foo}"); //~ ERROR: no argument named `foo`
16+
format!("{}");
17+
//~^ ERROR: 1 positional argument in format string, but no arguments were given
1918

20-
format!("", 1, 2); //~ ERROR: multiple unused formatting arguments
21-
format!("{}", 1, 2); //~ ERROR: argument never used
22-
format!("{1}", 1, 2); //~ ERROR: argument never used
23-
format!("{}", 1, foo=2); //~ ERROR: named argument never used
24-
format!("{foo}", 1, foo=2); //~ ERROR: argument never used
25-
format!("", foo=2); //~ ERROR: named argument never used
19+
format!("{1}", 1);
20+
//~^ ERROR: 1 positional argument in format string, but there is only 1 argument
21+
//~^^ ERROR: argument never used
2622

27-
format!("{foo}", foo=1, foo=2); //~ ERROR: duplicate argument
28-
format!("", foo=1, 2); //~ ERROR: positional arguments cannot follow
29-
30-
// bad number of arguments, see #15780
31-
32-
format!("{0}");
33-
//~^ ERROR invalid reference to argument `0` (no arguments given)
23+
format!("{} {}");
24+
//~^ ERROR: 2 positional arguments in format string, but no arguments were given
3425

3526
format!("{0} {1}", 1);
36-
//~^ ERROR invalid reference to argument `1` (there is 1 argument)
27+
//~^ ERROR: 2 positional arguments in format string, but there is only 1 argument
3728

3829
format!("{0} {1} {2}", 1, 2);
39-
//~^ ERROR invalid reference to argument `2` (there are 2 arguments)
40-
41-
format!("{0} {1}");
42-
//~^ ERROR invalid reference to argument `0` (no arguments given)
43-
//~^^ ERROR invalid reference to argument `1` (no arguments given)
30+
//~^ ERROR: 3 positional arguments in format string, but there are only 2 arguments
31+
32+
format!("{} {value} {} {}", 1, value=2);
33+
//~^ ERROR: invalid reference to positional argument 2 (there are only 2 arguments)
34+
format!("{name} {value} {} {} {} {} {} {}", 0, name=1, value=2);
35+
//~^ ERROR: invalid reference to positional arguments 3, 4 and 5 (there are only 3 arguments)
36+
37+
format!("{foo}"); //~ ERROR: no argument named `foo`
38+
format!("", 1, 2); //~ ERROR: multiple unused formatting arguments
39+
format!("{}", 1, 2); //~ ERROR: argument never used
40+
format!("{1}", 1, 2); //~ ERROR: argument never used
41+
format!("{}", 1, foo=2); //~ ERROR: named argument never used
42+
format!("{foo}", 1, foo=2); //~ ERROR: argument never used
43+
format!("", foo=2); //~ ERROR: named argument never used
44+
45+
format!("{foo}", foo=1, foo=2); //~ ERROR: duplicate argument
46+
format!("", foo=1, 2); //~ ERROR: positional arguments cannot follow
4447

4548
// bad named arguments, #35082
4649

0 commit comments

Comments
 (0)