1 #![allow(clippy::print_literal)]
2 #![warn(clippy::useless_format)]
4 struct Foo(pub String);
7 ($($t:tt)*) => (Foo(format!($($t)*)))
14 format!("{:?}", "foo"); // don't warn about debug
15 format!("{:8}", "foo");
16 format!("{:width$}", "foo", width = 8);
17 format!("{:+}", "foo"); // warn when the format makes no difference
18 format!("{:<}", "foo"); // warn when the format makes no difference
19 format!("foo {}", "bar");
20 format!("{} bar", "foo");
22 let arg: String = "".to_owned();
24 format!("{:?}", arg); // don't warn about debug
26 format!("{:width$}", arg, width = 8);
27 format!("{:+}", arg); // warn when the format makes no difference
28 format!("{:<}", arg); // warn when the format makes no difference
29 format!("foo {}", arg);
30 format!("{} bar", arg);
32 // we don’t want to warn for non-string args, see #697
36 format!("foo {}", 42);
37 format!("{} bar", 42);
39 // we only want to warn about `format!` itself
41 println!("{}", "foo");
42 println!("foo {}", "foo");
44 println!("foo {}", 42);
46 // A format! inside a macro should not trigger a warning
47 foo!("should not warn");
49 // precision on string means slicing without panicking on size:
50 format!("{:.1}", "foo"); // could be "foo"[..1]
51 format!("{:.10}", "foo"); // could not be "foo"[..10]
52 format!("{:.prec$}", "foo", prec = 1);
53 format!("{:.prec$}", "foo", prec = 10);
55 format!("{}", 42.to_string());
56 let x = std::path::PathBuf::from("/bar/foo/qux");
57 format!("{}", x.display().to_string());