]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/fmt/ifmt-bad-arg.rs
2 // bad arguments to the format! call
4 // bad number of arguments, see #44954 (originally #15780)
7 //~^ ERROR: 1 positional argument in format string, but no arguments were given
10 //~^ ERROR: invalid reference to positional argument 1 (there is 1 argument)
11 //~^^ ERROR: argument never used
14 //~^ ERROR: 2 positional arguments in format string, but no arguments were given
16 format
!("{0} {1}", 1);
17 //~^ ERROR: invalid reference to positional argument 1 (there is 1 argument)
19 format
!("{0} {1} {2}", 1, 2);
20 //~^ ERROR: invalid reference to positional argument 2 (there are 2 arguments)
22 format
!("{} {value} {} {}", 1, value
=2);
23 //~^ ERROR: invalid reference to positional argument 2 (there are 2 arguments)
24 format
!("{name} {value} {} {} {} {} {} {}", 0, name
=1, value
=2);
25 //~^ ERROR: invalid reference to positional arguments 3, 4 and 5 (there are 3 arguments)
27 format
!("{} {foo} {} {bar} {}", 1, 2, 3);
28 //~^ ERROR: cannot find value `foo` in this scope
29 //~^^ ERROR: cannot find value `bar` in this scope
31 format
!("{foo}"); //~ ERROR: cannot find value `foo` in this scope
32 format
!("", 1, 2); //~ ERROR: multiple unused formatting arguments
33 format
!("{}", 1, 2); //~ ERROR: argument never used
34 format
!("{1}", 1, 2); //~ ERROR: argument never used
35 format
!("{}", 1, foo
=2); //~ ERROR: named argument never used
36 format
!("{foo}", 1, foo
=2); //~ ERROR: argument never used
37 format
!("", foo
=2); //~ ERROR: named argument never used
38 format
!("{} {}", 1, 2, foo
=1, bar
=2); //~ ERROR: multiple unused formatting arguments
40 format
!("{foo}", foo
=1, foo
=2); //~ ERROR: duplicate argument
41 format
!("{foo} {} {}", foo
=1, 2); //~ ERROR: positional arguments cannot follow
43 // bad named arguments, #35082
45 format
!("{valuea} {valueb}", valuea
=5, valuec
=7);
46 //~^ ERROR cannot find value `valueb` in this scope
47 //~^^ ERROR named argument never used
49 // bad syntax of the format string
51 format
!("{"); //~ ERROR: expected `'}'` but string was terminated
53 format!("foo
} bar
"); //~ ERROR: unmatched `}` found
54 format!("foo
}"); //~ ERROR: unmatched `}` found
56 format!("foo
%s baz
", "bar
"); //~ ERROR: argument never used
63 //~^^^ ERROR: cannot find value `foo` in this scope
65 // bad syntax in format string with multiple newlines, #53836
66 format!("first number
: {}
76 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
77 //~^^ ERROR: invalid format string
78 println!("{} {:.*} {}
", 1, 3.2, 4);
79 //~^ ERROR 4 positional arguments in format string, but there are 3 arguments
80 //~| ERROR mismatched types
81 println!("{} {:07$.*} {}
", 1, 3.2, 4);
82 //~^ ERROR 4 positional arguments in format string, but there are 3 arguments
83 //~| ERROR mismatched types
84 println!("{} {:07$} {}
", 1, 3.2, 4);
85 //~^ ERROR invalid reference to positional argument 7 (there are 3 arguments)
86 println!("{:foo}
", 1); //~ ERROR unknown format trait `foo`
87 println!("{5} {:4$} {6:7$}
", 1);
88 //~^ ERROR invalid reference to positional arguments 4, 5, 6 and 7 (there is 1 argument)
90 // We used to ICE here because we tried to unconditionally access the first argument, which
93 //~^ ERROR 2 positional arguments in format string, but no arguments were given