]> git.lizzy.rs Git - rust.git/blob - src/test/ui/generics/wrong-number-of-args.rs
Rollup merge of #98640 - cuviper:stable-rust-analyzer, r=Mark-Simulacrum
[rust.git] / src / test / 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
124     type C = Box<dyn GenericLifetime<'static, 'static>>;
125     //~^ ERROR this trait takes 1 lifetime argument but 2 lifetime arguments were supplied
126     //~| HELP remove
127
128     type D = Box<dyn GenericType>;
129     //~^ ERROR missing generics for trait `GenericType`
130     //~| HELP add missing
131
132     type E = Box<dyn GenericType<String, usize>>;
133     //~^ ERROR this trait takes 1 generic argument but 2 generic arguments
134     //~| HELP remove
135
136     type F = Box<dyn GenericLifetime<>>;
137     //~^ ERROR missing lifetime specifier
138     //~| HELP consider introducing
139
140     type G = Box<dyn GenericType<>>;
141     //~^ ERROR this trait takes 1 generic argument but 0 generic arguments
142     //~| HELP add missing
143 }
144
145 mod associated_item {
146     mod non_generic {
147         trait NonGenericAT {
148             type AssocTy;
149         }
150
151         type A = Box<dyn NonGenericAT<usize, AssocTy=()>>;
152         //~^ ERROR this trait takes 0 generic arguments but 1 generic argument
153         //~| HELP remove
154     }
155
156     mod lifetime {
157         trait GenericLifetimeAT<'a> {
158             type AssocTy;
159         }
160
161         type A = Box<dyn GenericLifetimeAT<AssocTy=()>>;
162         //~^ ERROR missing lifetime specifier
163         //~| HELP consider introducing
164
165         type B = Box<dyn GenericLifetimeAT<'static, 'static, AssocTy=()>>;
166         //~^ ERROR this trait takes 1 lifetime argument but 2 lifetime arguments were supplied
167         //~| HELP remove
168
169         type C = Box<dyn GenericLifetimeAT<(), AssocTy=()>>;
170         //~^ ERROR missing lifetime specifier
171         //~| HELP consider introducing
172         //~| ERROR this trait takes 0 generic arguments but 1 generic argument
173         //~| HELP remove
174     }
175
176     mod r#type {
177         trait GenericTypeAT<A> {
178             type AssocTy;
179         }
180
181         type A = Box<dyn GenericTypeAT<AssocTy=()>>;
182         //~^ ERROR this trait takes 1 generic argument but 0 generic arguments
183         //~| HELP add missing
184
185         type B = Box<dyn GenericTypeAT<(), (), AssocTy=()>>;
186         //~^ ERROR this trait takes 1 generic argument but 2 generic arguments
187         //~| HELP remove
188
189         type C = Box<dyn GenericTypeAT<'static, AssocTy=()>>;
190         //~^ ERROR this trait takes 1 generic argument but 0 generic arguments
191         //~| HELP add missing
192         //~| ERROR this trait takes 0 lifetime arguments but 1 lifetime argument was supplied
193         //~| HELP remove
194     }
195
196     mod lifetime_and_type {
197         trait GenericLifetimeTypeAT<'a, A> {
198             type AssocTy;
199         }
200
201         type A = Box<dyn GenericLifetimeTypeAT<AssocTy=()>>;
202         //~^ ERROR this trait takes 1 generic argument but 0 generic arguments
203         //~| HELP add missing
204         //~| ERROR missing lifetime specifier
205         //~| HELP consider introducing
206
207         type B = Box<dyn GenericLifetimeTypeAT<'static, AssocTy=()>>;
208         //~^ ERROR this trait takes 1 generic argument but 0 generic arguments were supplied
209         //~| HELP add missing
210
211         type C = Box<dyn GenericLifetimeTypeAT<'static, 'static, AssocTy=()>>;
212         //~^ ERROR this trait takes 1 lifetime argument but 2 lifetime arguments were supplied
213         //~| HELP remove
214         //~| ERROR this trait takes 1 generic argument but 0 generic arguments
215         //~| HELP add missing
216
217         type D = Box<dyn GenericLifetimeTypeAT<(), AssocTy=()>>;
218         //~^ ERROR missing lifetime specifier
219         //~| HELP consider introducing
220
221         type E = Box<dyn GenericLifetimeTypeAT<(), (), AssocTy=()>>;
222         //~^ ERROR missing lifetime specifier
223         //~| HELP consider introducing
224         //~| ERROR this trait takes 1 generic argument but 2 generic arguments
225         //~| HELP remove
226
227         type F = Box<dyn GenericLifetimeTypeAT<'static, 'static, (), AssocTy=()>>;
228         //~^ ERROR this trait takes 1 lifetime argument but 2 lifetime arguments were supplied
229         //~| HELP remove
230
231         type G = Box<dyn GenericLifetimeTypeAT<'static, (), (), AssocTy=()>>;
232         //~^ ERROR this trait takes 1 generic argument but 2 generic arguments
233         //~| HELP remove
234
235         type H = Box<dyn GenericLifetimeTypeAT<'static, 'static, (), (), AssocTy=()>>;
236         //~^ ERROR this trait takes 1 lifetime argument but 2 lifetime arguments were supplied
237         //~| HELP remove
238         //~| ERROR this trait takes 1 generic argument but 2 generic arguments
239         //~| HELP remove
240     }
241
242     mod type_and_type {
243         trait GenericTypeTypeAT<A, B> {
244             type AssocTy;
245         }
246
247         type A = Box<dyn GenericTypeTypeAT<AssocTy=()>>;
248         //~^ ERROR this trait takes 2 generic arguments but 0 generic arguments
249         //~| HELP add missing
250
251         type B = Box<dyn GenericTypeTypeAT<(), AssocTy=()>>;
252         //~^ ERROR this trait takes 2 generic arguments but 1 generic argument
253         //~| HELP add missing
254
255         type C = Box<dyn GenericTypeTypeAT<(), (), (), AssocTy=()>>;
256         //~^ ERROR this trait takes 2 generic arguments but 3 generic arguments
257         //~| HELP remove
258     }
259
260     mod lifetime_and_lifetime {
261         trait GenericLifetimeLifetimeAT<'a, 'b> {
262             type AssocTy;
263         }
264
265         type A = Box<dyn GenericLifetimeLifetimeAT<AssocTy=()>>;
266         //~^ ERROR missing lifetime specifier
267         //~| HELP consider introducing
268
269         type B = Box<dyn GenericLifetimeLifetimeAT<'static, AssocTy=()>>;
270         //~^ ERROR this trait takes 2 lifetime arguments but 1 lifetime argument was supplied
271         //~| HELP add missing lifetime argument
272     }
273
274     mod lifetime_and_lifetime_and_type {
275         trait GenericLifetimeLifetimeTypeAT<'a, 'b, A> {
276             type AssocTy;
277         }
278
279         type A = Box<dyn GenericLifetimeLifetimeTypeAT<AssocTy=()>>;
280         //~^ ERROR missing lifetime specifier
281         //~| HELP consider introducing
282         //~| ERROR this trait takes 1 generic argument but 0 generic arguments
283         //~| HELP add missing
284
285         type B = Box<dyn GenericLifetimeLifetimeTypeAT<'static, AssocTy=()>>;
286         //~^ ERROR this trait takes 2 lifetime arguments but 1 lifetime argument was supplied
287         //~| HELP add missing lifetime argument
288         //~| ERROR this trait takes 1 generic argument but 0 generic arguments
289         //~| HELP add missing
290
291         type C = Box<dyn GenericLifetimeLifetimeTypeAT<'static, (), AssocTy=()>>;
292         //~^ ERROR this trait takes 2 lifetime arguments but 1 lifetime argument was supplied
293         //~| HELP add missing lifetime argument
294     }
295 }
296
297 mod stdlib {
298     mod hash_map {
299         use std::collections::HashMap;
300
301         type A = HashMap;
302         //~^ ERROR missing generics for struct `HashMap`
303         //~| HELP add missing
304
305         type B = HashMap<String>;
306         //~^ ERROR this struct takes at least
307         //~| HELP add missing
308
309         type C = HashMap<'static>;
310         //~^ ERROR this struct takes 0 lifetime arguments but 1 lifetime argument
311         //~| HELP remove these generics
312         //~| ERROR this struct takes at least 2
313         //~| HELP add missing
314
315         type D = HashMap<usize, String, char, f64>;
316         //~^ ERROR this struct takes at most 3
317         //~| HELP remove this
318
319         type E = HashMap<>;
320         //~^ ERROR this struct takes at least 2 generic arguments but 0 generic arguments
321         //~| HELP add missing
322     }
323
324     mod result {
325         type A = Result;
326         //~^ ERROR missing generics for enum `Result`
327         //~| HELP add missing
328
329         type B = Result<String>;
330         //~^ ERROR this enum takes 2 generic arguments but 1 generic argument
331         //~| HELP add missing
332
333         type C = Result<'static>;
334         //~^ ERROR this enum takes 0 lifetime arguments but 1 lifetime argument
335         //~| HELP remove these generics
336         //~| ERROR this enum takes 2 generic arguments but 0 generic arguments
337         //~| HELP add missing
338
339         type D = Result<usize, String, char>;
340         //~^ ERROR this enum takes 2 generic arguments but 3 generic arguments
341         //~| HELP remove
342
343         type E = Result<>;
344         //~^ ERROR this enum takes 2 generic arguments but 0 generic arguments
345         //~| HELP add missing
346     }
347 }
348
349 fn main() { }