]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/to_string_in_display.rs
New upstream version 1.52.1+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / to_string_in_display.rs
CommitLineData
f20569fa
XL
1#![warn(clippy::to_string_in_display)]
2#![allow(clippy::inherent_to_string_shadow_display)]
3
4use std::fmt;
5
6struct A;
7impl A {
8 fn fmt(&self) {
9 self.to_string();
10 }
11}
12
13trait B {
14 fn fmt(&self) {}
15}
16
17impl B for A {
18 fn fmt(&self) {
19 self.to_string();
20 }
21}
22
23impl fmt::Display for A {
24 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25 write!(f, "{}", self.to_string())
26 }
27}
28
29fn fmt(a: A) {
30 a.to_string();
31}
32
33struct C;
34
35impl C {
36 fn to_string(&self) -> String {
37 String::from("I am C")
38 }
39}
40
41impl fmt::Display for C {
42 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
43 write!(f, "{}", self.to_string())
44 }
45}
46
47enum D {
48 E(String),
49 F,
50}
51
52impl 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
61fn 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}