1 #![warn(clippy::recursive_format_impl)]
3 clippy::inherent_to_string_shadow_display,
4 clippy::to_string_in_format_args,
6 clippy::borrow_deref_ref
28 impl fmt::Display for A {
29 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
30 write!(f, "{}", self.to_string())
41 // Doesn't trigger if to_string defined separately
42 // i.e. not using ToString trait (from Display)
43 fn to_string(&self) -> String {
44 String::from("I am C")
48 impl fmt::Display for C {
49 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
50 write!(f, "{}", self.to_string())
59 impl std::fmt::Display for D {
60 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62 Self::E(string) => write!(f, "E {}", string.to_string()),
63 Self::F => write!(f, "F"),
68 // Check for use of self as Display, in Display impl
69 // Triggers on direct use of self
72 impl std::fmt::Display for G {
73 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
78 // Triggers on reference to self
81 impl std::fmt::Display for H {
82 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
83 write!(f, "{}", &self)
87 impl std::fmt::Debug for H {
88 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
89 write!(f, "{:?}", &self)
93 // Triggers on multiple reference to self
96 impl std::fmt::Display for H2 {
97 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
98 write!(f, "{}", &&&self)
102 // Doesn't trigger on correct deref
105 impl std::ops::Deref for I {
108 fn deref(&self) -> &Self::Target {
113 impl std::fmt::Display for I {
114 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
115 write!(f, "{}", &**self)
119 impl std::fmt::Debug for I {
120 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
121 write!(f, "{:?}", &**self)
125 // Doesn't trigger on multiple correct deref
128 impl std::ops::Deref for I2 {
131 fn deref(&self) -> &Self::Target {
136 impl std::fmt::Display for I2 {
137 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
138 write!(f, "{}", **&&&**self)
142 // Doesn't trigger on multiple correct deref
145 impl std::ops::Deref for I3 {
148 fn deref(&self) -> &Self::Target {
153 impl std::fmt::Display for I3 {
154 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
155 write!(f, "{}", &&**&&&**self)
159 // Does trigger when deref resolves to self
162 impl std::ops::Deref for J {
165 fn deref(&self) -> &Self::Target {
170 impl std::fmt::Display for J {
171 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
172 write!(f, "{}", &*self)
176 impl std::fmt::Debug for J {
177 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
178 write!(f, "{:?}", &*self)
184 impl std::ops::Deref for J2 {
187 fn deref(&self) -> &Self::Target {
192 impl std::fmt::Display for J2 {
193 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
194 write!(f, "{}", *self)
200 impl std::ops::Deref for J3 {
203 fn deref(&self) -> &Self::Target {
208 impl std::fmt::Display for J3 {
209 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
210 write!(f, "{}", **&&*self)
216 impl std::ops::Deref for J4 {
219 fn deref(&self) -> &Self::Target {
224 impl std::fmt::Display for J4 {
225 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
226 write!(f, "{}", &&**&&*self)
230 // Doesn't trigger on Debug from Display
233 impl std::fmt::Debug for K {
234 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
239 impl std::fmt::Display for K {
240 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
241 write!(f, "{:?}", self)
245 // Doesn't trigger on Display from Debug
248 impl std::fmt::Debug for K2 {
249 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
250 write!(f, "{}", self)
254 impl std::fmt::Display for K2 {
255 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
260 // Doesn't trigger on struct fields
266 impl std::fmt::Display for L {
267 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
268 write!(f, "{},{}", self.field1, self.field2)
272 impl std::fmt::Debug for L {
273 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
274 write!(f, "{:?},{:?}", self.field1, self.field2)
278 // Doesn't trigger on nested enum matching
284 impl std::fmt::Display for Tree {
285 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
287 Tree::Leaf => write!(f, "*"),
288 Tree::Node(children) => {
290 for child in children.iter() {
291 write!(f, "{},", child)?;
299 impl std::fmt::Debug for Tree {
300 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
302 Tree::Leaf => write!(f, "*"),
303 Tree::Node(children) => {
305 for child in children.iter() {
306 write!(f, "{:?},", child)?;