]> git.lizzy.rs Git - rust.git/blob - tests/ui/new_ret_no_self.rs
Merge branch 'master' into rustfmt_tests
[rust.git] / tests / ui / new_ret_no_self.rs
1 #![warn(clippy::new_ret_no_self)]
2 #![allow(dead_code, clippy::trivially_copy_pass_by_ref)]
3
4 fn main() {}
5
6 trait R {
7     type Item;
8 }
9
10 trait Q {
11     type Item;
12     type Item2;
13 }
14
15 struct S;
16
17 impl R for S {
18     type Item = Self;
19 }
20
21 impl S {
22     // should not trigger the lint
23     pub fn new() -> impl R<Item = Self> {
24         S
25     }
26 }
27
28 struct S2;
29
30 impl R for S2 {
31     type Item = Self;
32 }
33
34 impl S2 {
35     // should not trigger the lint
36     pub fn new(_: String) -> impl R<Item = Self> {
37         S2
38     }
39 }
40
41 struct S3;
42
43 impl R for S3 {
44     type Item = u32;
45 }
46
47 impl S3 {
48     // should trigger the lint
49     pub fn new(_: String) -> impl R<Item = u32> {
50         S3
51     }
52 }
53
54 struct S4;
55
56 impl Q for S4 {
57     type Item = u32;
58     type Item2 = Self;
59 }
60
61 impl S4 {
62     // should not trigger the lint
63     pub fn new(_: String) -> impl Q<Item = u32, Item2 = Self> {
64         S4
65     }
66 }
67
68 struct T;
69
70 impl T {
71     // should not trigger lint
72     pub fn new() -> Self {
73         unimplemented!();
74     }
75 }
76
77 struct U;
78
79 impl U {
80     // should trigger lint
81     pub fn new() -> u32 {
82         unimplemented!();
83     }
84 }
85
86 struct V;
87
88 impl V {
89     // should trigger lint
90     pub fn new(_: String) -> u32 {
91         unimplemented!();
92     }
93 }
94
95 struct TupleReturnerOk;
96
97 impl TupleReturnerOk {
98     // should not trigger lint
99     pub fn new() -> (Self, u32) {
100         unimplemented!();
101     }
102 }
103
104 struct TupleReturnerOk2;
105
106 impl TupleReturnerOk2 {
107     // should not trigger lint (it doesn't matter which element in the tuple is Self)
108     pub fn new() -> (u32, Self) {
109         unimplemented!();
110     }
111 }
112
113 struct TupleReturnerOk3;
114
115 impl TupleReturnerOk3 {
116     // should not trigger lint (tuple can contain multiple Self)
117     pub fn new() -> (Self, Self) {
118         unimplemented!();
119     }
120 }
121
122 struct TupleReturnerBad;
123
124 impl TupleReturnerBad {
125     // should trigger lint
126     pub fn new() -> (u32, u32) {
127         unimplemented!();
128     }
129 }
130
131 struct MutPointerReturnerOk;
132
133 impl MutPointerReturnerOk {
134     // should not trigger lint
135     pub fn new() -> *mut Self {
136         unimplemented!();
137     }
138 }
139
140 struct MutPointerReturnerOk2;
141
142 impl MutPointerReturnerOk2 {
143     // should not trigger lint
144     pub fn new() -> *const Self {
145         unimplemented!();
146     }
147 }
148
149 struct MutPointerReturnerBad;
150
151 impl MutPointerReturnerBad {
152     // should trigger lint
153     pub fn new() -> *mut V {
154         unimplemented!();
155     }
156 }
157
158 struct GenericReturnerOk;
159
160 impl GenericReturnerOk {
161     // should not trigger lint
162     pub fn new() -> Option<Self> {
163         unimplemented!();
164     }
165 }
166
167 struct GenericReturnerBad;
168
169 impl GenericReturnerBad {
170     // should trigger lint
171     pub fn new() -> Option<u32> {
172         unimplemented!();
173     }
174 }
175
176 struct NestedReturnerOk;
177
178 impl NestedReturnerOk {
179     // should not trigger lint
180     pub fn new() -> (Option<Self>, u32) {
181         unimplemented!();
182     }
183 }
184
185 struct NestedReturnerOk2;
186
187 impl NestedReturnerOk2 {
188     // should not trigger lint
189     pub fn new() -> ((Self, u32), u32) {
190         unimplemented!();
191     }
192 }
193
194 struct NestedReturnerOk3;
195
196 impl NestedReturnerOk3 {
197     // should not trigger lint
198     pub fn new() -> Option<(Self, u32)> {
199         unimplemented!();
200     }
201 }