3 #![allow(clippy::print_literal)]
4 #![warn(clippy::useless_format)]
6 struct Foo(pub String);
9 ($($t:tt)*) => (Foo(format!($($t)*)))
15 "{} abc {}".to_string();
18 format!("{:?}", "foo"); // Don't warn about `Debug`.
19 format!("{:8}", "foo");
20 format!("{:width$}", "foo", width = 8);
21 "foo".to_string(); // Warn when the format makes no difference.
22 "foo".to_string(); // Warn when the format makes no difference.
23 format!("foo {}", "bar");
24 format!("{} bar", "foo");
26 let arg: String = "".to_owned();
28 format!("{:?}", arg); // Don't warn about debug.
30 format!("{:width$}", arg, width = 8);
31 arg.to_string(); // Warn when the format makes no difference.
32 arg.to_string(); // Warn when the format makes no difference.
33 format!("foo {}", arg);
34 format!("{} bar", arg);
36 // We don’t want to warn for non-string args; see issue #697.
40 format!("foo {}", 42);
41 format!("{} bar", 42);
43 // We only want to warn about `format!` itself.
45 println!("{}", "foo");
46 println!("foo {}", "foo");
48 println!("foo {}", 42);
50 // A `format!` inside a macro should not trigger a warning.
51 foo!("should not warn");
53 // Precision on string means slicing without panicking on size.
54 format!("{:.1}", "foo"); // Could be `"foo"[..1]`
55 format!("{:.10}", "foo"); // Could not be `"foo"[..10]`
56 format!("{:.prec$}", "foo", prec = 1);
57 format!("{:.prec$}", "foo", prec = 10);
60 let x = std::path::PathBuf::from("/bar/foo/qux");
61 x.display().to_string();