Skip to content

Commit ce48086

Browse files
committed
enum-variant-generic-args-pats-pass: harden + describe.
1 parent 86c74d3 commit ce48086

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/test/ui/type-alias-enum-variants/enum-variant-generic-args-pats-pass.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
// run-pass
22

3+
// Check that resolving, in the value namespace, to an `enum` variant
4+
// through a type alias is well behaved in the presence of generics.
5+
// We check for situations with:
6+
// 1. a generic type `Alias<T>`, we can type-apply `Alias` when referring to a variant.
7+
// 2. a monotype `AliasFixed` of generic `Enum<T>`, we can refer to variants
8+
// and the type-application of `T` in `AliasFixed` is kept.
9+
310
#![allow(irrefutable_let_patterns)]
411

512
#[allow(dead_code)]
6-
enum Enum<T> { TSVariant(T), SVariant { v: T } }
13+
enum Enum<T> { TSVariant(T), SVariant { v: T }, UVariant }
714
type Alias<T> = Enum<T>;
815
type AliasFixed = Enum<()>;
916

1017
macro_rules! is_variant {
1118
(TSVariant, $expr:expr) => (is_variant!(@check TSVariant, (_), $expr));
1219
(SVariant, $expr:expr) => (is_variant!(@check SVariant, { v: _ }, $expr));
20+
(UVariant, $expr:expr) => (is_variant!(@check UVariant, {}, $expr));
1321
(@check $variant:ident, $matcher:tt, $expr:expr) => (
1422
assert!(if let Enum::$variant::<()> $matcher = $expr { true } else { false },
1523
"expr does not have correct type");
@@ -38,4 +46,15 @@ fn main() {
3846
is_variant!(SVariant, Alias::<()>::SVariant { v: () });
3947

4048
is_variant!(SVariant, AliasFixed::SVariant { v: () });
49+
50+
// Unit variant
51+
52+
is_variant!(UVariant, Enum::UVariant);
53+
is_variant!(UVariant, Enum::UVariant::<()>);
54+
is_variant!(UVariant, Enum::<()>::UVariant);
55+
56+
is_variant!(UVariant, Alias::UVariant);
57+
is_variant!(UVariant, Alias::<()>::UVariant);
58+
59+
is_variant!(UVariant, AliasFixed::UVariant);
4160
}

0 commit comments

Comments
 (0)