5 clippy::redundant_clone,
6 clippy::to_string_in_format_args,
7 clippy::needless_borrow
9 #![warn(clippy::useless_format)]
11 struct Foo(pub String);
14 ($($t:tt)*) => (Foo(format!($($t)*)))
20 "{} abc {}".to_string();
24 let _ = String::new();
27 format!("{:?}", "foo"); // Don't warn about `Debug`.
28 format!("{:8}", "foo");
29 format!("{:width$}", "foo", width = 8);
30 "foo".to_string(); // Warn when the format makes no difference.
31 "foo".to_string(); // Warn when the format makes no difference.
32 format!("foo {}", "bar");
33 format!("{} bar", "foo");
35 let arg: String = "".to_owned();
37 format!("{:?}", arg); // Don't warn about debug.
39 format!("{:width$}", arg, width = 8);
40 arg.to_string(); // Warn when the format makes no difference.
41 arg.to_string(); // Warn when the format makes no difference.
42 format!("foo {}", arg);
43 format!("{} bar", arg);
45 // We don’t want to warn for non-string args; see issue #697.
49 format!("foo {}", 42);
50 format!("{} bar", 42);
52 // We only want to warn about `format!` itself.
54 println!("{}", "foo");
55 println!("foo {}", "foo");
57 println!("foo {}", 42);
59 // A `format!` inside a macro should not trigger a warning.
60 foo!("should not warn");
62 // Precision on string means slicing without panicking on size.
63 format!("{:.1}", "foo"); // Could be `"foo"[..1]`
64 format!("{:.10}", "foo"); // Could not be `"foo"[..10]`
65 format!("{:.prec$}", "foo", prec = 1);
66 format!("{:.prec$}", "foo", prec = 10);
69 let x = std::path::PathBuf::from("/bar/foo/qux");
70 x.display().to_string();
73 let a = "foo".to_string();
74 let _ = Some(a + "bar");
76 // Wrap it with braces
77 let v: Vec<String> = vec!["foo".to_string(), "bar".to_string()];
78 let _s: String = (&*v.join("\n")).to_string();
80 format!("prepend {:+}", "s");
84 let _ = x.to_string();
85 let _ = format!("{x:?}"); // Don't lint on debug
86 let _ = x.to_string();