enum-variant-generic-args.rs 4.3 KB
Newer Older
1 2 3 4 5 6 7
// Checks that applied type arguments of enums, and aliases to them, are respected.
// For example, `Self` is never a type constructor. Therefore, no types can be applied to it.
//
// We also check that the variant to an type-aliased enum cannot be type applied whether
// that alias is generic or monomorphic.

enum Enum<T> { TSVariant(T), SVariant { v: T }, UVariant }
8 9 10 11 12
type Alias<T> = Enum<T>;
type AliasFixed = Enum<()>;

impl<T> Enum<T> {
    fn ts_variant() {
13
        Self::TSVariant(());
14
        //~^ ERROR mismatched types [E0308]
15
        Self::TSVariant::<()>(());
V
varkor 已提交
16
        //~^ ERROR type arguments are not allowed for this type [E0109]
17
        Self::<()>::TSVariant(());
V
varkor 已提交
18
        //~^ ERROR type arguments are not allowed for this type [E0109]
19
        //~| ERROR mismatched types [E0308]
20
        Self::<()>::TSVariant::<()>(());
V
varkor 已提交
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: () };
V
varkor 已提交
29
        //~^ ERROR type arguments are not allowed for this type [E0109]
30
        //~| ERROR mismatched types [E0308]
31
        Self::<()>::SVariant { v: () };
V
varkor 已提交
32
        //~^ ERROR type arguments are not allowed for this type [E0109]
33
        //~| ERROR mismatched types [E0308]
34
        Self::<()>::SVariant::<()> { v: () };
V
varkor 已提交
35
        //~^ ERROR type arguments are not allowed for this type [E0109]
36 37
        //~| ERROR type arguments are not allowed for this type [E0109]
        //~| ERROR mismatched types [E0308]
38
    }
39 40 41 42 43 44 45 46

    fn u_variant() {
        Self::UVariant::<()>;
        //~^ ERROR type arguments are not allowed for this type [E0109]
        Self::<()>::UVariant;
        //~^ ERROR type arguments are not allowed for this type [E0109]
        Self::<()>::UVariant::<()>;
        //~^ 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 52 53 54
}

fn main() {
    // Tuple struct variant

    Enum::<()>::TSVariant::<()>(());
V
varkor 已提交
55
    //~^ ERROR type arguments are not allowed for this type [E0109]
56 57

    Alias::TSVariant::<()>(());
V
varkor 已提交
58
    //~^ ERROR type arguments are not allowed for this type [E0109]
59
    Alias::<()>::TSVariant::<()>(());
V
varkor 已提交
60
    //~^ ERROR type arguments are not allowed for this type [E0109]
61 62

    AliasFixed::TSVariant::<()>(());
V
varkor 已提交
63
    //~^ ERROR type arguments are not allowed for this type [E0109]
64
    AliasFixed::<()>::TSVariant(());
B
b-naber 已提交
65
    //~^ ERROR this type alias takes 0 generic arguments but 1 generic argument was supplied [E0107]
66
    AliasFixed::<()>::TSVariant::<()>(());
V
varkor 已提交
67
    //~^ ERROR type arguments are not allowed for this type [E0109]
B
b-naber 已提交
68
    //~| ERROR this type alias takes 0 generic arguments but 1 generic argument was supplied [E0107]
69 70 71

    // Struct variant

72
    Enum::<()>::SVariant::<()> { v: () };
V
varkor 已提交
73
    //~^ ERROR type arguments are not allowed for this type [E0109]
74

75
    Alias::SVariant::<()> { v: () };
V
varkor 已提交
76
    //~^ ERROR type arguments are not allowed for this type [E0109]
77
    Alias::<()>::SVariant::<()> { v: () };
V
varkor 已提交
78
    //~^ ERROR type arguments are not allowed for this type [E0109]
79

80
    AliasFixed::SVariant::<()> { v: () };
V
varkor 已提交
81
    //~^ ERROR type arguments are not allowed for this type [E0109]
82
    AliasFixed::<()>::SVariant { v: () };
B
b-naber 已提交
83
    //~^ ERROR this type alias takes 0 generic arguments but 1 generic argument was supplied [E0107]
84
    AliasFixed::<()>::SVariant::<()> { v: () };
V
varkor 已提交
85
    //~^ ERROR type arguments are not allowed for this type [E0109]
B
b-naber 已提交
86
    //~| ERROR this type alias takes 0 generic arguments but 1 generic argument was supplied [E0107]
87 88 89 90 91 92 93 94 95 96 97 98 99 100

    // Unit variant

    Enum::<()>::UVariant::<()>;
    //~^ ERROR type arguments are not allowed for this type [E0109]

    Alias::UVariant::<()>;
    //~^ ERROR type arguments are not allowed for this type [E0109]
    Alias::<()>::UVariant::<()>;
    //~^ ERROR type arguments are not allowed for this type [E0109]

    AliasFixed::UVariant::<()>;
    //~^ ERROR type arguments are not allowed for this type [E0109]
    AliasFixed::<()>::UVariant;
B
b-naber 已提交
101
    //~^ ERROR this type alias takes 0 generic arguments but 1 generic argument was supplied [E0107]
102 103
    AliasFixed::<()>::UVariant::<()>;
    //~^ ERROR type arguments are not allowed for this type [E0109]
B
b-naber 已提交
104
    //~| ERROR this type alias takes 0 generic arguments but 1 generic argument was supplied [E0107]
105
}