2 #![warn(clippy::useless_format)]
4 unused_tuple_struct_fields,
6 clippy::redundant_clone,
7 clippy::to_string_in_format_args,
8 clippy::needless_borrow,
9 clippy::uninlined_format_args
12 struct Foo(pub String);
15 ($($t:tt)*) => (Foo(format!($($t)*)))
21 format!("{{}} abc {{}}");
30 format!("{:?}", "foo"); // Don't warn about `Debug`.
31 format!("{:8}", "foo");
32 format!("{:width$}", "foo", width = 8);
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 format!("foo {}", arg);
42 format!("{} bar", arg);
44 // We don’t want to warn for non-string args; see issue #697.
48 format!("foo {}", 42);
49 format!("{} bar", 42);
51 // We only want to warn about `format!` itself.
53 println!("{}", "foo");
54 println!("foo {}", "foo");
56 println!("foo {}", 42);
58 // A `format!` inside a macro should not trigger a warning.
59 foo!("should not warn");
61 // Precision on string means slicing without panicking on size.
62 format!("{:.1}", "foo"); // Could be `"foo"[..1]`
63 format!("{:.10}", "foo"); // Could not be `"foo"[..10]`
64 format!("{:.prec$}", "foo", prec = 1);
65 format!("{:.prec$}", "foo", prec = 10);
67 format!("{}", 42.to_string());
68 let x = std::path::PathBuf::from("/bar/foo/qux");
69 format!("{}", x.display().to_string());
72 let a = "foo".to_string();
73 let _ = Some(format!("{}", a + "bar"));
75 // Wrap it with braces
76 let v: Vec<String> = vec!["foo".to_string(), "bar".to_string()];
77 let _s: String = format!("{}", &*v.join("\n"));
79 format!("prepend {:+}", "s");
83 let _ = format!("{x}");
84 let _ = format!("{x:?}"); // Don't lint on debug
85 let _ = format!("{y}", y = x);
89 let _ = format!("{abc}");
91 let _ = format!("{xx}");