1 #![warn(clippy::recursive_format_impl)]
3 clippy::inherent_to_string_shadow_display,
4 clippy::to_string_in_format_args,
27 impl fmt::Display for A {
28 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
29 write!(f, "{}", self.to_string())
40 // Doesn't trigger if to_string defined separately
41 // i.e. not using ToString trait (from Display)
42 fn to_string(&self) -> String {
43 String::from("I am C")
47 impl fmt::Display for C {
48 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
49 write!(f, "{}", self.to_string())
58 impl std::fmt::Display for D {
59 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61 Self::E(string) => write!(f, "E {}", string.to_string()),
62 Self::F => write!(f, "F"),
67 // Check for use of self as Display, in Display impl
68 // Triggers on direct use of self
71 impl std::fmt::Display for G {
72 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
77 // Triggers on reference to self
80 impl std::fmt::Display for H {
81 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
82 write!(f, "{}", &self)
86 impl std::fmt::Debug for H {
87 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
88 write!(f, "{:?}", &self)
92 // Triggers on multiple reference to self
95 impl std::fmt::Display for H2 {
96 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
97 write!(f, "{}", &&&self)
101 // Doesn't trigger on correct deref
104 impl std::ops::Deref for I {
107 fn deref(&self) -> &Self::Target {
112 impl std::fmt::Display for I {
113 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
114 write!(f, "{}", &**self)
118 impl std::fmt::Debug for I {
119 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
120 write!(f, "{:?}", &**self)
124 // Doesn't trigger on multiple correct deref
127 impl std::ops::Deref for I2 {
130 fn deref(&self) -> &Self::Target {
135 impl std::fmt::Display for I2 {
136 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
137 write!(f, "{}", **&&&**self)
141 // Doesn't trigger on multiple correct deref
144 impl std::ops::Deref for I3 {
147 fn deref(&self) -> &Self::Target {
152 impl std::fmt::Display for I3 {
153 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
154 write!(f, "{}", &&**&&&**self)
158 // Does trigger when deref resolves to self
161 impl std::ops::Deref for J {
164 fn deref(&self) -> &Self::Target {
169 impl std::fmt::Display for J {
170 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
171 write!(f, "{}", &*self)
175 impl std::fmt::Debug for J {
176 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
177 write!(f, "{:?}", &*self)
183 impl std::ops::Deref for J2 {
186 fn deref(&self) -> &Self::Target {
191 impl std::fmt::Display for J2 {
192 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
193 write!(f, "{}", *self)
199 impl std::ops::Deref for J3 {
202 fn deref(&self) -> &Self::Target {
207 impl std::fmt::Display for J3 {
208 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
209 write!(f, "{}", **&&*self)
215 impl std::ops::Deref for J4 {
218 fn deref(&self) -> &Self::Target {
223 impl std::fmt::Display for J4 {
224 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
225 write!(f, "{}", &&**&&*self)
229 // Doesn't trigger on Debug from Display
232 impl std::fmt::Debug for K {
233 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
238 impl std::fmt::Display for K {
239 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
240 write!(f, "{:?}", self)
244 // Doesn't trigger on Display from Debug
247 impl std::fmt::Debug for K2 {
248 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
249 write!(f, "{}", self)
253 impl std::fmt::Display for K2 {
254 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
259 // Doesn't trigger on struct fields
265 impl std::fmt::Display for L {
266 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
267 write!(f, "{},{}", self.field1, self.field2)
271 impl std::fmt::Debug for L {
272 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
273 write!(f, "{:?},{:?}", self.field1, self.field2)
277 // Doesn't trigger on nested enum matching
283 impl std::fmt::Display for Tree {
284 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
286 Tree::Leaf => write!(f, "*"),
287 Tree::Node(children) => {
289 for child in children.iter() {
290 write!(f, "{},", child)?;
298 impl std::fmt::Debug for Tree {
299 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
301 Tree::Leaf => write!(f, "*"),
302 Tree::Node(children) => {
304 for child in children.iter() {
305 write!(f, "{:?},", child)?;