]> git.lizzy.rs Git - rust.git/blob - src/test/ui/type-alias-enum-variants/enum-variant-generic-args.rs
Rollup merge of #85174 - GuillaumeGomez:doc-code-block-border-radius, r=jsha
[rust.git] / src / test / ui / type-alias-enum-variants / enum-variant-generic-args.rs
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 }
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::<()>(());
16         //~^ ERROR type arguments are not allowed for this type [E0109]
17         Self::<()>::TSVariant(());
18         //~^ ERROR type arguments are not allowed for this type [E0109]
19         //~| ERROR mismatched types [E0308]
20         Self::<()>::TSVariant::<()>(());
21         //~^ ERROR type arguments are not allowed for this type [E0109]
22         //~| ERROR type arguments are not allowed for this type [E0109]
23     }
24
25     fn s_variant() {
26         Self::SVariant { v: () };
27         //~^ ERROR mismatched types [E0308]
28         Self::SVariant::<()> { v: () };
29         //~^ ERROR type arguments are not allowed for this type [E0109]
30         //~| ERROR mismatched types [E0308]
31         Self::<()>::SVariant { v: () };
32         //~^ ERROR type arguments are not allowed for this type [E0109]
33         //~| ERROR mismatched types [E0308]
34         Self::<()>::SVariant::<()> { v: () };
35         //~^ ERROR type arguments are not allowed for this type [E0109]
36         //~| ERROR type arguments are not allowed for this type [E0109]
37         //~| ERROR mismatched types [E0308]
38     }
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     }
49 }
50
51 fn main() {
52     // Tuple struct variant
53
54     Enum::<()>::TSVariant::<()>(());
55     //~^ ERROR type arguments are not allowed for this type [E0109]
56
57     Alias::TSVariant::<()>(());
58     //~^ ERROR type arguments are not allowed for this type [E0109]
59     Alias::<()>::TSVariant::<()>(());
60     //~^ ERROR type arguments are not allowed for this type [E0109]
61
62     AliasFixed::TSVariant::<()>(());
63     //~^ ERROR type arguments are not allowed for this type [E0109]
64     AliasFixed::<()>::TSVariant(());
65     //~^ ERROR this type alias takes 0 generic arguments but 1 generic argument was supplied [E0107]
66     AliasFixed::<()>::TSVariant::<()>(());
67     //~^ ERROR type arguments are not allowed for this type [E0109]
68     //~| ERROR this type alias takes 0 generic arguments but 1 generic argument was supplied [E0107]
69
70     // Struct variant
71
72     Enum::<()>::SVariant::<()> { v: () };
73     //~^ ERROR type arguments are not allowed for this type [E0109]
74
75     Alias::SVariant::<()> { v: () };
76     //~^ ERROR type arguments are not allowed for this type [E0109]
77     Alias::<()>::SVariant::<()> { v: () };
78     //~^ ERROR type arguments are not allowed for this type [E0109]
79
80     AliasFixed::SVariant::<()> { v: () };
81     //~^ ERROR type arguments are not allowed for this type [E0109]
82     AliasFixed::<()>::SVariant { v: () };
83     //~^ ERROR this type alias takes 0 generic arguments but 1 generic argument was supplied [E0107]
84     AliasFixed::<()>::SVariant::<()> { v: () };
85     //~^ ERROR type arguments are not allowed for this type [E0109]
86     //~| ERROR this type alias takes 0 generic arguments but 1 generic argument was supplied [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 this type alias takes 0 generic arguments but 1 generic argument was supplied [E0107]
102     AliasFixed::<()>::UVariant::<()>;
103     //~^ ERROR type arguments are not allowed for this type [E0109]
104     //~| ERROR this type alias takes 0 generic arguments but 1 generic argument was supplied [E0107]
105 }