enum-variant-generic-args-pats-pass: harden + describe.
This commit is contained in:
parent
86c74d3a86
commit
ce48086293
@ -1,15 +1,23 @@
|
||||
// run-pass
|
||||
|
||||
// Check that resolving, in the value namespace, to an `enum` variant
|
||||
// through a type alias is well behaved in the presence of generics.
|
||||
// We check for situations with:
|
||||
// 1. a generic type `Alias<T>`, we can type-apply `Alias` when referring to a variant.
|
||||
// 2. a monotype `AliasFixed` of generic `Enum<T>`, we can refer to variants
|
||||
// and the type-application of `T` in `AliasFixed` is kept.
|
||||
|
||||
#![allow(irrefutable_let_patterns)]
|
||||
|
||||
#[allow(dead_code)]
|
||||
enum Enum<T> { TSVariant(T), SVariant { v: T } }
|
||||
enum Enum<T> { TSVariant(T), SVariant { v: T }, UVariant }
|
||||
type Alias<T> = Enum<T>;
|
||||
type AliasFixed = Enum<()>;
|
||||
|
||||
macro_rules! is_variant {
|
||||
(TSVariant, $expr:expr) => (is_variant!(@check TSVariant, (_), $expr));
|
||||
(SVariant, $expr:expr) => (is_variant!(@check SVariant, { v: _ }, $expr));
|
||||
(UVariant, $expr:expr) => (is_variant!(@check UVariant, {}, $expr));
|
||||
(@check $variant:ident, $matcher:tt, $expr:expr) => (
|
||||
assert!(if let Enum::$variant::<()> $matcher = $expr { true } else { false },
|
||||
"expr does not have correct type");
|
||||
@ -38,4 +46,15 @@ fn main() {
|
||||
is_variant!(SVariant, Alias::<()>::SVariant { v: () });
|
||||
|
||||
is_variant!(SVariant, AliasFixed::SVariant { v: () });
|
||||
|
||||
// Unit variant
|
||||
|
||||
is_variant!(UVariant, Enum::UVariant);
|
||||
is_variant!(UVariant, Enum::UVariant::<()>);
|
||||
is_variant!(UVariant, Enum::<()>::UVariant);
|
||||
|
||||
is_variant!(UVariant, Alias::UVariant);
|
||||
is_variant!(UVariant, Alias::<()>::UVariant);
|
||||
|
||||
is_variant!(UVariant, AliasFixed::UVariant);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user