@@ -19,6 +19,24 @@ use crate::infer::type_variable::TypeVariableValue;
19
19
use crate :: infer:: unify_key:: ConstVariableValue ;
20
20
use crate :: infer:: { InferCtxt , RegionVariableOrigin , relate} ;
21
21
22
+ #[ derive( Copy , Clone , Eq , PartialEq , Debug ) ]
23
+ enum TermVid {
24
+ Ty ( ty:: TyVid ) ,
25
+ Const ( ty:: ConstVid ) ,
26
+ }
27
+
28
+ impl From < ty:: TyVid > for TermVid {
29
+ fn from ( value : ty:: TyVid ) -> Self {
30
+ TermVid :: Ty ( value)
31
+ }
32
+ }
33
+
34
+ impl From < ty:: ConstVid > for TermVid {
35
+ fn from ( value : ty:: ConstVid ) -> Self {
36
+ TermVid :: Const ( value)
37
+ }
38
+ }
39
+
22
40
impl < ' tcx > InferCtxt < ' tcx > {
23
41
/// The idea is that we should ensure that the type variable `target_vid`
24
42
/// is equal to, a subtype of, or a supertype of `source_ty`.
@@ -238,20 +256,18 @@ impl<'tcx> InferCtxt<'tcx> {
238
256
& self ,
239
257
span : Span ,
240
258
structurally_relate_aliases : StructurallyRelateAliases ,
241
- target_vid : impl Into < ty :: TermVid > ,
259
+ target_vid : impl Into < TermVid > ,
242
260
ambient_variance : ty:: Variance ,
243
261
source_term : T ,
244
262
) -> RelateResult < ' tcx , Generalization < T > > {
245
263
assert ! ( !source_term. has_escaping_bound_vars( ) ) ;
246
264
let ( for_universe, root_vid) = match target_vid. into ( ) {
247
- ty :: TermVid :: Ty ( ty_vid) => {
248
- ( self . probe_ty_var ( ty_vid) . unwrap_err ( ) , ty :: TermVid :: Ty ( self . root_var ( ty_vid) ) )
265
+ TermVid :: Ty ( ty_vid) => {
266
+ ( self . probe_ty_var ( ty_vid) . unwrap_err ( ) , TermVid :: Ty ( self . root_var ( ty_vid) ) )
249
267
}
250
- ty :: TermVid :: Const ( ct_vid) => (
268
+ TermVid :: Const ( ct_vid) => (
251
269
self . probe_const_var ( ct_vid) . unwrap_err ( ) ,
252
- ty:: TermVid :: Const (
253
- self . inner . borrow_mut ( ) . const_unification_table ( ) . find ( ct_vid) . vid ,
254
- ) ,
270
+ TermVid :: Const ( self . inner . borrow_mut ( ) . const_unification_table ( ) . find ( ct_vid) . vid ) ,
255
271
) ,
256
272
} ;
257
273
@@ -299,7 +315,7 @@ struct Generalizer<'me, 'tcx> {
299
315
/// The vid of the type variable that is in the process of being
300
316
/// instantiated. If we find this within the value we are folding,
301
317
/// that means we would have created a cyclic value.
302
- root_vid : ty :: TermVid ,
318
+ root_vid : TermVid ,
303
319
304
320
/// The universe of the type variable that is in the process of being
305
321
/// instantiated. If we find anything that this universe cannot name,
@@ -469,7 +485,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
469
485
ty:: Infer ( ty:: TyVar ( vid) ) => {
470
486
let mut inner = self . infcx . inner . borrow_mut ( ) ;
471
487
let vid = inner. type_variables ( ) . root_var ( vid) ;
472
- if ty :: TermVid :: Ty ( vid) == self . root_vid {
488
+ if TermVid :: Ty ( vid) == self . root_vid {
473
489
// If sub-roots are equal, then `root_vid` and
474
490
// `vid` are related via subtyping.
475
491
Err ( self . cyclic_term_error ( ) )
@@ -621,7 +637,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
621
637
// If root const vids are equal, then `root_vid` and
622
638
// `vid` are related and we'd be inferring an infinitely
623
639
// deep const.
624
- if ty :: TermVid :: Const (
640
+ if TermVid :: Const (
625
641
self . infcx . inner . borrow_mut ( ) . const_unification_table ( ) . find ( vid) . vid ,
626
642
) == self . root_vid
627
643
{
0 commit comments