diff options
| author | Alexander Regueiro <alexreg@me.com> | 2018-12-03 00:56:08 +0000 |
|---|---|---|
| committer | Alexander Regueiro <alexreg@me.com> | 2018-12-26 21:27:08 +0000 |
| commit | ecacad07708a7ef756b45eae828d0c3b1e209c2c (patch) | |
| tree | d761fec7f43d469b652d8c0e5782cfe7e0ed8485 | |
| parent | c77fdbf2ebfa6a2f17017c38eebf18b4a802336a (diff) | |
| download | rust-ecacad07708a7ef756b45eae828d0c3b1e209c2c.tar.gz rust-ecacad07708a7ef756b45eae828d0c3b1e209c2c.zip | |
Added tests for feature.
5 files changed, 146 insertions, 0 deletions
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 00000000000..0cf413babcb --- /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<i32>; + +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 00000000000..39472af43fd --- /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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 00000000000..7dce09e483f --- /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: `<Foo as Trait>::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: `<Foo as Trait>::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 00000000000..8e5aaae0a93 --- /dev/null +++ b/src/test/ui/type-alias-enum-variants.rs @@ -0,0 +1,10 @@ +#![feature(type_alias_enum_variants)] + +type Alias<T> = Option<T>; + +fn main() { + let _ = Option::<u8>::None; // OK + let _ = Option::None::<u8>; // OK (Lint in future!) + let _ = Alias::<u8>::None; // OK + let _ = Alias::None::<u8>; // 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 00000000000..e7003217c8d --- /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::<u8>; // Error + | ^^ type parameter not allowed + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0109`. |
