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 "{} 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 format!("foo {}", "bar");
32 format!("{} bar", "foo");
34 let arg = String::new();
36 format!("{:?}", arg); // Don't warn about debug.
38 format!("{:width$}", arg, width = 8);
39 format!("foo {}", arg);
40 format!("{} bar", arg);
42 // We don’t want to warn for non-string args; see issue #697.
46 format!("foo {}", 42);
47 format!("{} bar", 42);
49 // We only want to warn about `format!` itself.
51 println!("{}", "foo");
52 println!("foo {}", "foo");
54 println!("foo {}", 42);
56 // A `format!` inside a macro should not trigger a warning.
57 foo!("should not warn");
59 // Precision on string means slicing without panicking on size.
60 format!("{:.1}", "foo"); // Could be `"foo"[..1]`
61 format!("{:.10}", "foo"); // Could not be `"foo"[..10]`
62 format!("{:.prec$}", "foo", prec = 1);
63 format!("{:.prec$}", "foo", prec = 10);
66 let x = std::path::PathBuf::from("/bar/foo/qux");
67 x.display().to_string();
70 let a = "foo".to_string();
71 let _ = Some(a + "bar");
73 // Wrap it with braces
74 let v: Vec<String> = vec!["foo".to_string(), "bar".to_string()];
75 let _s: String = (&*v.join("\n")).to_string();
77 format!("prepend {:+}", "s");
81 let _ = x.to_string();
82 let _ = format!("{x:?}"); // Don't lint on debug
83 let _ = x.to_string();
87 let _ = abc.to_string();
89 let _ = xx.to_string();