@@ -25,10 +25,8 @@ use crate::infer::MemberConstraint;
25
25
use crate :: mir:: ConstraintCategory ;
26
26
use crate :: ty:: subst:: GenericArg ;
27
27
use crate :: ty:: { self , BoundVar , List , Region , Ty , TyCtxt } ;
28
- use rustc_index:: vec:: IndexVec ;
29
28
use rustc_macros:: HashStable ;
30
29
use smallvec:: SmallVec ;
31
- use std:: iter;
32
30
use std:: ops:: Index ;
33
31
34
32
/// A "canonicalized" type `V` is one where all free inference
@@ -62,23 +60,23 @@ impl<'tcx> ty::TypeFoldable<'tcx> for CanonicalVarInfos<'tcx> {
62
60
/// vectors with the original values that were replaced by canonical
63
61
/// variables. You will need to supply it later to instantiate the
64
62
/// canonicalized query response.
65
- #[ derive( Clone , Debug , PartialEq , Eq , Hash , TyDecodable , TyEncodable ) ]
63
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , TyDecodable , TyEncodable ) ]
66
64
#[ derive( HashStable , TypeFoldable , TypeVisitable , Lift ) ]
67
65
pub struct CanonicalVarValues < ' tcx > {
68
- pub var_values : IndexVec < BoundVar , GenericArg < ' tcx > > ,
66
+ pub var_values : ty :: SubstsRef < ' tcx > ,
69
67
}
70
68
71
69
impl CanonicalVarValues < ' _ > {
72
70
pub fn is_identity ( & self ) -> bool {
73
- self . var_values . iter_enumerated ( ) . all ( |( bv, arg) | match arg. unpack ( ) {
71
+ self . var_values . iter ( ) . enumerate ( ) . all ( |( bv, arg) | match arg. unpack ( ) {
74
72
ty:: GenericArgKind :: Lifetime ( r) => {
75
- matches ! ( * r, ty:: ReLateBound ( ty:: INNERMOST , br) if br. var == bv)
73
+ matches ! ( * r, ty:: ReLateBound ( ty:: INNERMOST , br) if br. var. as_usize ( ) == bv)
76
74
}
77
75
ty:: GenericArgKind :: Type ( ty) => {
78
- matches ! ( * ty. kind( ) , ty:: Bound ( ty:: INNERMOST , bt) if bt. var == bv)
76
+ matches ! ( * ty. kind( ) , ty:: Bound ( ty:: INNERMOST , bt) if bt. var. as_usize ( ) == bv)
79
77
}
80
78
ty:: GenericArgKind :: Const ( ct) => {
81
- matches ! ( ct. kind( ) , ty:: ConstKind :: Bound ( ty:: INNERMOST , bc) if bc == bv)
79
+ matches ! ( ct. kind( ) , ty:: ConstKind :: Bound ( ty:: INNERMOST , bc) if bc. as_usize ( ) == bv)
82
80
}
83
81
} )
84
82
}
@@ -342,7 +340,7 @@ impl<'tcx> CanonicalVarValues<'tcx> {
342
340
/// Creates dummy var values which should not be used in a
343
341
/// canonical response.
344
342
pub fn dummy ( ) -> CanonicalVarValues < ' tcx > {
345
- CanonicalVarValues { var_values : Default :: default ( ) }
343
+ CanonicalVarValues { var_values : ty :: List :: empty ( ) }
346
344
}
347
345
348
346
#[ inline]
@@ -360,43 +358,45 @@ impl<'tcx> CanonicalVarValues<'tcx> {
360
358
use crate :: ty:: subst:: GenericArgKind ;
361
359
362
360
CanonicalVarValues {
363
- var_values : iter:: zip ( & self . var_values , 0 ..)
364
- . map ( |( kind, i) | match kind. unpack ( ) {
365
- GenericArgKind :: Type ( ..) => {
366
- tcx. mk_ty ( ty:: Bound ( ty:: INNERMOST , ty:: BoundVar :: from_u32 ( i) . into ( ) ) ) . into ( )
367
- }
368
- GenericArgKind :: Lifetime ( ..) => {
369
- let br = ty:: BoundRegion {
370
- var : ty:: BoundVar :: from_u32 ( i) ,
371
- kind : ty:: BrAnon ( i, None ) ,
372
- } ;
373
- tcx. mk_region ( ty:: ReLateBound ( ty:: INNERMOST , br) ) . into ( )
361
+ var_values : tcx. mk_substs ( self . var_values . iter ( ) . enumerate ( ) . map (
362
+ |( i, kind) | -> ty:: GenericArg < ' tcx > {
363
+ match kind. unpack ( ) {
364
+ GenericArgKind :: Type ( ..) => tcx
365
+ . mk_ty ( ty:: Bound ( ty:: INNERMOST , ty:: BoundVar :: from_usize ( i) . into ( ) ) )
366
+ . into ( ) ,
367
+ GenericArgKind :: Lifetime ( ..) => {
368
+ let br = ty:: BoundRegion {
369
+ var : ty:: BoundVar :: from_usize ( i) ,
370
+ kind : ty:: BrAnon ( i as u32 , None ) ,
371
+ } ;
372
+ tcx. mk_region ( ty:: ReLateBound ( ty:: INNERMOST , br) ) . into ( )
373
+ }
374
+ GenericArgKind :: Const ( ct) => tcx
375
+ . mk_const (
376
+ ty:: ConstKind :: Bound ( ty:: INNERMOST , ty:: BoundVar :: from_usize ( i) ) ,
377
+ ct. ty ( ) ,
378
+ )
379
+ . into ( ) ,
374
380
}
375
- GenericArgKind :: Const ( ct) => tcx
376
- . mk_const (
377
- ty:: ConstKind :: Bound ( ty:: INNERMOST , ty:: BoundVar :: from_u32 ( i) ) ,
378
- ct. ty ( ) ,
379
- )
380
- . into ( ) ,
381
- } )
382
- . collect ( ) ,
381
+ } ,
382
+ ) ) ,
383
383
}
384
384
}
385
385
}
386
386
387
387
impl < ' a , ' tcx > IntoIterator for & ' a CanonicalVarValues < ' tcx > {
388
388
type Item = GenericArg < ' tcx > ;
389
- type IntoIter = :: std:: iter:: Cloned < :: std:: slice:: Iter < ' a , GenericArg < ' tcx > > > ;
389
+ type IntoIter = :: std:: iter:: Copied < :: std:: slice:: Iter < ' a , GenericArg < ' tcx > > > ;
390
390
391
391
fn into_iter ( self ) -> Self :: IntoIter {
392
- self . var_values . iter ( ) . cloned ( )
392
+ self . var_values . iter ( )
393
393
}
394
394
}
395
395
396
396
impl < ' tcx > Index < BoundVar > for CanonicalVarValues < ' tcx > {
397
397
type Output = GenericArg < ' tcx > ;
398
398
399
399
fn index ( & self , value : BoundVar ) -> & GenericArg < ' tcx > {
400
- & self . var_values [ value]
400
+ & self . var_values [ value. as_usize ( ) ]
401
401
}
402
402
}
0 commit comments