Added tests for enums & enum aliases with various combinations of generic args.
This commit is contained in:
parent
edabad64b0
commit
248dbbdffa
3 changed files with 139 additions and 0 deletions
34
src/test/run-pass/enum-generic-args.rs
Normal file
34
src/test/run-pass/enum-generic-args.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#![feature(irrefutable_let_patterns)]
|
||||
#![feature(type_alias_enum_variants)]
|
||||
|
||||
#![allow(irrefutable_let_patterns)]
|
||||
|
||||
enum Enum<T> { Variant(T) }
|
||||
type Alias<T> = Enum<T>;
|
||||
type AliasFixed = Enum<()>;
|
||||
|
||||
macro_rules! is_variant {
|
||||
($expr:expr) => (
|
||||
assert!(if let Enum::Variant::<()>(_) = $expr { true } else { false },
|
||||
"expr does not have correct type");
|
||||
)
|
||||
}
|
||||
|
||||
impl<T> Enum<T> {
|
||||
fn foo() {
|
||||
is_variant!(Self::Variant(()));
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
is_variant!(Enum::Variant(()));
|
||||
is_variant!(Enum::Variant::<()>(()));
|
||||
is_variant!(Enum::<()>::Variant(()));
|
||||
|
||||
is_variant!(Alias::Variant(()));
|
||||
is_variant!(Alias::<()>::Variant(()));
|
||||
|
||||
is_variant!(AliasFixed::Variant(()));
|
||||
|
||||
Enum::<()>::foo();
|
||||
}
|
||||
35
src/test/ui/enum-generic-args.rs
Normal file
35
src/test/ui/enum-generic-args.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#![feature(type_alias_enum_variants)]
|
||||
|
||||
enum Enum<T> { Variant(T) }
|
||||
type Alias<T> = Enum<T>;
|
||||
type AliasFixed = Enum<()>;
|
||||
|
||||
impl<T> Enum<T> {
|
||||
fn foo() {
|
||||
Self::Variant::<()>(());
|
||||
//~^ ERROR type parameters are not allowed on this type [E0109]
|
||||
Self::<()>::Variant(());
|
||||
//~^ ERROR type parameters are not allowed on this type [E0109]
|
||||
Self::<()>::Variant::<()>(());
|
||||
//~^ ERROR type parameters are not allowed on this type [E0109]
|
||||
//~^^ ERROR type parameters are not allowed on this type [E0109]
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
Enum::<()>::Variant::<()>(());
|
||||
//~^ ERROR type parameters are not allowed on this type [E0109]
|
||||
|
||||
Alias::Variant::<()>(());
|
||||
//~^ ERROR type parameters are not allowed on this type [E0109]
|
||||
Alias::<()>::Variant::<()>(());
|
||||
//~^ ERROR type parameters are not allowed on this type [E0109]
|
||||
|
||||
AliasFixed::Variant::<()>(());
|
||||
//~^ ERROR type parameters are not allowed on this type [E0109]
|
||||
AliasFixed::<()>::Variant(());
|
||||
//~^ ERROR wrong number of type arguments: expected 0, found 1 [E0107]
|
||||
AliasFixed::<()>::Variant::<()>(());
|
||||
//~^ ERROR type parameters are not allowed on this type [E0109]
|
||||
//~^^ ERROR wrong number of type arguments: expected 0, found 1 [E0107]
|
||||
}
|
||||
70
src/test/ui/enum-generic-args.stderr
Normal file
70
src/test/ui/enum-generic-args.stderr
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
error[E0109]: type parameters are not allowed on this type
|
||||
--> $DIR/enum-generic-args.rs:9:25
|
||||
|
|
||||
LL | Self::Variant::<()>(());
|
||||
| ^^ type parameter not allowed
|
||||
|
||||
error[E0109]: type parameters are not allowed on this type
|
||||
--> $DIR/enum-generic-args.rs:11:16
|
||||
|
|
||||
LL | Self::<()>::Variant(());
|
||||
| ^^ type parameter not allowed
|
||||
|
||||
error[E0109]: type parameters are not allowed on this type
|
||||
--> $DIR/enum-generic-args.rs:13:16
|
||||
|
|
||||
LL | Self::<()>::Variant::<()>(());
|
||||
| ^^ type parameter not allowed
|
||||
|
||||
error[E0109]: type parameters are not allowed on this type
|
||||
--> $DIR/enum-generic-args.rs:13:31
|
||||
|
|
||||
LL | Self::<()>::Variant::<()>(());
|
||||
| ^^ type parameter not allowed
|
||||
|
||||
error[E0109]: type parameters are not allowed on this type
|
||||
--> $DIR/enum-generic-args.rs:20:27
|
||||
|
|
||||
LL | Enum::<()>::Variant::<()>(());
|
||||
| ^^ type parameter not allowed
|
||||
|
||||
error[E0109]: type parameters are not allowed on this type
|
||||
--> $DIR/enum-generic-args.rs:23:22
|
||||
|
|
||||
LL | Alias::Variant::<()>(());
|
||||
| ^^ type parameter not allowed
|
||||
|
||||
error[E0109]: type parameters are not allowed on this type
|
||||
--> $DIR/enum-generic-args.rs:25:28
|
||||
|
|
||||
LL | Alias::<()>::Variant::<()>(());
|
||||
| ^^ type parameter not allowed
|
||||
|
||||
error[E0109]: type parameters are not allowed on this type
|
||||
--> $DIR/enum-generic-args.rs:28:27
|
||||
|
|
||||
LL | AliasFixed::Variant::<()>(());
|
||||
| ^^ type parameter not allowed
|
||||
|
||||
error[E0107]: wrong number of type arguments: expected 0, found 1
|
||||
--> $DIR/enum-generic-args.rs:30:18
|
||||
|
|
||||
LL | AliasFixed::<()>::Variant(());
|
||||
| ^^ unexpected type argument
|
||||
|
||||
error[E0107]: wrong number of type arguments: expected 0, found 1
|
||||
--> $DIR/enum-generic-args.rs:32:18
|
||||
|
|
||||
LL | AliasFixed::<()>::Variant::<()>(());
|
||||
| ^^ unexpected type argument
|
||||
|
||||
error[E0109]: type parameters are not allowed on this type
|
||||
--> $DIR/enum-generic-args.rs:32:33
|
||||
|
|
||||
LL | AliasFixed::<()>::Variant::<()>(());
|
||||
| ^^ type parameter not allowed
|
||||
|
||||
error: aborting due to 11 previous errors
|
||||
|
||||
Some errors occurred: E0107, E0109.
|
||||
For more information about an error, try `rustc --explain E0107`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue