@@ -110,7 +110,7 @@ impl<I: Interner> CanonicalVarInfo<I> {
110110
111111 pub fn is_existential ( & self ) -> bool {
112112 match self . kind {
113- CanonicalVarKind :: Ty ( _) => true ,
113+ CanonicalVarKind :: Ty ( _) | CanonicalVarKind :: Int | CanonicalVarKind :: Float => true ,
114114 CanonicalVarKind :: PlaceholderTy ( _) => false ,
115115 CanonicalVarKind :: Region ( _) => true ,
116116 CanonicalVarKind :: PlaceholderRegion ( ..) => false ,
@@ -123,6 +123,8 @@ impl<I: Interner> CanonicalVarInfo<I> {
123123 match self . kind {
124124 CanonicalVarKind :: Region ( _) | CanonicalVarKind :: PlaceholderRegion ( _) => true ,
125125 CanonicalVarKind :: Ty ( _)
126+ | CanonicalVarKind :: Int
127+ | CanonicalVarKind :: Float
126128 | CanonicalVarKind :: PlaceholderTy ( _)
127129 | CanonicalVarKind :: Const ( _)
128130 | CanonicalVarKind :: PlaceholderConst ( _) => false ,
@@ -131,7 +133,11 @@ impl<I: Interner> CanonicalVarInfo<I> {
131133
132134 pub fn expect_placeholder_index ( self ) -> usize {
133135 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 ( _) => {
135141 panic ! ( "expected placeholder: {self:?}" )
136142 }
137143
@@ -151,8 +157,14 @@ impl<I: Interner> CanonicalVarInfo<I> {
151157 derive( Decodable_NoContext , Encodable_NoContext , HashStable_NoContext )
152158) ]
153159pub 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 ,
156168
157169 /// A "placeholder" that represents "any type".
158170 PlaceholderTy ( I :: PlaceholderTy ) ,
@@ -175,15 +187,13 @@ pub enum CanonicalVarKind<I: Interner> {
175187impl < I : Interner > CanonicalVarKind < I > {
176188 pub fn universe ( self ) -> UniverseIndex {
177189 match self {
178- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( ui ) ) => ui,
190+ CanonicalVarKind :: Ty ( ui ) => ui,
179191 CanonicalVarKind :: Region ( ui) => ui,
180192 CanonicalVarKind :: Const ( ui) => ui,
181193 CanonicalVarKind :: PlaceholderTy ( placeholder) => placeholder. universe ( ) ,
182194 CanonicalVarKind :: PlaceholderRegion ( placeholder) => placeholder. universe ( ) ,
183195 CanonicalVarKind :: PlaceholderConst ( placeholder) => placeholder. universe ( ) ,
184- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Float | CanonicalTyVarKind :: Int ) => {
185- UniverseIndex :: ROOT
186- }
196+ CanonicalVarKind :: Int | CanonicalVarKind :: Float => UniverseIndex :: ROOT ,
187197 }
188198 }
189199
@@ -193,9 +203,7 @@ impl<I: Interner> CanonicalVarKind<I> {
193203 /// the updated universe is not the root.
194204 pub fn with_updated_universe ( self , ui : UniverseIndex ) -> CanonicalVarKind < I > {
195205 match self {
196- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( _) ) => {
197- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( ui) )
198- }
206+ CanonicalVarKind :: Ty ( _) => CanonicalVarKind :: Ty ( ui) ,
199207 CanonicalVarKind :: Region ( _) => CanonicalVarKind :: Region ( ui) ,
200208 CanonicalVarKind :: Const ( _) => CanonicalVarKind :: Const ( ui) ,
201209
@@ -208,36 +216,14 @@ impl<I: Interner> CanonicalVarKind<I> {
208216 CanonicalVarKind :: PlaceholderConst ( placeholder) => {
209217 CanonicalVarKind :: PlaceholderConst ( placeholder. with_updated_universe ( ui) )
210218 }
211- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Int | CanonicalTyVarKind :: Float ) => {
219+ CanonicalVarKind :: Int | CanonicalVarKind :: Float => {
212220 assert_eq ! ( ui, UniverseIndex :: ROOT ) ;
213221 self
214222 }
215223 }
216224 }
217225}
218226
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-
241227/// A set of values corresponding to the canonical variables from some
242228/// `Canonical`. You can give these values to
243229/// `canonical_value.instantiate` to instantiate them into the canonical
@@ -311,7 +297,10 @@ impl<I: Interner> CanonicalVarValues<I> {
311297 var_values : cx. mk_args_from_iter ( infos. iter ( ) . enumerate ( ) . map (
312298 |( i, info) | -> I :: GenericArg {
313299 match info. kind {
314- CanonicalVarKind :: Ty ( _) | CanonicalVarKind :: PlaceholderTy ( _) => {
300+ CanonicalVarKind :: Ty ( _)
301+ | CanonicalVarKind :: Int
302+ | CanonicalVarKind :: Float
303+ | CanonicalVarKind :: PlaceholderTy ( _) => {
315304 Ty :: new_anon_bound ( cx, ty:: INNERMOST , ty:: BoundVar :: from_usize ( i) )
316305 . into ( )
317306 }
0 commit comments