3 #![allow(clippy::print_literal)]
4 #![warn(clippy::useless_format)]
6 struct Foo(pub String);
9 ($($t:tt)*) => (Foo(format!($($t)*)))
16 format!("{:?}", "foo"); // don't warn about debug
17 format!("{:8}", "foo");
18 format!("{:width$}", "foo", width = 8);
19 "foo".to_string(); // warn when the format makes no difference
20 "foo".to_string(); // warn when the format makes no difference
21 format!("foo {}", "bar");
22 format!("{} bar", "foo");
24 let arg: String = "".to_owned();
26 format!("{:?}", arg); // don't warn about debug
28 format!("{:width$}", arg, width = 8);
29 arg.to_string(); // warn when the format makes no difference
30 arg.to_string(); // warn when the format makes no difference
31 format!("foo {}", arg);
32 format!("{} bar", arg);
34 // we don’t want to warn for non-string args, see #697
38 format!("foo {}", 42);
39 format!("{} bar", 42);
41 // we only want to warn about `format!` itself
43 println!("{}", "foo");
44 println!("foo {}", "foo");
46 println!("foo {}", 42);
48 // A format! inside a macro should not trigger a warning
49 foo!("should not warn");
51 // precision on string means slicing without panicking on size:
52 format!("{:.1}", "foo"); // could be "foo"[..1]
53 format!("{:.10}", "foo"); // could not be "foo"[..10]
54 format!("{:.prec$}", "foo", prec = 1);
55 format!("{:.prec$}", "foo", prec = 10);
58 let x = std::path::PathBuf::from("/bar/foo/qux");
59 x.display().to_string();