diff --git a/src/test/run-pass/enum-generic-args.rs b/src/test/run-pass/enum-generic-args.rs deleted file mode 100644 index f8cac550b41b..000000000000 --- a/src/test/run-pass/enum-generic-args.rs +++ /dev/null @@ -1,34 +0,0 @@ -#![feature(irrefutable_let_patterns)] -#![feature(type_alias_enum_variants)] - -#![allow(irrefutable_let_patterns)] - -enum Enum { Variant(T) } -type Alias = Enum; -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 Enum { - 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(); -} diff --git a/src/test/run-pass/enum-variant-generic-args.rs b/src/test/run-pass/enum-variant-generic-args.rs new file mode 100644 index 000000000000..bb4a4c9cf0c0 --- /dev/null +++ b/src/test/run-pass/enum-variant-generic-args.rs @@ -0,0 +1,55 @@ +#![feature(irrefutable_let_patterns)] +#![feature(type_alias_enum_variants)] + +#![allow(irrefutable_let_patterns)] + +enum Enum { TSVariant(T), SVariant { v: T } } +type Alias = Enum; +type AliasFixed = Enum<()>; + +macro_rules! is_variant { + (TSVariant, $expr:expr) => (is_variant!(@TSVariant, (_), $expr)); + (SVariant, $expr:expr) => (is_variant!(@SVariant, { v: _ }, $expr)); + (@$variant:ident, $matcher:tt, $expr:expr) => ( + assert!(if let Enum::$variant::<()> $matcher = $expr { true } else { false }, + "expr does not have correct type"); + ); +} + +impl Enum { + fn ts_variant() { + is_variant!(TSVariant, Self::TSVariant(())); + } + + fn s_variant() { + is_variant!(SVariant, Self::SVariant { v: () }); + } +} + +fn main() { + // Tuple struct variant + + is_variant!(TSVariant, Enum::TSVariant(())); + is_variant!(TSVariant, Enum::TSVariant::<()>(())); + is_variant!(TSVariant, Enum::<()>::TSVariant(())); + + is_variant!(TSVariant, Alias::TSVariant(())); + is_variant!(TSVariant, Alias::<()>::TSVariant(())); + + is_variant!(TSVariant, AliasFixed::TSVariant(())); + + Enum::<()>::ts_variant(); + + // Struct variant + + is_variant!(SVariant, Enum::SVariant { v: () }); + is_variant!(SVariant, Enum::SVariant::<()> { v: () }); + is_variant!(SVariant, Enum::<()>::SVariant { v: () }); + + is_variant!(SVariant, Alias::SVariant { v: () }); + is_variant!(SVariant, Alias::<()>::SVariant { v: () }); + + is_variant!(SVariant, AliasFixed::SVariant { v: () }); + + Enum::<()>::s_variant(); +} diff --git a/src/test/run-pass/type-alias-enum-variants-2.rs b/src/test/run-pass/type-alias-enum-variants-2.rs new file mode 100644 index 000000000000..0cf413babcbf --- /dev/null +++ b/src/test/run-pass/type-alias-enum-variants-2.rs @@ -0,0 +1,30 @@ +#![feature(type_alias_enum_variants)] + +#[derive(Debug, PartialEq, Eq)] +enum Foo { + Bar(i32), + Baz { i: i32 }, +} + +type FooAlias = Foo; +type OptionAlias = Option; + +impl Foo { + fn foo() -> Self { + Self::Bar(3) + } +} + +fn main() { + let t = FooAlias::Bar(1); + assert_eq!(t, Foo::Bar(1)); + let t = FooAlias::Baz { i: 2 }; + assert_eq!(t, Foo::Baz { i: 2 }); + match t { + FooAlias::Bar(_i) => {} + FooAlias::Baz { i } => { assert_eq!(i, 2); } + } + assert_eq!(Foo::foo(), Foo::Bar(3)); + + assert_eq!(OptionAlias::Some(4), Option::Some(4)); +} diff --git a/src/test/ui/enum-generic-args.rs b/src/test/ui/enum-generic-args.rs deleted file mode 100644 index 21378b044e1b..000000000000 --- a/src/test/ui/enum-generic-args.rs +++ /dev/null @@ -1,35 +0,0 @@ -#![feature(type_alias_enum_variants)] - -enum Enum { Variant(T) } -type Alias = Enum; -type AliasFixed = Enum<()>; - -impl Enum { - 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] -} diff --git a/src/test/ui/enum-generic-args.stderr b/src/test/ui/enum-generic-args.stderr deleted file mode 100644 index 0807ee15dc75..000000000000 --- a/src/test/ui/enum-generic-args.stderr +++ /dev/null @@ -1,70 +0,0 @@ -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`. diff --git a/src/test/ui/enum-variant-generic-args.rs b/src/test/ui/enum-variant-generic-args.rs new file mode 100644 index 000000000000..37109e89624b --- /dev/null +++ b/src/test/ui/enum-variant-generic-args.rs @@ -0,0 +1,65 @@ +#![feature(type_alias_enum_variants)] + +enum Enum { TSVariant(T), SVariant { v: T } } +type Alias = Enum; +type AliasFixed = Enum<()>; + +impl Enum { + fn ts_variant() { + Self::TSVariant::<()>(()); + //~^ ERROR type parameters are not allowed on this type [E0109] + Self::<()>::TSVariant(()); + //~^ ERROR type parameters are not allowed on this type [E0109] + Self::<()>::TSVariant::<()>(()); + //~^ ERROR type parameters are not allowed on this type [E0109] + //~^^ ERROR type parameters are not allowed on this type [E0109] + } + + fn s_variant() { + Self::SVariant::<()>(()); + //~^ ERROR type parameters are not allowed on this type [E0109] + Self::<()>::SVariant(()); + //~^ ERROR type parameters are not allowed on this type [E0109] + Self::<()>::SVariant::<()>(()); + //~^ ERROR type parameters are not allowed on this type [E0109] + //~^^ ERROR type parameters are not allowed on this type [E0109] + } +} + +fn main() { + // Tuple struct variant + + Enum::<()>::TSVariant::<()>(()); + //~^ ERROR type parameters are not allowed on this type [E0109] + + Alias::TSVariant::<()>(()); + //~^ ERROR type parameters are not allowed on this type [E0109] + Alias::<()>::TSVariant::<()>(()); + //~^ ERROR type parameters are not allowed on this type [E0109] + + AliasFixed::TSVariant::<()>(()); + //~^ ERROR type parameters are not allowed on this type [E0109] + AliasFixed::<()>::TSVariant(()); + //~^ ERROR wrong number of type arguments: expected 0, found 1 [E0107] + AliasFixed::<()>::TSVariant::<()>(()); + //~^ ERROR type parameters are not allowed on this type [E0109] + //~^^ ERROR wrong number of type arguments: expected 0, found 1 [E0107] + + // Struct variant + + Enum::<()>::SVariant::<()>(()); + //~^ ERROR type parameters are not allowed on this type [E0109] + + Alias::SVariant::<()>(()); + //~^ ERROR type parameters are not allowed on this type [E0109] + Alias::<()>::SVariant::<()>(()); + //~^ ERROR type parameters are not allowed on this type [E0109] + + AliasFixed::SVariant::<()>(()); + //~^ ERROR type parameters are not allowed on this type [E0109] + AliasFixed::<()>::SVariant(()); + //~^ ERROR wrong number of type arguments: expected 0, found 1 [E0107] + AliasFixed::<()>::SVariant::<()>(()); + //~^ ERROR type parameters are not allowed on this type [E0109] + //~^^ ERROR wrong number of type arguments: expected 0, found 1 [E0107] +} diff --git a/src/test/ui/enum-variant-generic-args.stderr b/src/test/ui/enum-variant-generic-args.stderr new file mode 100644 index 000000000000..4cae164b6ff4 --- /dev/null +++ b/src/test/ui/enum-variant-generic-args.stderr @@ -0,0 +1,259 @@ +error[E0423]: expected function, found struct variant `Enum::SVariant` + --> $DIR/enum-variant-generic-args.rs:50:5 + | +LL | Enum::<()>::SVariant::<()>(()); + | ^^^^^^^^^^^^--------^^^^^^ + | | | + | | did you mean `TSVariant`? + | did you mean `Enum::SVariant { /* fields */ }`? + +error[E0109]: type parameters are not allowed on this type + --> $DIR/enum-variant-generic-args.rs:9:27 + | +LL | Self::TSVariant::<()>(()); + | ^^ type parameter not allowed + +error[E0109]: type parameters are not allowed on this type + --> $DIR/enum-variant-generic-args.rs:11:16 + | +LL | Self::<()>::TSVariant(()); + | ^^ type parameter not allowed + +error[E0109]: type parameters are not allowed on this type + --> $DIR/enum-variant-generic-args.rs:13:16 + | +LL | Self::<()>::TSVariant::<()>(()); + | ^^ type parameter not allowed + +error[E0109]: type parameters are not allowed on this type + --> $DIR/enum-variant-generic-args.rs:13:33 + | +LL | Self::<()>::TSVariant::<()>(()); + | ^^ type parameter not allowed + +error[E0109]: type parameters are not allowed on this type + --> $DIR/enum-variant-generic-args.rs:19:26 + | +LL | Self::SVariant::<()>(()); + | ^^ type parameter not allowed + +error[E0618]: expected function, found enum variant `::SVariant::<()>` + --> $DIR/enum-variant-generic-args.rs:19:9 + | +LL | enum Enum { TSVariant(T), SVariant { v: T } } + | ----------------- `::SVariant::<()>` defined here +... +LL | Self::SVariant::<()>(()); + | ^^^^^^^^^^^^^^^^^^^^---- + | | + | call expression requires function +help: `::SVariant::<()>` is a unit variant, you need to write it without the parenthesis + | +LL | ::SVariant::<()>; + | ^^^^^^^^^^^^^^^^^^^^^^ + +error[E0109]: type parameters are not allowed on this type + --> $DIR/enum-variant-generic-args.rs:21:16 + | +LL | Self::<()>::SVariant(()); + | ^^ type parameter not allowed + +error[E0618]: expected function, found enum variant `>::SVariant` + --> $DIR/enum-variant-generic-args.rs:21:9 + | +LL | enum Enum { TSVariant(T), SVariant { v: T } } + | ----------------- `>::SVariant` defined here +... +LL | Self::<()>::SVariant(()); + | ^^^^^^^^^^^^^^^^^^^^---- + | | + | call expression requires function +help: `>::SVariant` is a unit variant, you need to write it without the parenthesis + | +LL | >::SVariant; + | ^^^^^^^^^^^^^^^^^^^^ + +error[E0109]: type parameters are not allowed on this type + --> $DIR/enum-variant-generic-args.rs:23:16 + | +LL | Self::<()>::SVariant::<()>(()); + | ^^ type parameter not allowed + +error[E0109]: type parameters are not allowed on this type + --> $DIR/enum-variant-generic-args.rs:23:32 + | +LL | Self::<()>::SVariant::<()>(()); + | ^^ type parameter not allowed + +error[E0618]: expected function, found enum variant `>::SVariant::<()>` + --> $DIR/enum-variant-generic-args.rs:23:9 + | +LL | enum Enum { TSVariant(T), SVariant { v: T } } + | ----------------- `>::SVariant::<()>` defined here +... +LL | Self::<()>::SVariant::<()>(()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^---- + | | + | call expression requires function +help: `>::SVariant::<()>` is a unit variant, you need to write it without the parenthesis + | +LL | >::SVariant::<()>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0109]: type parameters are not allowed on this type + --> $DIR/enum-variant-generic-args.rs:32:29 + | +LL | Enum::<()>::TSVariant::<()>(()); + | ^^ type parameter not allowed + +error[E0109]: type parameters are not allowed on this type + --> $DIR/enum-variant-generic-args.rs:35:24 + | +LL | Alias::TSVariant::<()>(()); + | ^^ type parameter not allowed + +error[E0109]: type parameters are not allowed on this type + --> $DIR/enum-variant-generic-args.rs:37:30 + | +LL | Alias::<()>::TSVariant::<()>(()); + | ^^ type parameter not allowed + +error[E0109]: type parameters are not allowed on this type + --> $DIR/enum-variant-generic-args.rs:40:29 + | +LL | AliasFixed::TSVariant::<()>(()); + | ^^ type parameter not allowed + +error[E0107]: wrong number of type arguments: expected 0, found 1 + --> $DIR/enum-variant-generic-args.rs:42:18 + | +LL | AliasFixed::<()>::TSVariant(()); + | ^^ unexpected type argument + +error[E0107]: wrong number of type arguments: expected 0, found 1 + --> $DIR/enum-variant-generic-args.rs:44:18 + | +LL | AliasFixed::<()>::TSVariant::<()>(()); + | ^^ unexpected type argument + +error[E0109]: type parameters are not allowed on this type + --> $DIR/enum-variant-generic-args.rs:44:35 + | +LL | AliasFixed::<()>::TSVariant::<()>(()); + | ^^ type parameter not allowed + +error[E0109]: type parameters are not allowed on this type + --> $DIR/enum-variant-generic-args.rs:53:23 + | +LL | Alias::SVariant::<()>(()); + | ^^ type parameter not allowed + +error[E0618]: expected function, found enum variant `::SVariant::<()>` + --> $DIR/enum-variant-generic-args.rs:53:5 + | +LL | enum Enum { TSVariant(T), SVariant { v: T } } + | ----------------- `::SVariant::<()>` defined here +... +LL | Alias::SVariant::<()>(()); + | ^^^^^^^^^^^^^^^^^^^^^---- + | | + | call expression requires function +help: `::SVariant::<()>` is a unit variant, you need to write it without the parenthesis + | +LL | ::SVariant::<()>; + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0109]: type parameters are not allowed on this type + --> $DIR/enum-variant-generic-args.rs:55:29 + | +LL | Alias::<()>::SVariant::<()>(()); + | ^^ type parameter not allowed + +error[E0618]: expected function, found enum variant `>::SVariant::<()>` + --> $DIR/enum-variant-generic-args.rs:55:5 + | +LL | enum Enum { TSVariant(T), SVariant { v: T } } + | ----------------- `>::SVariant::<()>` defined here +... +LL | Alias::<()>::SVariant::<()>(()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^---- + | | + | call expression requires function +help: `>::SVariant::<()>` is a unit variant, you need to write it without the parenthesis + | +LL | >::SVariant::<()>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0109]: type parameters are not allowed on this type + --> $DIR/enum-variant-generic-args.rs:58:28 + | +LL | AliasFixed::SVariant::<()>(()); + | ^^ type parameter not allowed + +error[E0618]: expected function, found enum variant `::SVariant::<()>` + --> $DIR/enum-variant-generic-args.rs:58:5 + | +LL | enum Enum { TSVariant(T), SVariant { v: T } } + | ----------------- `::SVariant::<()>` defined here +... +LL | AliasFixed::SVariant::<()>(()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^---- + | | + | call expression requires function +help: `::SVariant::<()>` is a unit variant, you need to write it without the parenthesis + | +LL | ::SVariant::<()>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0107]: wrong number of type arguments: expected 0, found 1 + --> $DIR/enum-variant-generic-args.rs:60:18 + | +LL | AliasFixed::<()>::SVariant(()); + | ^^ unexpected type argument + +error[E0618]: expected function, found enum variant `>::SVariant` + --> $DIR/enum-variant-generic-args.rs:60:5 + | +LL | enum Enum { TSVariant(T), SVariant { v: T } } + | ----------------- `>::SVariant` defined here +... +LL | AliasFixed::<()>::SVariant(()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^---- + | | + | call expression requires function +help: `>::SVariant` is a unit variant, you need to write it without the parenthesis + | +LL | >::SVariant; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0107]: wrong number of type arguments: expected 0, found 1 + --> $DIR/enum-variant-generic-args.rs:62:18 + | +LL | AliasFixed::<()>::SVariant::<()>(()); + | ^^ unexpected type argument + +error[E0109]: type parameters are not allowed on this type + --> $DIR/enum-variant-generic-args.rs:62:34 + | +LL | AliasFixed::<()>::SVariant::<()>(()); + | ^^ type parameter not allowed + +error[E0618]: expected function, found enum variant `>::SVariant::<()>` + --> $DIR/enum-variant-generic-args.rs:62:5 + | +LL | enum Enum { TSVariant(T), SVariant { v: T } } + | ----------------- `>::SVariant::<()>` defined here +... +LL | AliasFixed::<()>::SVariant::<()>(()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---- + | | + | call expression requires function +help: `>::SVariant::<()>` is a unit variant, you need to write it without the parenthesis + | +LL | >::SVariant::<()>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 30 previous errors + +Some errors occurred: E0107, E0109, E0423, E0618. +For more information about an error, try `rustc --explain E0107`. diff --git a/src/test/ui/type-alias-enum-variants-panic.rs b/src/test/ui/type-alias-enum-variants-panic.rs new file mode 100644 index 000000000000..abed190d22b0 --- /dev/null +++ b/src/test/ui/type-alias-enum-variants-panic.rs @@ -0,0 +1,10 @@ +#![feature(type_alias_enum_variants)] + +enum Enum { Variant {} } +type Alias = Enum; + +fn main() { + Alias::Variant; + let Alias::Variant = panic!(); + let Alias::Variant(..) = panic!(); +}