@@ -111,7 +111,7 @@ impl<I: Interner> CanonicalVarInfo<I> {
111111
112112 pub fn is_existential ( & self ) -> bool {
113113 match self . kind {
114- CanonicalVarKind :: Ty ( _) => true ,
114+ CanonicalVarKind :: Ty ( _) | CanonicalVarKind :: Int | CanonicalVarKind :: Float => true ,
115115 CanonicalVarKind :: PlaceholderTy ( _) => false ,
116116 CanonicalVarKind :: Region ( _) => true ,
117117 CanonicalVarKind :: PlaceholderRegion ( ..) => false ,
@@ -124,6 +124,8 @@ impl<I: Interner> CanonicalVarInfo<I> {
124124 match self . kind {
125125 CanonicalVarKind :: Region ( _) | CanonicalVarKind :: PlaceholderRegion ( _) => true ,
126126 CanonicalVarKind :: Ty ( _)
127+ | CanonicalVarKind :: Int
128+ | CanonicalVarKind :: Float
127129 | CanonicalVarKind :: PlaceholderTy ( _)
128130 | CanonicalVarKind :: Const ( _)
129131 | CanonicalVarKind :: PlaceholderConst ( _) => false ,
@@ -132,7 +134,11 @@ impl<I: Interner> CanonicalVarInfo<I> {
132134
133135 pub fn expect_placeholder_index ( self ) -> usize {
134136 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 ( _) => {
136142 panic ! ( "expected placeholder: {self:?}" )
137143 }
138144
@@ -153,8 +159,14 @@ impl<I: Interner> CanonicalVarInfo<I> {
153159 derive( Decodable_NoContext , Encodable_NoContext , HashStable_NoContext )
154160) ]
155161pub 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 ,
158170
159171 /// A "placeholder" that represents "any type".
160172 PlaceholderTy ( I :: PlaceholderTy ) ,
@@ -177,15 +189,13 @@ pub enum CanonicalVarKind<I: Interner> {
177189impl < I : Interner > CanonicalVarKind < I > {
178190 pub fn universe ( self ) -> UniverseIndex {
179191 match self {
180- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( ui ) ) => ui,
192+ CanonicalVarKind :: Ty ( ui ) => ui,
181193 CanonicalVarKind :: Region ( ui) => ui,
182194 CanonicalVarKind :: Const ( ui) => ui,
183195 CanonicalVarKind :: PlaceholderTy ( placeholder) => placeholder. universe ( ) ,
184196 CanonicalVarKind :: PlaceholderRegion ( placeholder) => placeholder. universe ( ) ,
185197 CanonicalVarKind :: PlaceholderConst ( placeholder) => placeholder. universe ( ) ,
186- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Float | CanonicalTyVarKind :: Int ) => {
187- UniverseIndex :: ROOT
188- }
198+ CanonicalVarKind :: Int | CanonicalVarKind :: Float => UniverseIndex :: ROOT ,
189199 }
190200 }
191201
@@ -195,9 +205,7 @@ impl<I: Interner> CanonicalVarKind<I> {
195205 /// the updated universe is not the root.
196206 pub fn with_updated_universe ( self , ui : UniverseIndex ) -> CanonicalVarKind < I > {
197207 match self {
198- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( _) ) => {
199- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( ui) )
200- }
208+ CanonicalVarKind :: Ty ( _) => CanonicalVarKind :: Ty ( ui) ,
201209 CanonicalVarKind :: Region ( _) => CanonicalVarKind :: Region ( ui) ,
202210 CanonicalVarKind :: Const ( _) => CanonicalVarKind :: Const ( ui) ,
203211
@@ -210,36 +218,14 @@ impl<I: Interner> CanonicalVarKind<I> {
210218 CanonicalVarKind :: PlaceholderConst ( placeholder) => {
211219 CanonicalVarKind :: PlaceholderConst ( placeholder. with_updated_universe ( ui) )
212220 }
213- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Int | CanonicalTyVarKind :: Float ) => {
221+ CanonicalVarKind :: Int | CanonicalVarKind :: Float => {
214222 assert_eq ! ( ui, UniverseIndex :: ROOT ) ;
215223 self
216224 }
217225 }
218226 }
219227}
220228
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-
243229/// A set of values corresponding to the canonical variables from some
244230/// `Canonical`. You can give these values to
245231/// `canonical_value.instantiate` to instantiate them into the canonical
@@ -313,7 +299,10 @@ impl<I: Interner> CanonicalVarValues<I> {
313299 var_values : cx. mk_args_from_iter ( infos. iter ( ) . enumerate ( ) . map (
314300 |( i, info) | -> I :: GenericArg {
315301 match info. kind {
316- CanonicalVarKind :: Ty ( _) | CanonicalVarKind :: PlaceholderTy ( _) => {
302+ CanonicalVarKind :: Ty ( _)
303+ | CanonicalVarKind :: Int
304+ | CanonicalVarKind :: Float
305+ | CanonicalVarKind :: PlaceholderTy ( _) => {
317306 Ty :: new_anon_bound ( cx, ty:: INNERMOST , ty:: BoundVar :: from_usize ( i) )
318307 . into ( )
319308 }
0 commit comments