enum-variant-generic-args: describe + account for unit variants.

This commit is contained in:
Mazdak Farrokhzad 2019-06-09 06:29:05 +02:00
parent 26f98fdf58
commit a70653ac7e
2 changed files with 130 additions and 30 deletions

View File

@ -1,4 +1,10 @@
enum Enum<T> { TSVariant(T), SVariant { v: T } } // 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 }
type Alias<T> = Enum<T>; type Alias<T> = Enum<T>;
type AliasFixed = Enum<()>; type AliasFixed = Enum<()>;
@ -30,6 +36,16 @@ impl<T> Enum<T> {
//~^^ ERROR type arguments are not allowed for this type [E0109] //~^^ ERROR type arguments are not allowed for this type [E0109]
//~^^^ ERROR mismatched types [E0308] //~^^^ ERROR mismatched types [E0308]
} }
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]
//~^^ ERROR type arguments are not allowed for this type [E0109]
}
} }
fn main() { fn main() {
@ -68,4 +84,22 @@ fn main() {
AliasFixed::<()>::SVariant::<()> { v: () }; AliasFixed::<()>::SVariant::<()> { v: () };
//~^ ERROR type arguments are not allowed for this type [E0109] //~^ ERROR type arguments are not allowed for this type [E0109]
//~^^ ERROR wrong number of type arguments: expected 0, found 1 [E0107] //~^^ ERROR wrong number of type arguments: expected 0, found 1 [E0107]
// 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;
//~^ ERROR wrong number of type arguments: expected 0, found 1 [E0107]
AliasFixed::<()>::UVariant::<()>;
//~^ ERROR type arguments are not allowed for this type [E0109]
//~^^ ERROR wrong number of type arguments: expected 0, found 1 [E0107]
} }

View File

@ -1,5 +1,5 @@
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/enum-variant-generic-args.rs:7:25 --> $DIR/enum-variant-generic-args.rs:13:25
| |
LL | Self::TSVariant(()); LL | Self::TSVariant(());
| ^^ expected type parameter, found () | ^^ expected type parameter, found ()
@ -8,19 +8,19 @@ LL | Self::TSVariant(());
found type `()` found type `()`
error[E0109]: type arguments are not allowed for this type error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:9:27 --> $DIR/enum-variant-generic-args.rs:15:27
| |
LL | Self::TSVariant::<()>(()); LL | Self::TSVariant::<()>(());
| ^^ type argument not allowed | ^^ type argument not allowed
error[E0109]: type arguments are not allowed for this type error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:11:16 --> $DIR/enum-variant-generic-args.rs:17:16
| |
LL | Self::<()>::TSVariant(()); LL | Self::<()>::TSVariant(());
| ^^ type argument not allowed | ^^ type argument not allowed
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/enum-variant-generic-args.rs:11:31 --> $DIR/enum-variant-generic-args.rs:17:31
| |
LL | Self::<()>::TSVariant(()); LL | Self::<()>::TSVariant(());
| ^^ expected type parameter, found () | ^^ expected type parameter, found ()
@ -29,19 +29,19 @@ LL | Self::<()>::TSVariant(());
found type `()` found type `()`
error[E0109]: type arguments are not allowed for this type error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:14:16 --> $DIR/enum-variant-generic-args.rs:20:16
| |
LL | Self::<()>::TSVariant::<()>(()); LL | Self::<()>::TSVariant::<()>(());
| ^^ type argument not allowed | ^^ type argument not allowed
error[E0109]: type arguments are not allowed for this type error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:14:33 --> $DIR/enum-variant-generic-args.rs:20:33
| |
LL | Self::<()>::TSVariant::<()>(()); LL | Self::<()>::TSVariant::<()>(());
| ^^ type argument not allowed | ^^ type argument not allowed
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/enum-variant-generic-args.rs:20:29 --> $DIR/enum-variant-generic-args.rs:26:29
| |
LL | Self::SVariant { v: () }; LL | Self::SVariant { v: () };
| ^^ expected type parameter, found () | ^^ expected type parameter, found ()
@ -50,13 +50,13 @@ LL | Self::SVariant { v: () };
found type `()` found type `()`
error[E0109]: type arguments are not allowed for this type error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:22:26 --> $DIR/enum-variant-generic-args.rs:28:26
| |
LL | Self::SVariant::<()> { v: () }; LL | Self::SVariant::<()> { v: () };
| ^^ type argument not allowed | ^^ type argument not allowed
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/enum-variant-generic-args.rs:22:35 --> $DIR/enum-variant-generic-args.rs:28:35
| |
LL | Self::SVariant::<()> { v: () }; LL | Self::SVariant::<()> { v: () };
| ^^ expected type parameter, found () | ^^ expected type parameter, found ()
@ -65,13 +65,13 @@ LL | Self::SVariant::<()> { v: () };
found type `()` found type `()`
error[E0109]: type arguments are not allowed for this type error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:25:16 --> $DIR/enum-variant-generic-args.rs:31:16
| |
LL | Self::<()>::SVariant { v: () }; LL | Self::<()>::SVariant { v: () };
| ^^ type argument not allowed | ^^ type argument not allowed
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/enum-variant-generic-args.rs:25:35 --> $DIR/enum-variant-generic-args.rs:31:35
| |
LL | Self::<()>::SVariant { v: () }; LL | Self::<()>::SVariant { v: () };
| ^^ expected type parameter, found () | ^^ expected type parameter, found ()
@ -80,19 +80,19 @@ LL | Self::<()>::SVariant { v: () };
found type `()` found type `()`
error[E0109]: type arguments are not allowed for this type error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:28:16 --> $DIR/enum-variant-generic-args.rs:34:16
| |
LL | Self::<()>::SVariant::<()> { v: () }; LL | Self::<()>::SVariant::<()> { v: () };
| ^^ type argument not allowed | ^^ type argument not allowed
error[E0109]: type arguments are not allowed for this type error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:28:32 --> $DIR/enum-variant-generic-args.rs:34:32
| |
LL | Self::<()>::SVariant::<()> { v: () }; LL | Self::<()>::SVariant::<()> { v: () };
| ^^ type argument not allowed | ^^ type argument not allowed
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/enum-variant-generic-args.rs:28:41 --> $DIR/enum-variant-generic-args.rs:34:41
| |
LL | Self::<()>::SVariant::<()> { v: () }; LL | Self::<()>::SVariant::<()> { v: () };
| ^^ expected type parameter, found () | ^^ expected type parameter, found ()
@ -101,90 +101,156 @@ LL | Self::<()>::SVariant::<()> { v: () };
found type `()` found type `()`
error[E0109]: type arguments are not allowed for this type error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:38:29 --> $DIR/enum-variant-generic-args.rs:41:26
|
LL | Self::UVariant::<()>;
| ^^ type argument not allowed
error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:43:16
|
LL | Self::<()>::UVariant;
| ^^ type argument not allowed
error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:45:16
|
LL | Self::<()>::UVariant::<()>;
| ^^ type argument not allowed
error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:45:32
|
LL | Self::<()>::UVariant::<()>;
| ^^ type argument not allowed
error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:54:29
| |
LL | Enum::<()>::TSVariant::<()>(()); LL | Enum::<()>::TSVariant::<()>(());
| ^^ type argument not allowed | ^^ type argument not allowed
error[E0109]: type arguments are not allowed for this type error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:41:24 --> $DIR/enum-variant-generic-args.rs:57:24
| |
LL | Alias::TSVariant::<()>(()); LL | Alias::TSVariant::<()>(());
| ^^ type argument not allowed | ^^ type argument not allowed
error[E0109]: type arguments are not allowed for this type error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:43:30 --> $DIR/enum-variant-generic-args.rs:59:30
| |
LL | Alias::<()>::TSVariant::<()>(()); LL | Alias::<()>::TSVariant::<()>(());
| ^^ type argument not allowed | ^^ type argument not allowed
error[E0109]: type arguments are not allowed for this type error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:46:29 --> $DIR/enum-variant-generic-args.rs:62:29
| |
LL | AliasFixed::TSVariant::<()>(()); LL | AliasFixed::TSVariant::<()>(());
| ^^ type argument not allowed | ^^ type argument not allowed
error[E0107]: wrong number of type arguments: expected 0, found 1 error[E0107]: wrong number of type arguments: expected 0, found 1
--> $DIR/enum-variant-generic-args.rs:48:18 --> $DIR/enum-variant-generic-args.rs:64:18
| |
LL | AliasFixed::<()>::TSVariant(()); LL | AliasFixed::<()>::TSVariant(());
| ^^ unexpected type argument | ^^ unexpected type argument
error[E0107]: wrong number of type arguments: expected 0, found 1 error[E0107]: wrong number of type arguments: expected 0, found 1
--> $DIR/enum-variant-generic-args.rs:50:18 --> $DIR/enum-variant-generic-args.rs:66:18
| |
LL | AliasFixed::<()>::TSVariant::<()>(()); LL | AliasFixed::<()>::TSVariant::<()>(());
| ^^ unexpected type argument | ^^ unexpected type argument
error[E0109]: type arguments are not allowed for this type error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:50:35 --> $DIR/enum-variant-generic-args.rs:66:35
| |
LL | AliasFixed::<()>::TSVariant::<()>(()); LL | AliasFixed::<()>::TSVariant::<()>(());
| ^^ type argument not allowed | ^^ type argument not allowed
error[E0109]: type arguments are not allowed for this type error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:56:28 --> $DIR/enum-variant-generic-args.rs:72:28
| |
LL | Enum::<()>::SVariant::<()> { v: () }; LL | Enum::<()>::SVariant::<()> { v: () };
| ^^ type argument not allowed | ^^ type argument not allowed
error[E0109]: type arguments are not allowed for this type error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:59:23 --> $DIR/enum-variant-generic-args.rs:75:23
| |
LL | Alias::SVariant::<()> { v: () }; LL | Alias::SVariant::<()> { v: () };
| ^^ type argument not allowed | ^^ type argument not allowed
error[E0109]: type arguments are not allowed for this type error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:61:29 --> $DIR/enum-variant-generic-args.rs:77:29
| |
LL | Alias::<()>::SVariant::<()> { v: () }; LL | Alias::<()>::SVariant::<()> { v: () };
| ^^ type argument not allowed | ^^ type argument not allowed
error[E0109]: type arguments are not allowed for this type error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:64:28 --> $DIR/enum-variant-generic-args.rs:80:28
| |
LL | AliasFixed::SVariant::<()> { v: () }; LL | AliasFixed::SVariant::<()> { v: () };
| ^^ type argument not allowed | ^^ type argument not allowed
error[E0107]: wrong number of type arguments: expected 0, found 1 error[E0107]: wrong number of type arguments: expected 0, found 1
--> $DIR/enum-variant-generic-args.rs:66:18 --> $DIR/enum-variant-generic-args.rs:82:18
| |
LL | AliasFixed::<()>::SVariant { v: () }; LL | AliasFixed::<()>::SVariant { v: () };
| ^^ unexpected type argument | ^^ unexpected type argument
error[E0107]: wrong number of type arguments: expected 0, found 1 error[E0107]: wrong number of type arguments: expected 0, found 1
--> $DIR/enum-variant-generic-args.rs:68:18 --> $DIR/enum-variant-generic-args.rs:84:18
| |
LL | AliasFixed::<()>::SVariant::<()> { v: () }; LL | AliasFixed::<()>::SVariant::<()> { v: () };
| ^^ unexpected type argument | ^^ unexpected type argument
error[E0109]: type arguments are not allowed for this type error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:68:34 --> $DIR/enum-variant-generic-args.rs:84:34
| |
LL | AliasFixed::<()>::SVariant::<()> { v: () }; LL | AliasFixed::<()>::SVariant::<()> { v: () };
| ^^ type argument not allowed | ^^ type argument not allowed
error: aborting due to 28 previous errors error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:90:28
|
LL | Enum::<()>::UVariant::<()>;
| ^^ type argument not allowed
error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:93:23
|
LL | Alias::UVariant::<()>;
| ^^ type argument not allowed
error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:95:29
|
LL | Alias::<()>::UVariant::<()>;
| ^^ type argument not allowed
error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:98:28
|
LL | AliasFixed::UVariant::<()>;
| ^^ type argument not allowed
error[E0107]: wrong number of type arguments: expected 0, found 1
--> $DIR/enum-variant-generic-args.rs:100:18
|
LL | AliasFixed::<()>::UVariant;
| ^^ unexpected type argument
error[E0107]: wrong number of type arguments: expected 0, found 1
--> $DIR/enum-variant-generic-args.rs:102:18
|
LL | AliasFixed::<()>::UVariant::<()>;
| ^^ unexpected type argument
error[E0109]: type arguments are not allowed for this type
--> $DIR/enum-variant-generic-args.rs:102:34
|
LL | AliasFixed::<()>::UVariant::<()>;
| ^^ type argument not allowed
error: aborting due to 39 previous errors
Some errors have detailed explanations: E0107, E0109, E0308. Some errors have detailed explanations: E0107, E0109, E0308.
For more information about an error, try `rustc --explain E0107`. For more information about an error, try `rustc --explain E0107`.