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 format!("{{}} abc {{}}");
22 format!("{:?}", "foo"); // Don't warn about `Debug`.
23 format!("{:8}", "foo");
24 format!("{:width$}", "foo", width = 8);
25 format!("{:+}", "foo"); // Warn when the format makes no difference.
26 format!("{:<}", "foo"); // Warn when the format makes no difference.
27 format!("foo {}", "bar");
28 format!("{} bar", "foo");
30 let arg: String = "".to_owned();
32 format!("{:?}", arg); // Don't warn about debug.
34 format!("{:width$}", arg, width = 8);
35 format!("{:+}", arg); // Warn when the format makes no difference.
36 format!("{:<}", arg); // Warn when the format makes no difference.
37 format!("foo {}", arg);
38 format!("{} bar", arg);
40 // We don’t want to warn for non-string args; see issue #697.
44 format!("foo {}", 42);
45 format!("{} bar", 42);
47 // We only want to warn about `format!` itself.
49 println!("{}", "foo");
50 println!("foo {}", "foo");
52 println!("foo {}", 42);
54 // A `format!` inside a macro should not trigger a warning.
55 foo!("should not warn");
57 // Precision on string means slicing without panicking on size.
58 format!("{:.1}", "foo"); // Could be `"foo"[..1]`
59 format!("{:.10}", "foo"); // Could not be `"foo"[..10]`
60 format!("{:.prec$}", "foo", prec = 1);
61 format!("{:.prec$}", "foo", prec = 10);
63 format!("{}", 42.to_string());
64 let x = std::path::PathBuf::from("/bar/foo/qux");
65 format!("{}", x.display().to_string());
68 let a = "foo".to_string();
69 let _ = Some(format!("{}", a + "bar"));