1
1
use std:: fmt;
2
- use std:: hash:: Hash ;
3
2
use std:: ops:: Index ;
4
3
5
4
use derive_where:: derive_where;
@@ -91,8 +90,14 @@ impl<I: Interner, V: fmt::Display> fmt::Display for Canonical<I, V> {
91
90
derive( Decodable_NoContext , Encodable_NoContext , HashStable_NoContext )
92
91
) ]
93
92
pub enum CanonicalVarKind < I : Interner > {
94
- /// Some kind of type inference variable.
95
- Ty ( CanonicalTyVarKind ) ,
93
+ /// General type variable `?T` that can be unified with arbitrary types.
94
+ Ty ( UniverseIndex ) ,
95
+
96
+ /// Integral type variable `?I` (that can only be unified with integral types).
97
+ Int ,
98
+
99
+ /// Floating-point type variable `?F` (that can only be unified with float types).
100
+ Float ,
96
101
97
102
/// A "placeholder" that represents "any type".
98
103
PlaceholderTy ( I :: PlaceholderTy ) ,
@@ -117,15 +122,13 @@ impl<I: Interner> Eq for CanonicalVarKind<I> {}
117
122
impl < I : Interner > CanonicalVarKind < I > {
118
123
pub fn universe ( self ) -> UniverseIndex {
119
124
match self {
120
- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( ui ) ) => ui,
125
+ CanonicalVarKind :: Ty ( ui ) => ui,
121
126
CanonicalVarKind :: Region ( ui) => ui,
122
127
CanonicalVarKind :: Const ( ui) => ui,
123
128
CanonicalVarKind :: PlaceholderTy ( placeholder) => placeholder. universe ( ) ,
124
129
CanonicalVarKind :: PlaceholderRegion ( placeholder) => placeholder. universe ( ) ,
125
130
CanonicalVarKind :: PlaceholderConst ( placeholder) => placeholder. universe ( ) ,
126
- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Float | CanonicalTyVarKind :: Int ) => {
127
- UniverseIndex :: ROOT
128
- }
131
+ CanonicalVarKind :: Float | CanonicalVarKind :: Int => UniverseIndex :: ROOT ,
129
132
}
130
133
}
131
134
@@ -135,9 +138,7 @@ impl<I: Interner> CanonicalVarKind<I> {
135
138
/// the updated universe is not the root.
136
139
pub fn with_updated_universe ( self , ui : UniverseIndex ) -> CanonicalVarKind < I > {
137
140
match self {
138
- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( _) ) => {
139
- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( ui) )
140
- }
141
+ CanonicalVarKind :: Ty ( _) => CanonicalVarKind :: Ty ( ui) ,
141
142
CanonicalVarKind :: Region ( _) => CanonicalVarKind :: Region ( ui) ,
142
143
CanonicalVarKind :: Const ( _) => CanonicalVarKind :: Const ( ui) ,
143
144
@@ -150,7 +151,7 @@ impl<I: Interner> CanonicalVarKind<I> {
150
151
CanonicalVarKind :: PlaceholderConst ( placeholder) => {
151
152
CanonicalVarKind :: PlaceholderConst ( placeholder. with_updated_universe ( ui) )
152
153
}
153
- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Int | CanonicalTyVarKind :: Float ) => {
154
+ CanonicalVarKind :: Int | CanonicalVarKind :: Float => {
154
155
assert_eq ! ( ui, UniverseIndex :: ROOT ) ;
155
156
self
156
157
}
@@ -159,19 +160,23 @@ impl<I: Interner> CanonicalVarKind<I> {
159
160
160
161
pub fn is_existential ( self ) -> bool {
161
162
match self {
162
- CanonicalVarKind :: Ty ( _) => true ,
163
- CanonicalVarKind :: PlaceholderTy ( _) => false ,
164
- CanonicalVarKind :: Region ( _) => true ,
165
- CanonicalVarKind :: PlaceholderRegion ( ..) => false ,
166
- CanonicalVarKind :: Const ( _) => true ,
167
- CanonicalVarKind :: PlaceholderConst ( _) => false ,
163
+ CanonicalVarKind :: Ty ( _)
164
+ | CanonicalVarKind :: Int
165
+ | CanonicalVarKind :: Float
166
+ | CanonicalVarKind :: Region ( _)
167
+ | CanonicalVarKind :: Const ( _) => true ,
168
+ CanonicalVarKind :: PlaceholderTy ( _)
169
+ | CanonicalVarKind :: PlaceholderRegion ( ..)
170
+ | CanonicalVarKind :: PlaceholderConst ( _) => false ,
168
171
}
169
172
}
170
173
171
174
pub fn is_region ( self ) -> bool {
172
175
match self {
173
176
CanonicalVarKind :: Region ( _) | CanonicalVarKind :: PlaceholderRegion ( _) => true ,
174
177
CanonicalVarKind :: Ty ( _)
178
+ | CanonicalVarKind :: Int
179
+ | CanonicalVarKind :: Float
175
180
| CanonicalVarKind :: PlaceholderTy ( _)
176
181
| CanonicalVarKind :: Const ( _)
177
182
| CanonicalVarKind :: PlaceholderConst ( _) => false ,
@@ -180,7 +185,11 @@ impl<I: Interner> CanonicalVarKind<I> {
180
185
181
186
pub fn expect_placeholder_index ( self ) -> usize {
182
187
match self {
183
- CanonicalVarKind :: Ty ( _) | CanonicalVarKind :: Region ( _) | CanonicalVarKind :: Const ( _) => {
188
+ CanonicalVarKind :: Ty ( _)
189
+ | CanonicalVarKind :: Int
190
+ | CanonicalVarKind :: Float
191
+ | CanonicalVarKind :: Region ( _)
192
+ | CanonicalVarKind :: Const ( _) => {
184
193
panic ! ( "expected placeholder: {self:?}" )
185
194
}
186
195
@@ -191,27 +200,6 @@ impl<I: Interner> CanonicalVarKind<I> {
191
200
}
192
201
}
193
202
194
- /// Rust actually has more than one category of type variables;
195
- /// notably, the type variables we create for literals (e.g., 22 or
196
- /// 22.) can only be instantiated with integral/float types (e.g.,
197
- /// usize or f32). In order to faithfully reproduce a type, we need to
198
- /// know what set of types a given type variable can be unified with.
199
- #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
200
- #[ cfg_attr(
201
- feature = "nightly" ,
202
- derive( Decodable_NoContext , Encodable_NoContext , HashStable_NoContext )
203
- ) ]
204
- pub enum CanonicalTyVarKind {
205
- /// General type variable `?T` that can be unified with arbitrary types.
206
- General ( UniverseIndex ) ,
207
-
208
- /// Integral type variable `?I` (that can only be unified with integral types).
209
- Int ,
210
-
211
- /// Floating-point type variable `?F` (that can only be unified with float types).
212
- Float ,
213
- }
214
-
215
203
/// A set of values corresponding to the canonical variables from some
216
204
/// `Canonical`. You can give these values to
217
205
/// `canonical_value.instantiate` to instantiate them into the canonical
@@ -287,7 +275,10 @@ impl<I: Interner> CanonicalVarValues<I> {
287
275
var_values : cx. mk_args_from_iter ( infos. iter ( ) . enumerate ( ) . map (
288
276
|( i, kind) | -> I :: GenericArg {
289
277
match kind {
290
- CanonicalVarKind :: Ty ( _) | CanonicalVarKind :: PlaceholderTy ( _) => {
278
+ CanonicalVarKind :: Ty ( _)
279
+ | CanonicalVarKind :: Int
280
+ | CanonicalVarKind :: Float
281
+ | CanonicalVarKind :: PlaceholderTy ( _) => {
291
282
Ty :: new_anon_bound ( cx, ty:: INNERMOST , ty:: BoundVar :: from_usize ( i) )
292
283
. into ( )
293
284
}
0 commit comments