]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/to_string_in_display.rs
Update (un)suspicious files
[rustc.git] / src / tools / clippy / tests / ui / to_string_in_display.rs
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 {
8 fn fmt(&self) {
9 self.to_string();
10 }
11 }
12
13 trait B {
14 fn fmt(&self) {}
15 }
16
17 impl B for A {
18 fn fmt(&self) {
19 self.to_string();
20 }
21 }
22
23 impl fmt::Display for A {
24 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25 write!(f, "{}", self.to_string())
26 }
27 }
28
29 fn fmt(a: A) {
30 a.to_string();
31 }
32
33 struct C;
34
35 impl C {
36 fn to_string(&self) -> String {
37 String::from("I am C")
38 }
39 }
40
41 impl fmt::Display for C {
42 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 {
53 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
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 }