]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/same_name_method.rs
Rollup merge of #100462 - zohnannor:master, r=thomcc
[rust.git] / src / tools / clippy / tests / ui / same_name_method.rs
1 #![feature(lint_reasons)]
2 #![warn(clippy::same_name_method)]
3 #![allow(dead_code, non_camel_case_types)]
4
5 trait T1 {
6     fn foo() {}
7 }
8
9 trait T2 {
10     fn foo() {}
11 }
12
13 mod should_lint {
14
15     mod test_basic_case {
16         use crate::T1;
17
18         struct S;
19
20         impl S {
21             fn foo() {}
22         }
23
24         impl T1 for S {
25             fn foo() {}
26         }
27     }
28
29     mod test_derive {
30
31         #[derive(Clone)]
32         struct S;
33
34         impl S {
35             fn clone() {}
36         }
37     }
38
39     mod with_generic {
40         use crate::T1;
41
42         struct S<U>(U);
43
44         impl<U> S<U> {
45             fn foo() {}
46         }
47
48         impl<U: Copy> T1 for S<U> {
49             fn foo() {}
50         }
51     }
52
53     mod default_method {
54         use crate::T1;
55
56         struct S;
57
58         impl S {
59             fn foo() {}
60         }
61
62         impl T1 for S {}
63     }
64
65     mod multiply_conflicit_trait {
66         use crate::{T1, T2};
67
68         struct S;
69
70         impl S {
71             fn foo() {}
72         }
73
74         impl T1 for S {}
75
76         impl T2 for S {}
77     }
78 }
79
80 mod should_not_lint {
81
82     mod not_lint_two_trait_method {
83         use crate::{T1, T2};
84
85         struct S;
86
87         impl T1 for S {
88             fn foo() {}
89         }
90
91         impl T2 for S {
92             fn foo() {}
93         }
94     }
95
96     mod only_lint_on_method {
97         trait T3 {
98             type foo;
99         }
100
101         struct S;
102
103         impl S {
104             fn foo() {}
105         }
106         impl T3 for S {
107             type foo = usize;
108         }
109     }
110 }
111
112 mod check_expect_suppression {
113     use crate::T1;
114
115     struct S;
116
117     impl S {
118         #[expect(clippy::same_name_method)]
119         fn foo() {}
120     }
121
122     impl T1 for S {
123         fn foo() {}
124     }
125 }
126
127 fn main() {}