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