From ecacad07708a7ef756b45eae828d0c3b1e209c2c Mon Sep 17 00:00:00 2001 From: Alexander Regueiro Date: Mon, 3 Dec 2018 00:56:08 +0000 Subject: [PATCH] Added tests for feature. --- src/test/run-pass/type-alias-enum-variants.rs | 30 ++++++++ .../feature-gate-type_alias_enum_variants.rs | 25 +++++++ ...ature-gate-type_alias_enum_variants.stderr | 72 +++++++++++++++++++ src/test/ui/type-alias-enum-variants.rs | 10 +++ src/test/ui/type-alias-enum-variants.stderr | 9 +++ 5 files changed, 146 insertions(+) create mode 100644 src/test/run-pass/type-alias-enum-variants.rs create mode 100644 src/test/ui/feature-gates/feature-gate-type_alias_enum_variants.rs create mode 100644 src/test/ui/feature-gates/feature-gate-type_alias_enum_variants.stderr create mode 100644 src/test/ui/type-alias-enum-variants.rs create mode 100644 src/test/ui/type-alias-enum-variants.stderr diff --git a/src/test/run-pass/type-alias-enum-variants.rs b/src/test/run-pass/type-alias-enum-variants.rs new file mode 100644 index 000000000000..0cf413babcbf --- /dev/null +++ b/src/test/run-pass/type-alias-enum-variants.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/feature-gates/feature-gate-type_alias_enum_variants.rs b/src/test/ui/feature-gates/feature-gate-type_alias_enum_variants.rs new file mode 100644 index 000000000000..39472af43fdb --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-type_alias_enum_variants.rs @@ -0,0 +1,25 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +enum Foo { + Bar(i32), + Baz { i: i32 }, +} + +type Alias = Foo; + +fn main() { + let t = Alias::Bar(0); + let t = Alias::Baz { i: 0 }; + match t { + Alias::Bar(_i) => {} + Alias::Baz { i: _i } => {} + } +} diff --git a/src/test/ui/feature-gates/feature-gate-type_alias_enum_variants.stderr b/src/test/ui/feature-gates/feature-gate-type_alias_enum_variants.stderr new file mode 100644 index 000000000000..7dce09e483f9 --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-type_alias_enum_variants.stderr @@ -0,0 +1,72 @@ +error: type alias enum variants are not yet allowed + --> $DIR/feature-gate-type_alias_enum_variants.rs:19:13 + | +LL | let t = Alias::Bar(0); + | ^^^^^^^^^^ + | + = help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable + +error[E0599]: no variant named `Bar` found for type `Foo` in the current scope + --> $DIR/feature-gate-type_alias_enum_variants.rs:19:20 + | +LL | enum Foo { + | -------- variant `Bar` not found here +... +LL | let t = Alias::Bar(0); + | -------^^^ + | | + | variant not found in `Foo` + | + = help: did you mean `Bar`? + +error: type alias enum variants are not yet allowed + --> $DIR/feature-gate-type_alias_enum_variants.rs:20:13 + | +LL | let t = Alias::Baz { i: 0 }; + | ^^^^^^^^^^ + | + = help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable + +error[E0223]: ambiguous associated type + --> $DIR/feature-gate-type_alias_enum_variants.rs:20:13 + | +LL | let t = Alias::Baz { i: 0 }; + | ^^^^^^^^^^ help: use fully-qualified syntax: `::Baz` + +error: type alias enum variants are not yet allowed + --> $DIR/feature-gate-type_alias_enum_variants.rs:22:9 + | +LL | Alias::Bar(_i) => {} + | ^^^^^^^^^^^^^^ + | + = help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable + +error[E0599]: no variant named `Bar` found for type `Foo` in the current scope + --> $DIR/feature-gate-type_alias_enum_variants.rs:22:16 + | +LL | enum Foo { + | -------- variant `Bar` not found here +... +LL | Alias::Bar(_i) => {} + | -------^^^---- variant not found in `Foo` + | + = help: did you mean `Bar`? + +error: type alias enum variants are not yet allowed + --> $DIR/feature-gate-type_alias_enum_variants.rs:23:9 + | +LL | Alias::Baz { i: _i } => {} + | ^^^^^^^^^^ + | + = help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable + +error[E0223]: ambiguous associated type + --> $DIR/feature-gate-type_alias_enum_variants.rs:23:9 + | +LL | Alias::Baz { i: _i } => {} + | ^^^^^^^^^^ help: use fully-qualified syntax: `::Baz` + +error: aborting due to 8 previous errors + +Some errors occurred: E0223, E0599. +For more information about an error, try `rustc --explain E0223`. diff --git a/src/test/ui/type-alias-enum-variants.rs b/src/test/ui/type-alias-enum-variants.rs new file mode 100644 index 000000000000..8e5aaae0a932 --- /dev/null +++ b/src/test/ui/type-alias-enum-variants.rs @@ -0,0 +1,10 @@ +#![feature(type_alias_enum_variants)] + +type Alias = Option; + +fn main() { + let _ = Option::::None; // OK + let _ = Option::None::; // OK (Lint in future!) + let _ = Alias::::None; // OK + let _ = Alias::None::; // Error +} diff --git a/src/test/ui/type-alias-enum-variants.stderr b/src/test/ui/type-alias-enum-variants.stderr new file mode 100644 index 000000000000..e7003217c8d7 --- /dev/null +++ b/src/test/ui/type-alias-enum-variants.stderr @@ -0,0 +1,9 @@ +error[E0109]: type parameters are not allowed on this type + --> $DIR/type-alias-enum-variants.rs:9:27 + | +LL | let _ = Alias::None::; // Error + | ^^ type parameter not allowed + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0109`.