4 unused_tuple_struct_fields,
6 clippy::redundant_clone,
7 clippy::to_string_in_format_args,
8 clippy::needless_borrow
10 #![warn(clippy::useless_format)]
12 struct Foo(pub String);
15 ($($t:tt)*) => (Foo(format!($($t)*)))
21 "{} abc {}".to_string();
25 let _ = String::new();
28 format!("{:?}", "foo"); // Don't warn about `Debug`.
29 format!("{:8}", "foo");
30 format!("{:width$}", "foo", width = 8);
31 "foo".to_string(); // Warn when the format makes no difference.
32 "foo".to_string(); // Warn when the format makes no difference.
33 format!("foo {}", "bar");
34 format!("{} bar", "foo");
36 let arg = String::new();
38 format!("{:?}", arg); // Don't warn about debug.
40 format!("{:width$}", arg, width = 8);
41 arg.to_string(); // Warn when the format makes no difference.
42 arg.to_string(); // Warn when the format makes no difference.
43 format!("foo {}", arg);
44 format!("{} bar", arg);
46 // We don’t want to warn for non-string args; see issue #697.
50 format!("foo {}", 42);
51 format!("{} bar", 42);
53 // We only want to warn about `format!` itself.
55 println!("{}", "foo");
56 println!("foo {}", "foo");
58 println!("foo {}", 42);
60 // A `format!` inside a macro should not trigger a warning.
61 foo!("should not warn");
63 // Precision on string means slicing without panicking on size.
64 format!("{:.1}", "foo"); // Could be `"foo"[..1]`
65 format!("{:.10}", "foo"); // Could not be `"foo"[..10]`
66 format!("{:.prec$}", "foo", prec = 1);
67 format!("{:.prec$}", "foo", prec = 10);
70 let x = std::path::PathBuf::from("/bar/foo/qux");
71 x.display().to_string();
74 let a = "foo".to_string();
75 let _ = Some(a + "bar");
77 // Wrap it with braces
78 let v: Vec<String> = vec!["foo".to_string(), "bar".to_string()];
79 let _s: String = (&*v.join("\n")).to_string();
81 format!("prepend {:+}", "s");
85 let _ = x.to_string();
86 let _ = format!("{x:?}"); // Don't lint on debug
87 let _ = x.to_string();
91 let _ = abc.to_string();
93 let _ = xx.to_string();