11use std:: fmt;
2- use std:: hash:: Hash ;
32use std:: ops:: Index ;
43
54use derive_where:: derive_where;
@@ -91,8 +90,14 @@ impl<I: Interner, V: fmt::Display> fmt::Display for Canonical<I, V> {
9190 derive( Decodable_NoContext , Encodable_NoContext , HashStable_NoContext )
9291) ]
9392pub 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 ,
96101
97102 /// A "placeholder" that represents "any type".
98103 PlaceholderTy ( I :: PlaceholderTy ) ,
@@ -117,15 +122,13 @@ impl<I: Interner> Eq for CanonicalVarKind<I> {}
117122impl < I : Interner > CanonicalVarKind < I > {
118123 pub fn universe ( self ) -> UniverseIndex {
119124 match self {
120- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( ui ) ) => ui,
125+ CanonicalVarKind :: Ty ( ui ) => ui,
121126 CanonicalVarKind :: Region ( ui) => ui,
122127 CanonicalVarKind :: Const ( ui) => ui,
123128 CanonicalVarKind :: PlaceholderTy ( placeholder) => placeholder. universe ( ) ,
124129 CanonicalVarKind :: PlaceholderRegion ( placeholder) => placeholder. universe ( ) ,
125130 CanonicalVarKind :: PlaceholderConst ( placeholder) => placeholder. universe ( ) ,
126- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Float | CanonicalTyVarKind :: Int ) => {
127- UniverseIndex :: ROOT
128- }
131+ CanonicalVarKind :: Float | CanonicalVarKind :: Int => UniverseIndex :: ROOT ,
129132 }
130133 }
131134
@@ -135,9 +138,7 @@ impl<I: Interner> CanonicalVarKind<I> {
135138 /// the updated universe is not the root.
136139 pub fn with_updated_universe ( self , ui : UniverseIndex ) -> CanonicalVarKind < I > {
137140 match self {
138- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( _) ) => {
139- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( ui) )
140- }
141+ CanonicalVarKind :: Ty ( _) => CanonicalVarKind :: Ty ( ui) ,
141142 CanonicalVarKind :: Region ( _) => CanonicalVarKind :: Region ( ui) ,
142143 CanonicalVarKind :: Const ( _) => CanonicalVarKind :: Const ( ui) ,
143144
@@ -150,7 +151,7 @@ impl<I: Interner> CanonicalVarKind<I> {
150151 CanonicalVarKind :: PlaceholderConst ( placeholder) => {
151152 CanonicalVarKind :: PlaceholderConst ( placeholder. with_updated_universe ( ui) )
152153 }
153- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Int | CanonicalTyVarKind :: Float ) => {
154+ CanonicalVarKind :: Int | CanonicalVarKind :: Float => {
154155 assert_eq ! ( ui, UniverseIndex :: ROOT ) ;
155156 self
156157 }
@@ -159,19 +160,23 @@ impl<I: Interner> CanonicalVarKind<I> {
159160
160161 pub fn is_existential ( self ) -> bool {
161162 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 ,
168171 }
169172 }
170173
171174 pub fn is_region ( self ) -> bool {
172175 match self {
173176 CanonicalVarKind :: Region ( _) | CanonicalVarKind :: PlaceholderRegion ( _) => true ,
174177 CanonicalVarKind :: Ty ( _)
178+ | CanonicalVarKind :: Int
179+ | CanonicalVarKind :: Float
175180 | CanonicalVarKind :: PlaceholderTy ( _)
176181 | CanonicalVarKind :: Const ( _)
177182 | CanonicalVarKind :: PlaceholderConst ( _) => false ,
@@ -180,7 +185,11 @@ impl<I: Interner> CanonicalVarKind<I> {
180185
181186 pub fn expect_placeholder_index ( self ) -> usize {
182187 match self {
183- CanonicalVarKind :: Ty ( _) | CanonicalVarKind :: Region ( _) | CanonicalVarKind :: Const ( _) => {
188+ CanonicalVarKind :: Ty ( _)
189+ | CanonicalVarKind :: Int
190+ | CanonicalVarKind :: Float
191+ | CanonicalVarKind :: Region ( _)
192+ | CanonicalVarKind :: Const ( _) => {
184193 panic ! ( "expected placeholder: {self:?}" )
185194 }
186195
@@ -191,27 +200,6 @@ impl<I: Interner> CanonicalVarKind<I> {
191200 }
192201}
193202
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-
215203/// A set of values corresponding to the canonical variables from some
216204/// `Canonical`. You can give these values to
217205/// `canonical_value.instantiate` to instantiate them into the canonical
@@ -287,7 +275,10 @@ impl<I: Interner> CanonicalVarValues<I> {
287275 var_values : cx. mk_args_from_iter ( infos. iter ( ) . enumerate ( ) . map (
288276 |( i, kind) | -> I :: GenericArg {
289277 match kind {
290- CanonicalVarKind :: Ty ( _) | CanonicalVarKind :: PlaceholderTy ( _) => {
278+ CanonicalVarKind :: Ty ( _)
279+ | CanonicalVarKind :: Int
280+ | CanonicalVarKind :: Float
281+ | CanonicalVarKind :: PlaceholderTy ( _) => {
291282 Ty :: new_anon_bound ( cx, ty:: INNERMOST , ty:: BoundVar :: from_usize ( i) )
292283 . into ( )
293284 }
0 commit comments