Skip to content

Commit 248dbbd

Browse files
committed
Added tests for enums & enum aliases with various combinations of generic args.
1 parent edabad6 commit 248dbbd

File tree

3 files changed

+139
-0
lines changed

3 files changed

+139
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#![feature(irrefutable_let_patterns)]
2+
#![feature(type_alias_enum_variants)]
3+
4+
#![allow(irrefutable_let_patterns)]
5+
6+
enum Enum<T> { Variant(T) }
7+
type Alias<T> = Enum<T>;
8+
type AliasFixed = Enum<()>;
9+
10+
macro_rules! is_variant {
11+
($expr:expr) => (
12+
assert!(if let Enum::Variant::<()>(_) = $expr { true } else { false },
13+
"expr does not have correct type");
14+
)
15+
}
16+
17+
impl<T> Enum<T> {
18+
fn foo() {
19+
is_variant!(Self::Variant(()));
20+
}
21+
}
22+
23+
fn main() {
24+
is_variant!(Enum::Variant(()));
25+
is_variant!(Enum::Variant::<()>(()));
26+
is_variant!(Enum::<()>::Variant(()));
27+
28+
is_variant!(Alias::Variant(()));
29+
is_variant!(Alias::<()>::Variant(()));
30+
31+
is_variant!(AliasFixed::Variant(()));
32+
33+
Enum::<()>::foo();
34+
}

src/test/ui/enum-generic-args.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#![feature(type_alias_enum_variants)]
2+
3+
enum Enum<T> { Variant(T) }
4+
type Alias<T> = Enum<T>;
5+
type AliasFixed = Enum<()>;
6+
7+
impl<T> Enum<T> {
8+
fn foo() {
9+
Self::Variant::<()>(());
10+
//~^ ERROR type parameters are not allowed on this type [E0109]
11+
Self::<()>::Variant(());
12+
//~^ ERROR type parameters are not allowed on this type [E0109]
13+
Self::<()>::Variant::<()>(());
14+
//~^ ERROR type parameters are not allowed on this type [E0109]
15+
//~^^ ERROR type parameters are not allowed on this type [E0109]
16+
}
17+
}
18+
19+
fn main() {
20+
Enum::<()>::Variant::<()>(());
21+
//~^ ERROR type parameters are not allowed on this type [E0109]
22+
23+
Alias::Variant::<()>(());
24+
//~^ ERROR type parameters are not allowed on this type [E0109]
25+
Alias::<()>::Variant::<()>(());
26+
//~^ ERROR type parameters are not allowed on this type [E0109]
27+
28+
AliasFixed::Variant::<()>(());
29+
//~^ ERROR type parameters are not allowed on this type [E0109]
30+
AliasFixed::<()>::Variant(());
31+
//~^ ERROR wrong number of type arguments: expected 0, found 1 [E0107]
32+
AliasFixed::<()>::Variant::<()>(());
33+
//~^ ERROR type parameters are not allowed on this type [E0109]
34+
//~^^ ERROR wrong number of type arguments: expected 0, found 1 [E0107]
35+
}

src/test/ui/enum-generic-args.stderr

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
error[E0109]: type parameters are not allowed on this type
2+
--> $DIR/enum-generic-args.rs:9:25
3+
|
4+
LL | Self::Variant::<()>(());
5+
| ^^ type parameter not allowed
6+
7+
error[E0109]: type parameters are not allowed on this type
8+
--> $DIR/enum-generic-args.rs:11:16
9+
|
10+
LL | Self::<()>::Variant(());
11+
| ^^ type parameter not allowed
12+
13+
error[E0109]: type parameters are not allowed on this type
14+
--> $DIR/enum-generic-args.rs:13:16
15+
|
16+
LL | Self::<()>::Variant::<()>(());
17+
| ^^ type parameter not allowed
18+
19+
error[E0109]: type parameters are not allowed on this type
20+
--> $DIR/enum-generic-args.rs:13:31
21+
|
22+
LL | Self::<()>::Variant::<()>(());
23+
| ^^ type parameter not allowed
24+
25+
error[E0109]: type parameters are not allowed on this type
26+
--> $DIR/enum-generic-args.rs:20:27
27+
|
28+
LL | Enum::<()>::Variant::<()>(());
29+
| ^^ type parameter not allowed
30+
31+
error[E0109]: type parameters are not allowed on this type
32+
--> $DIR/enum-generic-args.rs:23:22
33+
|
34+
LL | Alias::Variant::<()>(());
35+
| ^^ type parameter not allowed
36+
37+
error[E0109]: type parameters are not allowed on this type
38+
--> $DIR/enum-generic-args.rs:25:28
39+
|
40+
LL | Alias::<()>::Variant::<()>(());
41+
| ^^ type parameter not allowed
42+
43+
error[E0109]: type parameters are not allowed on this type
44+
--> $DIR/enum-generic-args.rs:28:27
45+
|
46+
LL | AliasFixed::Variant::<()>(());
47+
| ^^ type parameter not allowed
48+
49+
error[E0107]: wrong number of type arguments: expected 0, found 1
50+
--> $DIR/enum-generic-args.rs:30:18
51+
|
52+
LL | AliasFixed::<()>::Variant(());
53+
| ^^ unexpected type argument
54+
55+
error[E0107]: wrong number of type arguments: expected 0, found 1
56+
--> $DIR/enum-generic-args.rs:32:18
57+
|
58+
LL | AliasFixed::<()>::Variant::<()>(());
59+
| ^^ unexpected type argument
60+
61+
error[E0109]: type parameters are not allowed on this type
62+
--> $DIR/enum-generic-args.rs:32:33
63+
|
64+
LL | AliasFixed::<()>::Variant::<()>(());
65+
| ^^ type parameter not allowed
66+
67+
error: aborting due to 11 previous errors
68+
69+
Some errors occurred: E0107, E0109.
70+
For more information about an error, try `rustc --explain E0107`.

0 commit comments

Comments
 (0)