Added tests for feature.
This commit is contained in:
parent
c77fdbf2eb
commit
ecacad0770
5 changed files with 146 additions and 0 deletions
30
src/test/run-pass/type-alias-enum-variants.rs
Normal file
30
src/test/run-pass/type-alias-enum-variants.rs
Normal file
|
|
@ -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));
|
||||
}
|
||||
|
|
@ -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 } => {}
|
||||
}
|
||||
}
|
||||
|
|
@ -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`.
|
||||
10
src/test/ui/type-alias-enum-variants.rs
Normal file
10
src/test/ui/type-alias-enum-variants.rs
Normal file
|
|
@ -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
|
||||
}
|
||||
9
src/test/ui/type-alias-enum-variants.stderr
Normal file
9
src/test/ui/type-alias-enum-variants.stderr
Normal file
|
|
@ -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`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue