]>
Commit | Line | Data |
---|---|---|
dc9dc135 XL |
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. | |
0731742a | 6 | |
dc9dc135 | 7 | enum Enum<T> { TSVariant(T), SVariant { v: T }, UVariant } |
0731742a XL |
8 | type Alias<T> = Enum<T>; |
9 | type AliasFixed = Enum<()>; | |
10 | ||
11 | impl<T> Enum<T> { | |
12 | fn ts_variant() { | |
13 | Self::TSVariant(()); | |
14 | //~^ ERROR mismatched types [E0308] | |
15 | Self::TSVariant::<()>(()); | |
532ac7d7 | 16 | //~^ ERROR type arguments are not allowed for this type [E0109] |
0731742a | 17 | Self::<()>::TSVariant(()); |
532ac7d7 | 18 | //~^ ERROR type arguments are not allowed for this type [E0109] |
5869c6ff | 19 | //~| ERROR mismatched types [E0308] |
0731742a | 20 | Self::<()>::TSVariant::<()>(()); |
532ac7d7 | 21 | //~^ ERROR type arguments are not allowed for this type [E0109] |
5869c6ff | 22 | //~| ERROR type arguments are not allowed for this type [E0109] |
0731742a XL |
23 | } |
24 | ||
25 | fn s_variant() { | |
26 | Self::SVariant { v: () }; | |
27 | //~^ ERROR mismatched types [E0308] | |
28 | Self::SVariant::<()> { v: () }; | |
532ac7d7 | 29 | //~^ ERROR type arguments are not allowed for this type [E0109] |
5869c6ff | 30 | //~| ERROR mismatched types [E0308] |
0731742a | 31 | Self::<()>::SVariant { v: () }; |
532ac7d7 | 32 | //~^ ERROR type arguments are not allowed for this type [E0109] |
5869c6ff | 33 | //~| ERROR mismatched types [E0308] |
0731742a | 34 | Self::<()>::SVariant::<()> { v: () }; |
532ac7d7 | 35 | //~^ ERROR type arguments are not allowed for this type [E0109] |
5869c6ff XL |
36 | //~| ERROR type arguments are not allowed for this type [E0109] |
37 | //~| ERROR mismatched types [E0308] | |
0731742a | 38 | } |
dc9dc135 XL |
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] | |
5869c6ff | 47 | //~| ERROR type arguments are not allowed for this type [E0109] |
dc9dc135 | 48 | } |
0731742a XL |
49 | } |
50 | ||
51 | fn main() { | |
52 | // Tuple struct variant | |
53 | ||
54 | Enum::<()>::TSVariant::<()>(()); | |
532ac7d7 | 55 | //~^ ERROR type arguments are not allowed for this type [E0109] |
0731742a XL |
56 | |
57 | Alias::TSVariant::<()>(()); | |
532ac7d7 | 58 | //~^ ERROR type arguments are not allowed for this type [E0109] |
0731742a | 59 | Alias::<()>::TSVariant::<()>(()); |
532ac7d7 | 60 | //~^ ERROR type arguments are not allowed for this type [E0109] |
0731742a XL |
61 | |
62 | AliasFixed::TSVariant::<()>(()); | |
532ac7d7 | 63 | //~^ ERROR type arguments are not allowed for this type [E0109] |
0731742a | 64 | AliasFixed::<()>::TSVariant(()); |
5869c6ff | 65 | //~^ ERROR this type alias takes 0 type arguments but 1 type argument was supplied [E0107] |
0731742a | 66 | AliasFixed::<()>::TSVariant::<()>(()); |
532ac7d7 | 67 | //~^ ERROR type arguments are not allowed for this type [E0109] |
5869c6ff | 68 | //~| ERROR this type alias takes 0 type arguments but 1 type argument was supplied [E0107] |
0731742a XL |
69 | |
70 | // Struct variant | |
71 | ||
72 | Enum::<()>::SVariant::<()> { v: () }; | |
532ac7d7 | 73 | //~^ ERROR type arguments are not allowed for this type [E0109] |
0731742a XL |
74 | |
75 | Alias::SVariant::<()> { v: () }; | |
532ac7d7 | 76 | //~^ ERROR type arguments are not allowed for this type [E0109] |
0731742a | 77 | Alias::<()>::SVariant::<()> { v: () }; |
532ac7d7 | 78 | //~^ ERROR type arguments are not allowed for this type [E0109] |
0731742a XL |
79 | |
80 | AliasFixed::SVariant::<()> { v: () }; | |
532ac7d7 | 81 | //~^ ERROR type arguments are not allowed for this type [E0109] |
0731742a | 82 | AliasFixed::<()>::SVariant { v: () }; |
5869c6ff | 83 | //~^ ERROR this type alias takes 0 type arguments but 1 type argument was supplied [E0107] |
0731742a | 84 | AliasFixed::<()>::SVariant::<()> { v: () }; |
532ac7d7 | 85 | //~^ ERROR type arguments are not allowed for this type [E0109] |
5869c6ff | 86 | //~| ERROR this type alias takes 0 type arguments but 1 type argument was supplied [E0107] |
dc9dc135 XL |
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; | |
5869c6ff | 101 | //~^ ERROR this type alias takes 0 type arguments but 1 type argument was supplied [E0107] |
dc9dc135 XL |
102 | AliasFixed::<()>::UVariant::<()>; |
103 | //~^ ERROR type arguments are not allowed for this type [E0109] | |
5869c6ff | 104 | //~| ERROR this type alias takes 0 type arguments but 1 type argument was supplied [E0107] |
0731742a | 105 | } |