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