]> git.proxmox.com Git - rustc.git/blob - src/test/ui/generics/wrong-number-of-args.rs
New upstream version 1.52.0~beta.3+dfsg1
[rustc.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 was supplied
8 //~| HELP remove these generics
9
10 type C = Ty<'static, usize>;
11 //~^ ERROR this struct takes 0 lifetime arguments but 1 lifetime argument was supplied
12 //~| ERROR this struct takes 0 type arguments but 1 type argument was supplied
13 //~| HELP remove this lifetime argument
14 //~| HELP remove this type argument
15
16 type D = Ty<'static, usize, { 0 }>;
17 //~^ ERROR this struct takes 0 lifetime arguments but 1 lifetime argument was supplied
18 //~| ERROR this struct takes 0 generic arguments but 2 generic arguments were supplied
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 use angle brackets
29
30 type B = Ty<usize>;
31 //~^ ERROR this struct takes 2 type arguments but only 1 type argument was supplied
32 //~| HELP add missing type argument
33
34 type C = Ty<usize, String>;
35
36 type D = Ty<usize, String, char>;
37 //~^ ERROR this struct takes 2 type arguments but 3 type arguments were supplied
38 //~| HELP remove this type argument
39 }
40
41 mod lifetime_and_type {
42 struct Ty<'a, T>;
43
44 type A = Ty;
45 //~^ ERROR missing generics for struct `lifetime_and_type::Ty`
46 //~| ERROR missing lifetime specifier
47 //~| HELP consider introducing
48 //~| HELP use angle brackets
49
50 type B = Ty<'static>;
51 //~^ ERROR this struct takes 1 type argument but 0 type arguments were supplied
52 //~| HELP add missing type argument
53
54 type C = Ty<usize>;
55 //~^ ERROR missing lifetime specifier
56 //~| HELP consider introducing
57
58 type D = Ty<'static, usize>;
59 }
60
61 mod type_and_type_and_type {
62 struct Ty<A, B, C = &'static str>;
63
64 type A = Ty;
65 //~^ ERROR missing generics for struct `type_and_type_and_type::Ty`
66 //~| HELP use angle brackets
67
68 type B = Ty<usize>;
69 //~^ ERROR this struct takes at least 2 type arguments but only 1 type argument was supplied
70 //~| HELP add missing type argument
71
72 type C = Ty<usize, String>;
73
74 type D = Ty<usize, String, char>;
75
76 type E = Ty<usize, String, char, f64>;
77 //~^ ERROR this struct takes at most 3 type arguments but 4 type arguments were supplied
78 //~| HELP remove
79 }
80
81 // Traits have an implicit `Self` type - these tests ensure we don't accidentally return it
82 // somewhere in the message
83 mod r#trait {
84 trait NonGeneric {
85 //
86 }
87
88 trait GenericLifetime<'a> {
89 //
90 }
91
92 trait GenericType<A> {
93 //
94 }
95
96 type A = Box<dyn NonGeneric<usize>>;
97 //~^ ERROR this trait takes 0 type arguments but 1 type argument was supplied
98 //~| HELP remove
99
100 type B = Box<dyn GenericLifetime>;
101 //~^ ERROR missing lifetime specifier
102 //~| HELP consider introducing
103
104 type C = Box<dyn GenericLifetime<'static, 'static>>;
105 //~^ ERROR this trait takes 1 lifetime argument but 2 lifetime arguments were supplied
106 //~| HELP remove
107
108 type D = Box<dyn GenericType>;
109 //~^ ERROR missing generics for trait `GenericType`
110 //~| HELP use angle brackets
111
112 type E = Box<dyn GenericType<String, usize>>;
113 //~^ ERROR this trait takes 1 type argument but 2 type arguments were supplied
114 //~| HELP remove
115 }
116
117 mod stdlib {
118 mod hash_map {
119 use std::collections::HashMap;
120
121 type A = HashMap;
122 //~^ ERROR missing generics for struct `HashMap`
123 //~| HELP use angle brackets
124
125 type B = HashMap<String>;
126 //~^ ERROR this struct takes at least 2 type arguments but only 1 type argument was supplied
127 //~| HELP add missing type argument
128
129 type C = HashMap<'static>;
130 //~^ ERROR this struct takes 0 lifetime arguments but 1 lifetime argument was supplied
131 //~| HELP remove these generics
132 //~| ERROR this struct takes at least 2 type arguments but 0 type arguments were supplied
133 //~| HELP add missing type arguments
134
135 type D = HashMap<usize, String, char, f64>;
136 //~^ ERROR this struct takes at most 3 type arguments but 4 type arguments were supplied
137 //~| HELP remove this type argument
138 }
139
140 mod result {
141 type A = Result;
142 //~^ ERROR missing generics for enum `Result`
143 //~| HELP use angle brackets
144
145 type B = Result<String>;
146 //~^ ERROR this enum takes 2 type arguments but only 1 type argument was supplied
147 //~| HELP add missing type argument
148
149 type C = Result<'static>;
150 //~^ ERROR this enum takes 0 lifetime arguments but 1 lifetime argument was supplied
151 //~| HELP remove these generics
152 //~| ERROR this enum takes 2 type arguments but 0 type arguments were supplied
153 //~| HELP add missing type arguments
154
155 type D = Result<usize, String, char>;
156 //~^ ERROR this enum takes 2 type arguments but 3 type arguments were supplied
157 //~| HELP remove
158 }
159 }
160
161 fn main() { }