@@ -25,14 +25,16 @@ pub fn init_tracing() {
25
25
26
26
/// A simple set of types.
27
27
#[ allow( dead_code) ]
28
- #[ derive( Debug , Copy , Clone ) ]
28
+ #[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
29
29
pub enum Ty {
30
30
/// Booleans
31
31
Bool ,
32
32
/// 8-bit unsigned integers
33
33
U8 ,
34
34
/// Tuples.
35
35
Tuple ( & ' static [ Ty ] ) ,
36
+ /// Enum with one variant of each given type.
37
+ Enum ( & ' static [ Ty ] ) ,
36
38
/// A struct with `arity` fields of type `ty`.
37
39
BigStruct { arity : usize , ty : & ' static Ty } ,
38
40
/// A enum with `arity` variants of type `ty`.
@@ -46,12 +48,23 @@ impl Ty {
46
48
match ( ctor, * self ) {
47
49
( Struct , Ty :: Tuple ( tys) ) => tys. iter ( ) . copied ( ) . collect ( ) ,
48
50
( Struct , Ty :: BigStruct { arity, ty } ) => ( 0 ..arity) . map ( |_| * ty) . collect ( ) ,
51
+ ( Variant ( i) , Ty :: Enum ( tys) ) => vec ! [ tys[ * i] ] ,
49
52
( Variant ( _) , Ty :: BigEnum { ty, .. } ) => vec ! [ * ty] ,
50
53
( Bool ( ..) | IntRange ( ..) | NonExhaustive | Missing | Wildcard , _) => vec ! [ ] ,
51
54
_ => panic ! ( "Unexpected ctor {ctor:?} for type {self:?}" ) ,
52
55
}
53
56
}
54
57
58
+ fn is_empty ( & self ) -> bool {
59
+ match * self {
60
+ Ty :: Bool | Ty :: U8 => false ,
61
+ Ty :: Tuple ( tys) => tys. iter ( ) . any ( |ty| ty. is_empty ( ) ) ,
62
+ Ty :: Enum ( tys) => tys. iter ( ) . all ( |ty| ty. is_empty ( ) ) ,
63
+ Ty :: BigStruct { arity, ty } => arity != 0 && ty. is_empty ( ) ,
64
+ Ty :: BigEnum { arity, ty } => arity == 0 || ty. is_empty ( ) ,
65
+ }
66
+ }
67
+
55
68
pub fn ctor_set ( & self ) -> ConstructorSet < Cx > {
56
69
match * self {
57
70
Ty :: Bool => ConstructorSet :: Bool ,
@@ -64,10 +77,32 @@ impl Ty {
64
77
range_2 : None ,
65
78
} ,
66
79
Ty :: Tuple ( ..) | Ty :: BigStruct { .. } => ConstructorSet :: Struct { empty : false } ,
67
- Ty :: BigEnum { arity, .. } => ConstructorSet :: Variants {
68
- variants : ( 0 ..arity) . map ( |_| VariantVisibility :: Visible ) . collect ( ) ,
80
+ Ty :: Enum ( tys) if tys. is_empty ( ) => ConstructorSet :: NoConstructors ,
81
+ Ty :: Enum ( tys) => ConstructorSet :: Variants {
82
+ variants : tys
83
+ . iter ( )
84
+ . map ( |ty| {
85
+ if ty. is_empty ( ) {
86
+ VariantVisibility :: Empty
87
+ } else {
88
+ VariantVisibility :: Visible
89
+ }
90
+ } )
91
+ . collect ( ) ,
69
92
non_exhaustive : false ,
70
93
} ,
94
+ Ty :: BigEnum { arity : 0 , .. } => ConstructorSet :: NoConstructors ,
95
+ Ty :: BigEnum { arity, ty } => {
96
+ let vis = if ty. is_empty ( ) {
97
+ VariantVisibility :: Empty
98
+ } else {
99
+ VariantVisibility :: Visible
100
+ } ;
101
+ ConstructorSet :: Variants {
102
+ variants : ( 0 ..arity) . map ( |_| vis) . collect ( ) ,
103
+ non_exhaustive : false ,
104
+ }
105
+ }
71
106
}
72
107
}
73
108
@@ -79,6 +114,7 @@ impl Ty {
79
114
match ( * self , ctor) {
80
115
( Ty :: Tuple ( ..) , _) => Ok ( ( ) ) ,
81
116
( Ty :: BigStruct { .. } , _) => write ! ( f, "BigStruct" ) ,
117
+ ( Ty :: Enum ( ..) , Constructor :: Variant ( i) ) => write ! ( f, "Enum::Variant{i}" ) ,
82
118
( Ty :: BigEnum { .. } , Constructor :: Variant ( i) ) => write ! ( f, "BigEnum::Variant{i}" ) ,
83
119
_ => write ! ( f, "{:?}::{:?}" , self , ctor) ,
84
120
}
@@ -119,7 +155,7 @@ impl PatCx for Cx {
119
155
}
120
156
121
157
fn is_min_exhaustive_patterns_feature_on ( & self ) -> bool {
122
- false
158
+ true
123
159
}
124
160
125
161
fn ctor_arity ( & self , ctor : & Constructor < Self > , ty : & Self :: Ty ) -> usize {
0 commit comments