From d5cb474f5761fd80b5d7ab7d43671dfbd534acce Mon Sep 17 00:00:00 2001 From: Tommy Ip Date: Mon, 6 Nov 2017 14:20:15 +0000 Subject: [PATCH] Add tests for new format! error message --- src/test/compile-fail/ifmt-bad-arg.rs | 47 ++++++++++++++------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/src/test/compile-fail/ifmt-bad-arg.rs b/src/test/compile-fail/ifmt-bad-arg.rs index a23b4b07741..336a0d825cb 100644 --- a/src/test/compile-fail/ifmt-bad-arg.rs +++ b/src/test/compile-fail/ifmt-bad-arg.rs @@ -11,36 +11,39 @@ fn main() { // bad arguments to the format! call - format!("{}"); //~ ERROR: invalid reference to argument + // bad number of arguments, see #44954 (originally #15780) - format!("{1}", 1); //~ ERROR: invalid reference to argument `1` - //~^ ERROR: argument never used - format!("{foo}"); //~ ERROR: no argument named `foo` + format!("{}"); + //~^ ERROR: 1 positional argument in format string, but no arguments were given - format!("", 1, 2); //~ ERROR: multiple unused formatting arguments - format!("{}", 1, 2); //~ ERROR: argument never used - format!("{1}", 1, 2); //~ ERROR: argument never used - format!("{}", 1, foo=2); //~ ERROR: named argument never used - format!("{foo}", 1, foo=2); //~ ERROR: argument never used - format!("", foo=2); //~ ERROR: named argument never used + format!("{1}", 1); + //~^ ERROR: 1 positional argument in format string, but there is only 1 argument + //~^^ ERROR: argument never used - format!("{foo}", foo=1, foo=2); //~ ERROR: duplicate argument - format!("", foo=1, 2); //~ ERROR: positional arguments cannot follow - - // bad number of arguments, see #15780 - - format!("{0}"); - //~^ ERROR invalid reference to argument `0` (no arguments given) + format!("{} {}"); + //~^ ERROR: 2 positional arguments in format string, but no arguments were given format!("{0} {1}", 1); - //~^ ERROR invalid reference to argument `1` (there is 1 argument) + //~^ ERROR: 2 positional arguments in format string, but there is only 1 argument format!("{0} {1} {2}", 1, 2); - //~^ ERROR invalid reference to argument `2` (there are 2 arguments) + //~^ ERROR: 3 positional arguments in format string, but there are only 2 arguments - format!("{0} {1}"); - //~^ ERROR invalid reference to argument `0` (no arguments given) - //~^^ ERROR invalid reference to argument `1` (no arguments given) + format!("{} {value} {} {}", 1, value=2); + //~^ ERROR: invalid reference to positional argument 2 (there are only 2 arguments) + format!("{name} {value} {} {} {} {} {} {}", 0, name=1, value=2); + //~^ ERROR: invalid reference to positional arguments 3, 4 and 5 (there are only 3 arguments) + + format!("{foo}"); //~ ERROR: no argument named `foo` + format!("", 1, 2); //~ ERROR: multiple unused formatting arguments + format!("{}", 1, 2); //~ ERROR: argument never used + format!("{1}", 1, 2); //~ ERROR: argument never used + format!("{}", 1, foo=2); //~ ERROR: named argument never used + format!("{foo}", 1, foo=2); //~ ERROR: argument never used + format!("", foo=2); //~ ERROR: named argument never used + + format!("{foo}", foo=1, foo=2); //~ ERROR: duplicate argument + format!("", foo=1, 2); //~ ERROR: positional arguments cannot follow // bad named arguments, #35082