]> git.lizzy.rs Git - rust.git/blob - tests/ui/format.rs
Merge pull request #2984 from flip1995/single_char_pattern
[rust.git] / tests / ui / format.rs
1
2 #![allow(print_literal)]
3 #![warn(useless_format)]
4
5 struct Foo(pub String);
6
7 macro_rules! foo {
8   ($($t:tt)*) => (Foo(format!($($t)*)))
9 }
10
11 fn main() {
12     format!("foo");
13
14     format!("{}", "foo");
15     format!("{:?}", "foo"); // don't warn about debug
16     format!("{:8}", "foo");
17     format!("{:+}", "foo"); // warn when the format makes no difference
18     format!("{:<}", "foo"); // warn when the format makes no difference
19     format!("foo {}", "bar");
20     format!("{} bar", "foo");
21
22     let arg: String = "".to_owned();
23     format!("{}", arg);
24     format!("{:?}", arg); // don't warn about debug
25     format!("{:8}", arg);
26     format!("{:+}", arg); // warn when the format makes no difference
27     format!("{:<}", arg); // warn when the format makes no difference
28     format!("foo {}", arg);
29     format!("{} bar", arg);
30
31     // we don’t want to warn for non-string args, see #697
32     format!("{}", 42);
33     format!("{:?}", 42);
34     format!("{:+}", 42);
35     format!("foo {}", 42);
36     format!("{} bar", 42);
37
38     // we only want to warn about `format!` itself
39     println!("foo");
40     println!("{}", "foo");
41     println!("foo {}", "foo");
42     println!("{}", 42);
43     println!("foo {}", 42);
44
45     // A format! inside a macro should not trigger a warning
46     foo!("should not warn");
47 }