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();
16 "foo {}\n\" bar".to_string();
19 format!("{:?}", "foo"); // Don't warn about `Debug`.
20 format!("{:8}", "foo");
21 format!("{:width$}", "foo", width = 8);
22 "foo".to_string(); // Warn when the format makes no difference.
23 "foo".to_string(); // Warn when the format makes no difference.
24 format!("foo {}", "bar");
25 format!("{} bar", "foo");
27 let arg: String = "".to_owned();
29 format!("{:?}", arg); // Don't warn about debug.
31 format!("{:width$}", arg, width = 8);
32 arg.to_string(); // Warn when the format makes no difference.
33 arg.to_string(); // Warn when the format makes no difference.
34 format!("foo {}", arg);
35 format!("{} bar", arg);
37 // We don’t want to warn for non-string args; see issue #697.
41 format!("foo {}", 42);
42 format!("{} bar", 42);
44 // We only want to warn about `format!` itself.
46 println!("{}", "foo");
47 println!("foo {}", "foo");
49 println!("foo {}", 42);
51 // A `format!` inside a macro should not trigger a warning.
52 foo!("should not warn");
54 // Precision on string means slicing without panicking on size.
55 format!("{:.1}", "foo"); // Could be `"foo"[..1]`
56 format!("{:.10}", "foo"); // Could not be `"foo"[..10]`
57 format!("{:.prec$}", "foo", prec = 1);
58 format!("{:.prec$}", "foo", prec = 10);
61 let x = std::path::PathBuf::from("/bar/foo/qux");
62 x.display().to_string();
65 let a = "foo".to_string();
66 let _ = Some(a + "bar");