1 #![warn(clippy::recursive_format_impl)]
3 clippy::borrow_deref_ref,
5 clippy::inherent_to_string_shadow_display,
6 clippy::to_string_in_format_args,
7 clippy::uninlined_format_args
29 impl fmt::Display for A {
30 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
31 write!(f, "{}", self.to_string())
42 // Doesn't trigger if to_string defined separately
43 // i.e. not using ToString trait (from Display)
44 fn to_string(&self) -> String {
45 String::from("I am C")
49 impl fmt::Display for C {
50 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
51 write!(f, "{}", self.to_string())
60 impl std::fmt::Display for D {
61 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
63 Self::E(string) => write!(f, "E {}", string.to_string()),
64 Self::F => write!(f, "F"),
69 // Check for use of self as Display, in Display impl
70 // Triggers on direct use of self
73 impl std::fmt::Display for G {
74 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79 // Triggers on reference to self
82 impl std::fmt::Display for H {
83 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
84 write!(f, "{}", &self)
88 impl std::fmt::Debug for H {
89 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
90 write!(f, "{:?}", &self)
94 // Triggers on multiple reference to self
97 impl std::fmt::Display for H2 {
98 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
99 write!(f, "{}", &&&self)
103 // Doesn't trigger on correct deref
106 impl std::ops::Deref for I {
109 fn deref(&self) -> &Self::Target {
114 impl std::fmt::Display for I {
115 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
116 write!(f, "{}", &**self)
120 impl std::fmt::Debug for I {
121 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
122 write!(f, "{:?}", &**self)
126 // Doesn't trigger on multiple correct deref
129 impl std::ops::Deref for I2 {
132 fn deref(&self) -> &Self::Target {
137 impl std::fmt::Display for I2 {
138 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
139 write!(f, "{}", **&&&**self)
143 // Doesn't trigger on multiple correct deref
146 impl std::ops::Deref for I3 {
149 fn deref(&self) -> &Self::Target {
154 impl std::fmt::Display for I3 {
155 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
156 write!(f, "{}", &&**&&&**self)
160 // Does trigger when deref resolves to self
163 impl std::ops::Deref for J {
166 fn deref(&self) -> &Self::Target {
171 impl std::fmt::Display for J {
172 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
173 write!(f, "{}", &*self)
177 impl std::fmt::Debug for J {
178 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
179 write!(f, "{:?}", &*self)
185 impl std::ops::Deref for J2 {
188 fn deref(&self) -> &Self::Target {
193 impl std::fmt::Display for J2 {
194 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
195 write!(f, "{}", *self)
201 impl std::ops::Deref for J3 {
204 fn deref(&self) -> &Self::Target {
209 impl std::fmt::Display for J3 {
210 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
211 write!(f, "{}", **&&*self)
217 impl std::ops::Deref for J4 {
220 fn deref(&self) -> &Self::Target {
225 impl std::fmt::Display for J4 {
226 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
227 write!(f, "{}", &&**&&*self)
231 // Doesn't trigger on Debug from Display
234 impl std::fmt::Debug for K {
235 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
240 impl std::fmt::Display for K {
241 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
242 write!(f, "{:?}", self)
246 // Doesn't trigger on Display from Debug
249 impl std::fmt::Debug for K2 {
250 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
251 write!(f, "{}", self)
255 impl std::fmt::Display for K2 {
256 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
261 // Doesn't trigger on struct fields
267 impl std::fmt::Display for L {
268 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
269 write!(f, "{},{}", self.field1, self.field2)
273 impl std::fmt::Debug for L {
274 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
275 write!(f, "{:?},{:?}", self.field1, self.field2)
279 // Doesn't trigger on nested enum matching
285 impl std::fmt::Display for Tree {
286 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
288 Tree::Leaf => write!(f, "*"),
289 Tree::Node(children) => {
291 for child in children.iter() {
292 write!(f, "{},", child)?;
300 impl std::fmt::Debug for Tree {
301 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
303 Tree::Leaf => write!(f, "*"),
304 Tree::Node(children) => {
306 for child in children.iter() {
307 write!(f, "{:?},", child)?;