1 #![warn(clippy::to_string_in_display)]
2 #![allow(clippy::inherent_to_string_shadow_display, clippy::to_string_in_format_args)]
3 
4 use std::fmt;
5 
6 struct A;
7 impl A {
fmt(&self)8     fn fmt(&self) {
9         self.to_string();
10     }
11 }
12 
13 trait B {
fmt(&self)14     fn fmt(&self) {}
15 }
16 
17 impl B for A {
fmt(&self)18     fn fmt(&self) {
19         self.to_string();
20     }
21 }
22 
23 impl fmt::Display for A {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result24     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25         write!(f, "{}", self.to_string())
26     }
27 }
28 
fmt(a: A)29 fn fmt(a: A) {
30     a.to_string();
31 }
32 
33 struct C;
34 
35 impl C {
to_string(&self) -> String36     fn to_string(&self) -> String {
37         String::from("I am C")
38     }
39 }
40 
41 impl fmt::Display for C {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result42     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
43         write!(f, "{}", self.to_string())
44     }
45 }
46 
47 enum D {
48     E(String),
49     F,
50 }
51 
52 impl std::fmt::Display for D {
fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result53     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54         match &self {
55             Self::E(string) => write!(f, "E {}", string.to_string()),
56             Self::F => write!(f, "F"),
57         }
58     }
59 }
60 
main()61 fn main() {
62     let a = A;
63     a.to_string();
64     a.fmt();
65     fmt(a);
66 
67     let c = C;
68     c.to_string();
69 }
70