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 format!("{:+}", "foo"); // Warn when the format makes no difference.
20 format!("{:<}", "foo"); // 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 format!("{:+}", arg); // Warn when the format makes no difference.
30 format!("{:<}", arg); // 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 issue #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);
57 format!("{}", 42.to_string());
58 let x = std::path::PathBuf::from("/bar/foo/qux");
59 format!("{}", x.display().to_string());