@@ -111,7 +111,7 @@ impl<I: Interner> CanonicalVarInfo<I> {
111
111
112
112
pub fn is_existential ( & self ) -> bool {
113
113
match self . kind {
114
- CanonicalVarKind :: Ty ( _) => true ,
114
+ CanonicalVarKind :: Ty ( _) | CanonicalVarKind :: Int | CanonicalVarKind :: Float => true ,
115
115
CanonicalVarKind :: PlaceholderTy ( _) => false ,
116
116
CanonicalVarKind :: Region ( _) => true ,
117
117
CanonicalVarKind :: PlaceholderRegion ( ..) => false ,
@@ -124,6 +124,8 @@ impl<I: Interner> CanonicalVarInfo<I> {
124
124
match self . kind {
125
125
CanonicalVarKind :: Region ( _) | CanonicalVarKind :: PlaceholderRegion ( _) => true ,
126
126
CanonicalVarKind :: Ty ( _)
127
+ | CanonicalVarKind :: Int
128
+ | CanonicalVarKind :: Float
127
129
| CanonicalVarKind :: PlaceholderTy ( _)
128
130
| CanonicalVarKind :: Const ( _)
129
131
| CanonicalVarKind :: PlaceholderConst ( _) => false ,
@@ -132,7 +134,11 @@ impl<I: Interner> CanonicalVarInfo<I> {
132
134
133
135
pub fn expect_placeholder_index ( self ) -> usize {
134
136
match self . kind {
135
- CanonicalVarKind :: Ty ( _) | CanonicalVarKind :: Region ( _) | CanonicalVarKind :: Const ( _) => {
137
+ CanonicalVarKind :: Ty ( _)
138
+ | CanonicalVarKind :: Int
139
+ | CanonicalVarKind :: Float
140
+ | CanonicalVarKind :: Region ( _)
141
+ | CanonicalVarKind :: Const ( _) => {
136
142
panic ! ( "expected placeholder: {self:?}" )
137
143
}
138
144
@@ -153,8 +159,14 @@ impl<I: Interner> CanonicalVarInfo<I> {
153
159
derive( Decodable_NoContext , Encodable_NoContext , HashStable_NoContext )
154
160
) ]
155
161
pub enum CanonicalVarKind < I : Interner > {
156
- /// Some kind of type inference variable.
157
- Ty ( CanonicalTyVarKind ) ,
162
+ /// A general type variable `?T` that can be unified with arbitrary types.
163
+ Ty ( UniverseIndex ) ,
164
+
165
+ /// Integral type variable `?I` (that can only be unified with integral types).
166
+ Int ,
167
+
168
+ /// Floating-point type variable `?F` (that can only be unified with float types).
169
+ Float ,
158
170
159
171
/// A "placeholder" that represents "any type".
160
172
PlaceholderTy ( I :: PlaceholderTy ) ,
@@ -177,15 +189,13 @@ pub enum CanonicalVarKind<I: Interner> {
177
189
impl < I : Interner > CanonicalVarKind < I > {
178
190
pub fn universe ( self ) -> UniverseIndex {
179
191
match self {
180
- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( ui ) ) => ui,
192
+ CanonicalVarKind :: Ty ( ui ) => ui,
181
193
CanonicalVarKind :: Region ( ui) => ui,
182
194
CanonicalVarKind :: Const ( ui) => ui,
183
195
CanonicalVarKind :: PlaceholderTy ( placeholder) => placeholder. universe ( ) ,
184
196
CanonicalVarKind :: PlaceholderRegion ( placeholder) => placeholder. universe ( ) ,
185
197
CanonicalVarKind :: PlaceholderConst ( placeholder) => placeholder. universe ( ) ,
186
- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Float | CanonicalTyVarKind :: Int ) => {
187
- UniverseIndex :: ROOT
188
- }
198
+ CanonicalVarKind :: Int | CanonicalVarKind :: Float => UniverseIndex :: ROOT ,
189
199
}
190
200
}
191
201
@@ -195,9 +205,7 @@ impl<I: Interner> CanonicalVarKind<I> {
195
205
/// the updated universe is not the root.
196
206
pub fn with_updated_universe ( self , ui : UniverseIndex ) -> CanonicalVarKind < I > {
197
207
match self {
198
- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( _) ) => {
199
- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( ui) )
200
- }
208
+ CanonicalVarKind :: Ty ( _) => CanonicalVarKind :: Ty ( ui) ,
201
209
CanonicalVarKind :: Region ( _) => CanonicalVarKind :: Region ( ui) ,
202
210
CanonicalVarKind :: Const ( _) => CanonicalVarKind :: Const ( ui) ,
203
211
@@ -210,36 +218,14 @@ impl<I: Interner> CanonicalVarKind<I> {
210
218
CanonicalVarKind :: PlaceholderConst ( placeholder) => {
211
219
CanonicalVarKind :: PlaceholderConst ( placeholder. with_updated_universe ( ui) )
212
220
}
213
- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Int | CanonicalTyVarKind :: Float ) => {
221
+ CanonicalVarKind :: Int | CanonicalVarKind :: Float => {
214
222
assert_eq ! ( ui, UniverseIndex :: ROOT ) ;
215
223
self
216
224
}
217
225
}
218
226
}
219
227
}
220
228
221
- /// Rust actually has more than one category of type variables;
222
- /// notably, the type variables we create for literals (e.g., 22 or
223
- /// 22.) can only be instantiated with integral/float types (e.g.,
224
- /// usize or f32). In order to faithfully reproduce a type, we need to
225
- /// know what set of types a given type variable can be unified with.
226
- #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
227
- #[ derive( TypeVisitable_Generic , TypeFoldable_Generic ) ]
228
- #[ cfg_attr(
229
- feature = "nightly" ,
230
- derive( Decodable_NoContext , Encodable_NoContext , HashStable_NoContext )
231
- ) ]
232
- pub enum CanonicalTyVarKind {
233
- /// General type variable `?T` that can be unified with arbitrary types.
234
- General ( UniverseIndex ) ,
235
-
236
- /// Integral type variable `?I` (that can only be unified with integral types).
237
- Int ,
238
-
239
- /// Floating-point type variable `?F` (that can only be unified with float types).
240
- Float ,
241
- }
242
-
243
229
/// A set of values corresponding to the canonical variables from some
244
230
/// `Canonical`. You can give these values to
245
231
/// `canonical_value.instantiate` to instantiate them into the canonical
@@ -313,7 +299,10 @@ impl<I: Interner> CanonicalVarValues<I> {
313
299
var_values : cx. mk_args_from_iter ( infos. iter ( ) . enumerate ( ) . map (
314
300
|( i, info) | -> I :: GenericArg {
315
301
match info. kind {
316
- CanonicalVarKind :: Ty ( _) | CanonicalVarKind :: PlaceholderTy ( _) => {
302
+ CanonicalVarKind :: Ty ( _)
303
+ | CanonicalVarKind :: Int
304
+ | CanonicalVarKind :: Float
305
+ | CanonicalVarKind :: PlaceholderTy ( _) => {
317
306
Ty :: new_anon_bound ( cx, ty:: INNERMOST , ty:: BoundVar :: from_usize ( i) )
318
307
. into ( )
319
308
}
0 commit comments