]> git.lizzy.rs Git - rust.git/blob - tests/ui/format.rs
Merge pull request #2661 from devonhollowood/ptr-ptr-casts
[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"); // we only want to warn about `{}`
16     format!("{:+}", "foo"); // we only want to warn about `{}`
17     format!("foo {}", "bar");
18     format!("{} bar", "foo");
19
20     let arg: String = "".to_owned();
21     format!("{}", arg);
22     format!("{:?}", arg); // we only want to warn about `{}`
23     format!("{:+}", arg); // we only want to warn about `{}`
24     format!("foo {}", arg);
25     format!("{} bar", arg);
26
27     // we don’t want to warn for non-string args, see #697
28     format!("{}", 42);
29     format!("{:?}", 42);
30     format!("{:+}", 42);
31     format!("foo {}", 42);
32     format!("{} bar", 42);
33
34     // we only want to warn about `format!` itself
35     println!("foo");
36     println!("{}", "foo");
37     println!("foo {}", "foo");
38     println!("{}", 42);
39     println!("foo {}", 42);
40
41     // A format! inside a macro should not trigger a warning
42     foo!("should not warn");
43 }