From 77ff38486553f40dee1315ba5c1e8c92c3845403 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sun, 9 Jun 2019 04:42:16 +0200 Subject: [PATCH] type-alias-enum-variants-pass: harden; account for unit variants. --- .../type-alias-enum-variants-pass.rs | 63 +++++++++++++++---- 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/src/test/ui/type-alias-enum-variants/type-alias-enum-variants-pass.rs b/src/test/ui/type-alias-enum-variants/type-alias-enum-variants-pass.rs index 00b787be3bc..39677733d52 100644 --- a/src/test/ui/type-alias-enum-variants/type-alias-enum-variants-pass.rs +++ b/src/test/ui/type-alias-enum-variants/type-alias-enum-variants-pass.rs @@ -1,30 +1,69 @@ // run-pass +// Check that it is possible to resolve, in the value namespace, +// to an `enum` variant through a type alias. This includes `Self`. +// Type qualified syntax `::Variant` also works when syntactically valid. + #[derive(Debug, PartialEq, Eq)] enum Foo { Bar(i32), Baz { i: i32 }, + Qux, } type FooAlias = Foo; type OptionAlias = Option; +macro_rules! check_pat { + ($x:expr, $p:pat) => { + assert!(if let $p = $x { true } else { false }); + }; +} + impl Foo { - fn foo() -> Self { - Self::Bar(3) + fn bar() -> Self { + let x = Self::Bar(3); + assert_eq!(x, ::Bar(3)); + check_pat!(x, Self::Bar(3)); + x + } + + fn baz() -> Self { + let x = Self::Baz { i: 42 }; + check_pat!(x, Self::Baz { i: 42 }); + x + } + + fn qux() -> Self { + let x = Self::Qux; + assert_eq!(x, ::Qux); + check_pat!(x, Self::Qux); + check_pat!(x, ::Qux); + x } } 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)); + let bar = Foo::Bar(1); + assert_eq!(bar, FooAlias::Bar(1)); + assert_eq!(bar, ::Bar(1)); + check_pat!(bar, FooAlias::Bar(1)); - assert_eq!(OptionAlias::Some(4), Option::Some(4)); + let baz = FooAlias::Baz { i: 2 }; + assert_eq!(baz, Foo::Baz { i: 2 }); + check_pat!(baz, FooAlias::Baz { i: 2 }); + + let qux = Foo::Qux; + assert_eq!(qux, FooAlias::Qux); + assert_eq!(qux, ::Qux); + check_pat!(qux, FooAlias::Qux); + check_pat!(qux, ::Qux); + + assert_eq!(Foo::bar(), Foo::Bar(3)); + assert_eq!(Foo::baz(), Foo::Baz { i: 42 }); + assert_eq!(Foo::qux(), Foo::Qux); + + let some = Option::Some(4); + assert_eq!(some, OptionAlias::Some(4)); + check_pat!(some, OptionAlias::Some(4)); }