Skip to content

Commit a70653a

Browse files
committed
enum-variant-generic-args: describe + account for unit variants.
1 parent 26f98fd commit a70653a

File tree

2 files changed

+130
-30
lines changed

2 files changed

+130
-30
lines changed

src/test/ui/type-alias-enum-variants/enum-variant-generic-args.rs

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
enum Enum<T> { TSVariant(T), SVariant { v: T } }
1+
// Checks that applied type arguments of enums, and aliases to them, are respected.
2+
// For example, `Self` is never a type constructor. Therefore, no types can be applied to it.
3+
//
4+
// We also check that the variant to an type-aliased enum cannot be type applied whether
5+
// that alias is generic or monomorphic.
6+
7+
enum Enum<T> { TSVariant(T), SVariant { v: T }, UVariant }
28
type Alias<T> = Enum<T>;
39
type AliasFixed = Enum<()>;
410

@@ -30,6 +36,16 @@ impl<T> Enum<T> {
3036
//~^^ ERROR type arguments are not allowed for this type [E0109]
3137
//~^^^ ERROR mismatched types [E0308]
3238
}
39+
40+
fn u_variant() {
41+
Self::UVariant::<()>;
42+
//~^ ERROR type arguments are not allowed for this type [E0109]
43+
Self::<()>::UVariant;
44+
//~^ ERROR type arguments are not allowed for this type [E0109]
45+
Self::<()>::UVariant::<()>;
46+
//~^ ERROR type arguments are not allowed for this type [E0109]
47+
//~^^ ERROR type arguments are not allowed for this type [E0109]
48+
}
3349
}
3450

3551
fn main() {
@@ -68,4 +84,22 @@ fn main() {
6884
AliasFixed::<()>::SVariant::<()> { v: () };
6985
//~^ ERROR type arguments are not allowed for this type [E0109]
7086
//~^^ ERROR wrong number of type arguments: expected 0, found 1 [E0107]
87+
88+
// Unit variant
89+
90+
Enum::<()>::UVariant::<()>;
91+
//~^ ERROR type arguments are not allowed for this type [E0109]
92+
93+
Alias::UVariant::<()>;
94+
//~^ ERROR type arguments are not allowed for this type [E0109]
95+
Alias::<()>::UVariant::<()>;
96+
//~^ ERROR type arguments are not allowed for this type [E0109]
97+
98+
AliasFixed::UVariant::<()>;
99+
//~^ ERROR type arguments are not allowed for this type [E0109]
100+
AliasFixed::<()>::UVariant;
101+
//~^ ERROR wrong number of type arguments: expected 0, found 1 [E0107]
102+
AliasFixed::<()>::UVariant::<()>;
103+
//~^ ERROR type arguments are not allowed for this type [E0109]
104+
//~^^ ERROR wrong number of type arguments: expected 0, found 1 [E0107]
71105
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/enum-variant-generic-args.rs:7:25
2+
--> $DIR/enum-variant-generic-args.rs:13:25
33
|
44
LL | Self::TSVariant(());
55
| ^^ expected type parameter, found ()
@@ -8,19 +8,19 @@ LL | Self::TSVariant(());
88
found type `()`
99

1010
error[E0109]: type arguments are not allowed for this type
11-
--> $DIR/enum-variant-generic-args.rs:9:27
11+
--> $DIR/enum-variant-generic-args.rs:15:27
1212
|
1313
LL | Self::TSVariant::<()>(());
1414
| ^^ type argument not allowed
1515

1616
error[E0109]: type arguments are not allowed for this type
17-
--> $DIR/enum-variant-generic-args.rs:11:16
17+
--> $DIR/enum-variant-generic-args.rs:17:16
1818
|
1919
LL | Self::<()>::TSVariant(());
2020
| ^^ type argument not allowed
2121

2222
error[E0308]: mismatched types
23-
--> $DIR/enum-variant-generic-args.rs:11:31
23+
--> $DIR/enum-variant-generic-args.rs:17:31
2424
|
2525
LL | Self::<()>::TSVariant(());
2626
| ^^ expected type parameter, found ()
@@ -29,19 +29,19 @@ LL | Self::<()>::TSVariant(());
2929
found type `()`
3030

3131
error[E0109]: type arguments are not allowed for this type
32-
--> $DIR/enum-variant-generic-args.rs:14:16
32+
--> $DIR/enum-variant-generic-args.rs:20:16
3333
|
3434
LL | Self::<()>::TSVariant::<()>(());
3535
| ^^ type argument not allowed
3636

3737
error[E0109]: type arguments are not allowed for this type
38-
--> $DIR/enum-variant-generic-args.rs:14:33
38+
--> $DIR/enum-variant-generic-args.rs:20:33
3939
|
4040
LL | Self::<()>::TSVariant::<()>(());
4141
| ^^ type argument not allowed
4242

4343
error[E0308]: mismatched types
44-
--> $DIR/enum-variant-generic-args.rs:20:29
44+
--> $DIR/enum-variant-generic-args.rs:26:29
4545
|
4646
LL | Self::SVariant { v: () };
4747
| ^^ expected type parameter, found ()
@@ -50,13 +50,13 @@ LL | Self::SVariant { v: () };
5050
found type `()`
5151

5252
error[E0109]: type arguments are not allowed for this type
53-
--> $DIR/enum-variant-generic-args.rs:22:26
53+
--> $DIR/enum-variant-generic-args.rs:28:26
5454
|
5555
LL | Self::SVariant::<()> { v: () };
5656
| ^^ type argument not allowed
5757

5858
error[E0308]: mismatched types
59-
--> $DIR/enum-variant-generic-args.rs:22:35
59+
--> $DIR/enum-variant-generic-args.rs:28:35
6060
|
6161
LL | Self::SVariant::<()> { v: () };
6262
| ^^ expected type parameter, found ()
@@ -65,13 +65,13 @@ LL | Self::SVariant::<()> { v: () };
6565
found type `()`
6666

6767
error[E0109]: type arguments are not allowed for this type
68-
--> $DIR/enum-variant-generic-args.rs:25:16
68+
--> $DIR/enum-variant-generic-args.rs:31:16
6969
|
7070
LL | Self::<()>::SVariant { v: () };
7171
| ^^ type argument not allowed
7272

7373
error[E0308]: mismatched types
74-
--> $DIR/enum-variant-generic-args.rs:25:35
74+
--> $DIR/enum-variant-generic-args.rs:31:35
7575
|
7676
LL | Self::<()>::SVariant { v: () };
7777
| ^^ expected type parameter, found ()
@@ -80,19 +80,19 @@ LL | Self::<()>::SVariant { v: () };
8080
found type `()`
8181

8282
error[E0109]: type arguments are not allowed for this type
83-
--> $DIR/enum-variant-generic-args.rs:28:16
83+
--> $DIR/enum-variant-generic-args.rs:34:16
8484
|
8585
LL | Self::<()>::SVariant::<()> { v: () };
8686
| ^^ type argument not allowed
8787

8888
error[E0109]: type arguments are not allowed for this type
89-
--> $DIR/enum-variant-generic-args.rs:28:32
89+
--> $DIR/enum-variant-generic-args.rs:34:32
9090
|
9191
LL | Self::<()>::SVariant::<()> { v: () };
9292
| ^^ type argument not allowed
9393

9494
error[E0308]: mismatched types
95-
--> $DIR/enum-variant-generic-args.rs:28:41
95+
--> $DIR/enum-variant-generic-args.rs:34:41
9696
|
9797
LL | Self::<()>::SVariant::<()> { v: () };
9898
| ^^ expected type parameter, found ()
@@ -101,90 +101,156 @@ LL | Self::<()>::SVariant::<()> { v: () };
101101
found type `()`
102102

103103
error[E0109]: type arguments are not allowed for this type
104-
--> $DIR/enum-variant-generic-args.rs:38:29
104+
--> $DIR/enum-variant-generic-args.rs:41:26
105+
|
106+
LL | Self::UVariant::<()>;
107+
| ^^ type argument not allowed
108+
109+
error[E0109]: type arguments are not allowed for this type
110+
--> $DIR/enum-variant-generic-args.rs:43:16
111+
|
112+
LL | Self::<()>::UVariant;
113+
| ^^ type argument not allowed
114+
115+
error[E0109]: type arguments are not allowed for this type
116+
--> $DIR/enum-variant-generic-args.rs:45:16
117+
|
118+
LL | Self::<()>::UVariant::<()>;
119+
| ^^ type argument not allowed
120+
121+
error[E0109]: type arguments are not allowed for this type
122+
--> $DIR/enum-variant-generic-args.rs:45:32
123+
|
124+
LL | Self::<()>::UVariant::<()>;
125+
| ^^ type argument not allowed
126+
127+
error[E0109]: type arguments are not allowed for this type
128+
--> $DIR/enum-variant-generic-args.rs:54:29
105129
|
106130
LL | Enum::<()>::TSVariant::<()>(());
107131
| ^^ type argument not allowed
108132

109133
error[E0109]: type arguments are not allowed for this type
110-
--> $DIR/enum-variant-generic-args.rs:41:24
134+
--> $DIR/enum-variant-generic-args.rs:57:24
111135
|
112136
LL | Alias::TSVariant::<()>(());
113137
| ^^ type argument not allowed
114138

115139
error[E0109]: type arguments are not allowed for this type
116-
--> $DIR/enum-variant-generic-args.rs:43:30
140+
--> $DIR/enum-variant-generic-args.rs:59:30
117141
|
118142
LL | Alias::<()>::TSVariant::<()>(());
119143
| ^^ type argument not allowed
120144

121145
error[E0109]: type arguments are not allowed for this type
122-
--> $DIR/enum-variant-generic-args.rs:46:29
146+
--> $DIR/enum-variant-generic-args.rs:62:29
123147
|
124148
LL | AliasFixed::TSVariant::<()>(());
125149
| ^^ type argument not allowed
126150

127151
error[E0107]: wrong number of type arguments: expected 0, found 1
128-
--> $DIR/enum-variant-generic-args.rs:48:18
152+
--> $DIR/enum-variant-generic-args.rs:64:18
129153
|
130154
LL | AliasFixed::<()>::TSVariant(());
131155
| ^^ unexpected type argument
132156

133157
error[E0107]: wrong number of type arguments: expected 0, found 1
134-
--> $DIR/enum-variant-generic-args.rs:50:18
158+
--> $DIR/enum-variant-generic-args.rs:66:18
135159
|
136160
LL | AliasFixed::<()>::TSVariant::<()>(());
137161
| ^^ unexpected type argument
138162

139163
error[E0109]: type arguments are not allowed for this type
140-
--> $DIR/enum-variant-generic-args.rs:50:35
164+
--> $DIR/enum-variant-generic-args.rs:66:35
141165
|
142166
LL | AliasFixed::<()>::TSVariant::<()>(());
143167
| ^^ type argument not allowed
144168

145169
error[E0109]: type arguments are not allowed for this type
146-
--> $DIR/enum-variant-generic-args.rs:56:28
170+
--> $DIR/enum-variant-generic-args.rs:72:28
147171
|
148172
LL | Enum::<()>::SVariant::<()> { v: () };
149173
| ^^ type argument not allowed
150174

151175
error[E0109]: type arguments are not allowed for this type
152-
--> $DIR/enum-variant-generic-args.rs:59:23
176+
--> $DIR/enum-variant-generic-args.rs:75:23
153177
|
154178
LL | Alias::SVariant::<()> { v: () };
155179
| ^^ type argument not allowed
156180

157181
error[E0109]: type arguments are not allowed for this type
158-
--> $DIR/enum-variant-generic-args.rs:61:29
182+
--> $DIR/enum-variant-generic-args.rs:77:29
159183
|
160184
LL | Alias::<()>::SVariant::<()> { v: () };
161185
| ^^ type argument not allowed
162186

163187
error[E0109]: type arguments are not allowed for this type
164-
--> $DIR/enum-variant-generic-args.rs:64:28
188+
--> $DIR/enum-variant-generic-args.rs:80:28
165189
|
166190
LL | AliasFixed::SVariant::<()> { v: () };
167191
| ^^ type argument not allowed
168192

169193
error[E0107]: wrong number of type arguments: expected 0, found 1
170-
--> $DIR/enum-variant-generic-args.rs:66:18
194+
--> $DIR/enum-variant-generic-args.rs:82:18
171195
|
172196
LL | AliasFixed::<()>::SVariant { v: () };
173197
| ^^ unexpected type argument
174198

175199
error[E0107]: wrong number of type arguments: expected 0, found 1
176-
--> $DIR/enum-variant-generic-args.rs:68:18
200+
--> $DIR/enum-variant-generic-args.rs:84:18
177201
|
178202
LL | AliasFixed::<()>::SVariant::<()> { v: () };
179203
| ^^ unexpected type argument
180204

181205
error[E0109]: type arguments are not allowed for this type
182-
--> $DIR/enum-variant-generic-args.rs:68:34
206+
--> $DIR/enum-variant-generic-args.rs:84:34
183207
|
184208
LL | AliasFixed::<()>::SVariant::<()> { v: () };
185209
| ^^ type argument not allowed
186210

187-
error: aborting due to 28 previous errors
211+
error[E0109]: type arguments are not allowed for this type
212+
--> $DIR/enum-variant-generic-args.rs:90:28
213+
|
214+
LL | Enum::<()>::UVariant::<()>;
215+
| ^^ type argument not allowed
216+
217+
error[E0109]: type arguments are not allowed for this type
218+
--> $DIR/enum-variant-generic-args.rs:93:23
219+
|
220+
LL | Alias::UVariant::<()>;
221+
| ^^ type argument not allowed
222+
223+
error[E0109]: type arguments are not allowed for this type
224+
--> $DIR/enum-variant-generic-args.rs:95:29
225+
|
226+
LL | Alias::<()>::UVariant::<()>;
227+
| ^^ type argument not allowed
228+
229+
error[E0109]: type arguments are not allowed for this type
230+
--> $DIR/enum-variant-generic-args.rs:98:28
231+
|
232+
LL | AliasFixed::UVariant::<()>;
233+
| ^^ type argument not allowed
234+
235+
error[E0107]: wrong number of type arguments: expected 0, found 1
236+
--> $DIR/enum-variant-generic-args.rs:100:18
237+
|
238+
LL | AliasFixed::<()>::UVariant;
239+
| ^^ unexpected type argument
240+
241+
error[E0107]: wrong number of type arguments: expected 0, found 1
242+
--> $DIR/enum-variant-generic-args.rs:102:18
243+
|
244+
LL | AliasFixed::<()>::UVariant::<()>;
245+
| ^^ unexpected type argument
246+
247+
error[E0109]: type arguments are not allowed for this type
248+
--> $DIR/enum-variant-generic-args.rs:102:34
249+
|
250+
LL | AliasFixed::<()>::UVariant::<()>;
251+
| ^^ type argument not allowed
252+
253+
error: aborting due to 39 previous errors
188254

189255
Some errors have detailed explanations: E0107, E0109, E0308.
190256
For more information about an error, try `rustc --explain E0107`.

0 commit comments

Comments
 (0)