]> git.proxmox.com Git - rustc.git/blame - src/test/compile-fail/ifmt-bad-arg.rs
New upstream version 1.15.0+dfsg1
[rustc.git] / src / test / compile-fail / ifmt-bad-arg.rs
CommitLineData
1a4d82fc
JJ
1// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11fn main() {
12 // bad arguments to the format! call
13
14 format!("{}"); //~ ERROR: invalid reference to argument
15
16 format!("{1}", 1); //~ ERROR: invalid reference to argument `1`
17 //~^ ERROR: argument never used
18 format!("{foo}"); //~ ERROR: no argument named `foo`
19
476ff2be 20 format!("", 1, 2); //~ ERROR: multiple unused formatting arguments
1a4d82fc
JJ
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
26
1a4d82fc
JJ
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)
34
35 format!("{0} {1}", 1);
36 //~^ ERROR invalid reference to argument `1` (there is 1 argument)
37
38 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)
44
5bcae85e
SL
45 // bad named arguments, #35082
46
47 format!("{valuea} {valueb}", valuea=5, valuec=7);
48 //~^ ERROR there is no argument named `valueb`
49 //~^^ ERROR named argument never used
50
1a4d82fc
JJ
51 // bad syntax of the format string
52
53 format!("{"); //~ ERROR: expected `'}'` but string was terminated
54
55 format!("foo } bar"); //~ ERROR: unmatched `}` found
56 format!("foo }"); //~ ERROR: unmatched `}` found
476ff2be
SL
57
58 format!("foo %s baz", "bar"); //~ ERROR: argument never used
1a4d82fc 59}