Skip to content

Commit c9ece5b

Browse files
author
Alexander Regueiro
committed
Added tests for feature.
1 parent b53cdb8 commit c9ece5b

5 files changed

+146
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#![feature(type_alias_enum_variants)]
2+
3+
#[derive(Debug, PartialEq, Eq)]
4+
enum Foo {
5+
Bar(i32),
6+
Baz { i: i32 },
7+
}
8+
9+
type FooAlias = Foo;
10+
type OptionAlias = Option<i32>;
11+
12+
impl Foo {
13+
fn foo() -> Self {
14+
Self::Bar(3)
15+
}
16+
}
17+
18+
fn main() {
19+
let t = FooAlias::Bar(1);
20+
assert_eq!(t, Foo::Bar(1));
21+
let t = FooAlias::Baz { i: 2 };
22+
assert_eq!(t, Foo::Baz { i: 2 });
23+
match t {
24+
FooAlias::Bar(_i) => {}
25+
FooAlias::Baz { i } => { assert_eq!(i, 2); }
26+
}
27+
assert_eq!(Foo::foo(), Foo::Bar(3));
28+
29+
assert_eq!(OptionAlias::Some(4), Option::Some(4));
30+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum Foo {
12+
Bar(i32),
13+
Baz { i: i32 },
14+
}
15+
16+
type Alias = Foo;
17+
18+
fn main() {
19+
let t = Alias::Bar(0);
20+
let t = Alias::Baz { i: 0 };
21+
match t {
22+
Alias::Bar(_i) => {}
23+
Alias::Baz { i: _i } => {}
24+
}
25+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
error: type alias enum variants are not yet allowed
2+
--> $DIR/feature-gate-type_alias_enum_variants.rs:19:13
3+
|
4+
LL | let t = Alias::Bar(0);
5+
| ^^^^^^^^^^
6+
|
7+
= help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable
8+
9+
error[E0599]: no variant named `Bar` found for type `Foo` in the current scope
10+
--> $DIR/feature-gate-type_alias_enum_variants.rs:19:20
11+
|
12+
LL | enum Foo {
13+
| -------- variant `Bar` not found here
14+
...
15+
LL | let t = Alias::Bar(0);
16+
| -------^^^
17+
| |
18+
| variant not found in `Foo`
19+
|
20+
= help: did you mean `Bar`?
21+
22+
error: type alias enum variants are not yet allowed
23+
--> $DIR/feature-gate-type_alias_enum_variants.rs:20:13
24+
|
25+
LL | let t = Alias::Baz { i: 0 };
26+
| ^^^^^^^^^^
27+
|
28+
= help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable
29+
30+
error[E0223]: ambiguous associated type
31+
--> $DIR/feature-gate-type_alias_enum_variants.rs:20:13
32+
|
33+
LL | let t = Alias::Baz { i: 0 };
34+
| ^^^^^^^^^^ help: use fully-qualified syntax: `<Foo as Trait>::Baz`
35+
36+
error: type alias enum variants are not yet allowed
37+
--> $DIR/feature-gate-type_alias_enum_variants.rs:22:9
38+
|
39+
LL | Alias::Bar(_i) => {}
40+
| ^^^^^^^^^^^^^^
41+
|
42+
= help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable
43+
44+
error[E0599]: no variant named `Bar` found for type `Foo` in the current scope
45+
--> $DIR/feature-gate-type_alias_enum_variants.rs:22:16
46+
|
47+
LL | enum Foo {
48+
| -------- variant `Bar` not found here
49+
...
50+
LL | Alias::Bar(_i) => {}
51+
| -------^^^---- variant not found in `Foo`
52+
|
53+
= help: did you mean `Bar`?
54+
55+
error: type alias enum variants are not yet allowed
56+
--> $DIR/feature-gate-type_alias_enum_variants.rs:23:9
57+
|
58+
LL | Alias::Baz { i: _i } => {}
59+
| ^^^^^^^^^^
60+
|
61+
= help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable
62+
63+
error[E0223]: ambiguous associated type
64+
--> $DIR/feature-gate-type_alias_enum_variants.rs:23:9
65+
|
66+
LL | Alias::Baz { i: _i } => {}
67+
| ^^^^^^^^^^ help: use fully-qualified syntax: `<Foo as Trait>::Baz`
68+
69+
error: aborting due to 8 previous errors
70+
71+
Some errors occurred: E0223, E0599.
72+
For more information about an error, try `rustc --explain E0223`.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(type_alias_enum_variants)]
2+
3+
type Alias<T> = Option<T>;
4+
5+
fn main() {
6+
let _ = Option::<u8>::None; // OK
7+
let _ = Option::None::<u8>; // OK (Lint in future!)
8+
let _ = Alias::<u8>::None; // OK
9+
let _ = Alias::None::<u8>; // Error
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0109]: type parameters are not allowed on this type
2+
--> $DIR/type-alias-enum-variants.rs:9:27
3+
|
4+
LL | let _ = Alias::None::<u8>; // Error
5+
| ^^ type parameter not allowed
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0109`.

0 commit comments

Comments
 (0)