]> git.lizzy.rs Git - rust.git/blob - tests/ui/generics/wrong-number-of-args.rs
Rollup merge of #107576 - P1n3appl3:master, r=tmandry
[rust.git] / tests / ui / generics / wrong-number-of-args.rs
1 mod no_generics {
2     struct Ty;
3
4     type A = Ty;
5
6     type B = Ty<'static>;
7     //~^ ERROR this struct takes 0 lifetime arguments but 1 lifetime argument
8     //~| HELP remove these generics
9
10     type C = Ty<'static, usize>;
11     //~^ ERROR this struct takes 0 lifetime arguments but 1 lifetime argument
12     //~| ERROR this struct takes 0 generic arguments but 1 generic argument
13     //~| HELP remove this lifetime argument
14     //~| HELP remove this generic argument
15
16     type D = Ty<'static, usize, { 0 }>;
17     //~^ ERROR this struct takes 0 lifetime arguments but 1 lifetime argument
18     //~| ERROR this struct takes 0 generic arguments but 2 generic arguments
19     //~| HELP remove this lifetime argument
20     //~| HELP remove these generic arguments
21 }
22
23 mod type_and_type {
24     struct Ty<A, B>;
25
26     type A = Ty;
27     //~^ ERROR missing generics for struct `type_and_type::Ty`
28     //~| HELP add missing
29
30     type B = Ty<usize>;
31     //~^ ERROR this struct takes 2 generic arguments but 1 generic argument
32     //~| HELP add missing
33
34     type C = Ty<usize, String>;
35
36     type D = Ty<usize, String, char>;
37     //~^ ERROR this struct takes 2 generic arguments but 3 generic arguments
38     //~| HELP remove this
39
40     type E = Ty<>;
41     //~^ ERROR this struct takes 2 generic arguments but 0 generic arguments were supplied
42     //~| HELP add missing
43 }
44
45 mod lifetime_and_type {
46     struct Ty<'a, T>;
47
48     type A = Ty;
49     //~^ ERROR missing generics for struct
50     //~| ERROR missing lifetime specifier
51     //~| HELP add missing
52     //~| HELP consider introducing
53
54     type B = Ty<'static>;
55     //~^ ERROR this struct takes 1 generic argument but 0 generic arguments
56     //~| HELP add missing
57
58     type C = Ty<usize>;
59     //~^ ERROR missing lifetime specifier
60     //~| HELP consider introducing
61
62     type D = Ty<'static, usize>;
63
64     type E = Ty<>;
65     //~^ ERROR this struct takes 1 generic argument but 0 generic arguments
66     //~| ERROR missing lifetime specifier
67     //~| HELP consider introducing
68     //~| HELP add missing
69
70     type F = Ty<'static, usize, 'static, usize>;
71     //~^ ERROR this struct takes 1 lifetime argument but 2 lifetime arguments
72     //~| ERROR this struct takes 1 generic argument but 2 generic arguments
73     //~| HELP remove this lifetime argument
74     //~| HELP remove this generic argument
75 }
76
77 mod type_and_type_and_type {
78     struct Ty<A, B, C = &'static str>;
79
80     type A = Ty;
81     //~^ ERROR missing generics for struct `type_and_type_and_type::Ty`
82     //~| HELP add missing
83
84     type B = Ty<usize>;
85     //~^ ERROR this struct takes at least 2
86     //~| HELP add missing
87
88     type C = Ty<usize, String>;
89
90     type D = Ty<usize, String, char>;
91
92     type E = Ty<usize, String, char, f64>;
93     //~^ ERROR this struct takes at most 3
94     //~| HELP remove
95
96     type F = Ty<>;
97     //~^ ERROR this struct takes at least 2 generic arguments but 0 generic arguments
98     //~| HELP add missing
99 }
100
101 // Traits have an implicit `Self` type - these tests ensure we don't accidentally return it
102 // somewhere in the message
103 mod r#trait {
104     trait NonGeneric {
105         //
106     }
107
108     trait GenericLifetime<'a> {
109         //
110     }
111
112     trait GenericType<A> {
113         //
114     }
115
116     type A = Box<dyn NonGeneric<usize>>;
117     //~^ ERROR this trait takes 0 generic arguments but 1 generic argument
118     //~| HELP remove
119
120     type B = Box<dyn GenericLifetime>;
121     //~^ ERROR missing lifetime specifier
122     //~| HELP consider introducing
123     //~| HELP consider making the bound lifetime-generic
124
125     type C = Box<dyn GenericLifetime<'static, 'static>>;
126     //~^ ERROR this trait takes 1 lifetime argument but 2 lifetime arguments were supplied
127     //~| HELP remove
128
129     type D = Box<dyn GenericType>;
130     //~^ ERROR missing generics for trait `GenericType`
131     //~| HELP add missing
132
133     type E = Box<dyn GenericType<String, usize>>;
134     //~^ ERROR this trait takes 1 generic argument but 2 generic arguments
135     //~| HELP remove
136
137     type F = Box<dyn GenericLifetime<>>;
138     //~^ ERROR missing lifetime specifier
139     //~| HELP consider introducing
140     //~| HELP consider making the bound lifetime-generic
141
142     type G = Box<dyn GenericType<>>;
143     //~^ ERROR this trait takes 1 generic argument but 0 generic arguments
144     //~| HELP add missing
145 }
146
147 mod associated_item {
148     mod non_generic {
149         trait NonGenericAT {
150             type AssocTy;
151         }
152
153         type A = Box<dyn NonGenericAT<usize, AssocTy=()>>;
154         //~^ ERROR this trait takes 0 generic arguments but 1 generic argument
155         //~| HELP remove
156     }
157
158     mod lifetime {
159         trait GenericLifetimeAT<'a> {
160             type AssocTy;
161         }
162
163         type A = Box<dyn GenericLifetimeAT<AssocTy=()>>;
164         //~^ ERROR missing lifetime specifier
165         //~| HELP consider introducing
166         //~| HELP consider making the bound lifetime-generic
167
168         type B = Box<dyn GenericLifetimeAT<'static, 'static, AssocTy=()>>;
169         //~^ ERROR this trait takes 1 lifetime argument but 2 lifetime arguments were supplied
170         //~| HELP remove
171
172         type C = Box<dyn GenericLifetimeAT<(), AssocTy=()>>;
173         //~^ ERROR missing lifetime specifier
174         //~| HELP consider introducing
175         //~| HELP consider making the bound lifetime-generic
176         //~| ERROR this trait takes 0 generic arguments but 1 generic argument
177         //~| HELP remove
178     }
179
180     mod r#type {
181         trait GenericTypeAT<A> {
182             type AssocTy;
183         }
184
185         type A = Box<dyn GenericTypeAT<AssocTy=()>>;
186         //~^ ERROR this trait takes 1 generic argument but 0 generic arguments
187         //~| HELP add missing
188
189         type B = Box<dyn GenericTypeAT<(), (), AssocTy=()>>;
190         //~^ ERROR this trait takes 1 generic argument but 2 generic arguments
191         //~| HELP remove
192
193         type C = Box<dyn GenericTypeAT<'static, AssocTy=()>>;
194         //~^ ERROR this trait takes 1 generic argument but 0 generic arguments
195         //~| HELP add missing
196         //~| ERROR this trait takes 0 lifetime arguments but 1 lifetime argument was supplied
197         //~| HELP remove
198     }
199
200     mod lifetime_and_type {
201         trait GenericLifetimeTypeAT<'a, A> {
202             type AssocTy;
203         }
204
205         type A = Box<dyn GenericLifetimeTypeAT<AssocTy=()>>;
206         //~^ ERROR this trait takes 1 generic argument but 0 generic arguments
207         //~| HELP add missing
208         //~| ERROR missing lifetime specifier
209         //~| HELP consider introducing
210         //~| HELP consider making the bound lifetime-generic
211
212         type B = Box<dyn GenericLifetimeTypeAT<'static, AssocTy=()>>;
213         //~^ ERROR this trait takes 1 generic argument but 0 generic arguments were supplied
214         //~| HELP add missing
215
216         type C = Box<dyn GenericLifetimeTypeAT<'static, 'static, AssocTy=()>>;
217         //~^ ERROR this trait takes 1 lifetime argument but 2 lifetime arguments were supplied
218         //~| HELP remove
219         //~| ERROR this trait takes 1 generic argument but 0 generic arguments
220         //~| HELP add missing
221
222         type D = Box<dyn GenericLifetimeTypeAT<(), AssocTy=()>>;
223         //~^ ERROR missing lifetime specifier
224         //~| HELP consider introducing
225         //~| HELP consider making the bound lifetime-generic
226
227         type E = Box<dyn GenericLifetimeTypeAT<(), (), AssocTy=()>>;
228         //~^ ERROR missing lifetime specifier
229         //~| HELP consider introducing
230         //~| HELP consider making the bound lifetime-generic
231         //~| ERROR this trait takes 1 generic argument but 2 generic arguments
232         //~| HELP remove
233
234         type F = Box<dyn GenericLifetimeTypeAT<'static, 'static, (), AssocTy=()>>;
235         //~^ ERROR this trait takes 1 lifetime argument but 2 lifetime arguments were supplied
236         //~| HELP remove
237
238         type G = Box<dyn GenericLifetimeTypeAT<'static, (), (), AssocTy=()>>;
239         //~^ ERROR this trait takes 1 generic argument but 2 generic arguments
240         //~| HELP remove
241
242         type H = Box<dyn GenericLifetimeTypeAT<'static, 'static, (), (), AssocTy=()>>;
243         //~^ ERROR this trait takes 1 lifetime argument but 2 lifetime arguments were supplied
244         //~| HELP remove
245         //~| ERROR this trait takes 1 generic argument but 2 generic arguments
246         //~| HELP remove
247     }
248
249     mod type_and_type {
250         trait GenericTypeTypeAT<A, B> {
251             type AssocTy;
252         }
253
254         type A = Box<dyn GenericTypeTypeAT<AssocTy=()>>;
255         //~^ ERROR this trait takes 2 generic arguments but 0 generic arguments
256         //~| HELP add missing
257
258         type B = Box<dyn GenericTypeTypeAT<(), AssocTy=()>>;
259         //~^ ERROR this trait takes 2 generic arguments but 1 generic argument
260         //~| HELP add missing
261
262         type C = Box<dyn GenericTypeTypeAT<(), (), (), AssocTy=()>>;
263         //~^ ERROR this trait takes 2 generic arguments but 3 generic arguments
264         //~| HELP remove
265     }
266
267     mod lifetime_and_lifetime {
268         trait GenericLifetimeLifetimeAT<'a, 'b> {
269             type AssocTy;
270         }
271
272         type A = Box<dyn GenericLifetimeLifetimeAT<AssocTy=()>>;
273         //~^ ERROR missing lifetime specifier
274         //~| HELP consider introducing
275         //~| HELP consider making the bound lifetime-generic
276
277         type B = Box<dyn GenericLifetimeLifetimeAT<'static, AssocTy=()>>;
278         //~^ ERROR this trait takes 2 lifetime arguments but 1 lifetime argument was supplied
279         //~| HELP add missing lifetime argument
280     }
281
282     mod lifetime_and_lifetime_and_type {
283         trait GenericLifetimeLifetimeTypeAT<'a, 'b, A> {
284             type AssocTy;
285         }
286
287         type A = Box<dyn GenericLifetimeLifetimeTypeAT<AssocTy=()>>;
288         //~^ ERROR missing lifetime specifier
289         //~| HELP consider introducing
290         //~| HELP consider making the bound lifetime-generic
291         //~| ERROR this trait takes 1 generic argument but 0 generic arguments
292         //~| HELP add missing
293
294         type B = Box<dyn GenericLifetimeLifetimeTypeAT<'static, AssocTy=()>>;
295         //~^ ERROR this trait takes 2 lifetime arguments but 1 lifetime argument was supplied
296         //~| HELP add missing lifetime argument
297         //~| ERROR this trait takes 1 generic argument but 0 generic arguments
298         //~| HELP add missing
299
300         type C = Box<dyn GenericLifetimeLifetimeTypeAT<'static, (), AssocTy=()>>;
301         //~^ ERROR this trait takes 2 lifetime arguments but 1 lifetime argument was supplied
302         //~| HELP add missing lifetime argument
303     }
304 }
305
306 mod stdlib {
307     mod hash_map {
308         use std::collections::HashMap;
309
310         type A = HashMap;
311         //~^ ERROR missing generics for struct `HashMap`
312         //~| HELP add missing
313
314         type B = HashMap<String>;
315         //~^ ERROR this struct takes at least
316         //~| HELP add missing
317
318         type C = HashMap<'static>;
319         //~^ ERROR this struct takes 0 lifetime arguments but 1 lifetime argument
320         //~| HELP remove these generics
321         //~| ERROR this struct takes at least 2
322         //~| HELP add missing
323
324         type D = HashMap<usize, String, char, f64>;
325         //~^ ERROR this struct takes at most 3
326         //~| HELP remove this
327
328         type E = HashMap<>;
329         //~^ ERROR this struct takes at least 2 generic arguments but 0 generic arguments
330         //~| HELP add missing
331     }
332
333     mod result {
334         type A = Result;
335         //~^ ERROR missing generics for enum `Result`
336         //~| HELP add missing
337
338         type B = Result<String>;
339         //~^ ERROR this enum takes 2 generic arguments but 1 generic argument
340         //~| HELP add missing
341
342         type C = Result<'static>;
343         //~^ ERROR this enum takes 0 lifetime arguments but 1 lifetime argument
344         //~| HELP remove these generics
345         //~| ERROR this enum takes 2 generic arguments but 0 generic arguments
346         //~| HELP add missing
347
348         type D = Result<usize, String, char>;
349         //~^ ERROR this enum takes 2 generic arguments but 3 generic arguments
350         //~| HELP remove
351
352         type E = Result<>;
353         //~^ ERROR this enum takes 2 generic arguments but 0 generic arguments
354         //~| HELP add missing
355     }
356 }
357
358 fn main() { }