3 #![allow(unreachable_code)]
4 #![allow(unused_macros)]
5 #![allow(unused_variables)]
6 #![allow(clippy::assertions_on_constants)]
7 #![allow(clippy::eq_op)]
8 #![allow(clippy::print_literal)]
9 #![warn(clippy::to_string_in_format_args)]
11 use std::io::{stdout, Write};
13 use std::panic::Location;
17 impl ToString for Somewhere {
18 fn to_string(&self) -> String {
19 String::from("somewhere")
28 fn deref(&self) -> &u32 {
35 impl<'a> Deref for Y<'a> {
38 fn deref(&self) -> &Self::Target {
48 fn deref(&self) -> &u32 {
53 impl std::fmt::Display for Z {
54 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
59 macro_rules! my_macro {
61 // here be dragons, do not enter (or lint)
62 println!("error: something failed at {}", Location::caller().to_string());
66 macro_rules! my_other_macro {
68 Location::caller().to_string()
76 let _ = format!("error: something failed at {}", Location::caller());
79 "error: something failed at {}",
84 "error: something failed at {}",
87 print!("error: something failed at {}", Location::caller());
88 println!("error: something failed at {}", Location::caller());
89 eprint!("error: something failed at {}", Location::caller());
90 eprintln!("error: something failed at {}", Location::caller());
91 let _ = format_args!("error: something failed at {}", Location::caller());
92 assert!(true, "error: something failed at {}", Location::caller());
93 assert_eq!(0, 0, "error: something failed at {}", Location::caller());
94 assert_ne!(0, 0, "error: something failed at {}", Location::caller());
95 panic!("error: something failed at {}", Location::caller());
96 println!("{}", *X(1));
97 println!("{}", ***Y(&X(1)));
100 println!("{}", ***x_ref);
101 // https://github.com/rust-lang/rust-clippy/issues/7903
102 println!("{foo}{bar}", foo = "foo", bar = "bar");
103 println!("{foo}{bar}", foo = "foo", bar = "bar");
104 println!("{foo}{bar}", bar = "bar", foo = "foo");
105 println!("{foo}{bar}", bar = "bar", foo = "foo");
108 println!("error: something failed at {}", Somewhere.to_string());
109 // The next two tests are negative because caching the string might be faster than calling `<X as
110 // Display>::fmt` twice.
111 println!("{} and again {0}", x.to_string());
112 println!("{foo}{foo}", foo = "foo".to_string());
114 println!("error: something failed at {}", my_other_macro!());
115 // https://github.com/rust-lang/rust-clippy/issues/7903
116 println!("{foo}{foo:?}", foo = "foo".to_string());