From 248dbbdffa842f3be4880c5dd016515d3c099f40 Mon Sep 17 00:00:00 2001 From: Alexander Regueiro Date: Thu, 13 Dec 2018 16:46:34 +0000 Subject: [PATCH] Added tests for enums & enum aliases with various combinations of generic args. --- src/test/run-pass/enum-generic-args.rs | 34 +++++++++++++ src/test/ui/enum-generic-args.rs | 35 +++++++++++++ src/test/ui/enum-generic-args.stderr | 70 ++++++++++++++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 src/test/run-pass/enum-generic-args.rs create mode 100644 src/test/ui/enum-generic-args.rs create mode 100644 src/test/ui/enum-generic-args.stderr diff --git a/src/test/run-pass/enum-generic-args.rs b/src/test/run-pass/enum-generic-args.rs new file mode 100644 index 000000000000..f8cac550b41b --- /dev/null +++ b/src/test/run-pass/enum-generic-args.rs @@ -0,0 +1,34 @@ +#![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/ui/enum-generic-args.rs b/src/test/ui/enum-generic-args.rs new file mode 100644 index 000000000000..21378b044e1b --- /dev/null +++ b/src/test/ui/enum-generic-args.rs @@ -0,0 +1,35 @@ +#![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 new file mode 100644 index 000000000000..0807ee15dc75 --- /dev/null +++ b/src/test/ui/enum-generic-args.stderr @@ -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`.