@@ -25,10 +25,8 @@ use crate::infer::MemberConstraint;
2525use crate :: mir:: ConstraintCategory ;
2626use crate :: ty:: subst:: GenericArg ;
2727use crate :: ty:: { self , BoundVar , List , Region , Ty , TyCtxt } ;
28- use rustc_index:: vec:: IndexVec ;
2928use rustc_macros:: HashStable ;
3029use smallvec:: SmallVec ;
31- use std:: iter;
3230use std:: ops:: Index ;
3331
3432/// A "canonicalized" type `V` is one where all free inference
@@ -62,23 +60,23 @@ impl<'tcx> ty::TypeFoldable<'tcx> for CanonicalVarInfos<'tcx> {
6260/// vectors with the original values that were replaced by canonical
6361/// variables. You will need to supply it later to instantiate the
6462/// canonicalized query response.
65- #[ derive( Clone , Debug , PartialEq , Eq , Hash , TyDecodable , TyEncodable ) ]
63+ #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , TyDecodable , TyEncodable ) ]
6664#[ derive( HashStable , TypeFoldable , TypeVisitable , Lift ) ]
6765pub struct CanonicalVarValues < ' tcx > {
68- pub var_values : IndexVec < BoundVar , GenericArg < ' tcx > > ,
66+ pub var_values : ty :: SubstsRef < ' tcx > ,
6967}
7068
7169impl CanonicalVarValues < ' _ > {
7270 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 ( ) {
7472 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)
7674 }
7775 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)
7977 }
8078 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)
8280 }
8381 } )
8482 }
@@ -342,7 +340,7 @@ impl<'tcx> CanonicalVarValues<'tcx> {
342340 /// Creates dummy var values which should not be used in a
343341 /// canonical response.
344342 pub fn dummy ( ) -> CanonicalVarValues < ' tcx > {
345- CanonicalVarValues { var_values : Default :: default ( ) }
343+ CanonicalVarValues { var_values : ty :: List :: empty ( ) }
346344 }
347345
348346 #[ inline]
@@ -360,43 +358,45 @@ impl<'tcx> CanonicalVarValues<'tcx> {
360358 use crate :: ty:: subst:: GenericArgKind ;
361359
362360 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 ( ) ,
374380 }
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+ ) ) ,
383383 }
384384 }
385385}
386386
387387impl < ' a , ' tcx > IntoIterator for & ' a CanonicalVarValues < ' tcx > {
388388 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 > > > ;
390390
391391 fn into_iter ( self ) -> Self :: IntoIter {
392- self . var_values . iter ( ) . cloned ( )
392+ self . var_values . iter ( )
393393 }
394394}
395395
396396impl < ' tcx > Index < BoundVar > for CanonicalVarValues < ' tcx > {
397397 type Output = GenericArg < ' tcx > ;
398398
399399 fn index ( & self , value : BoundVar ) -> & GenericArg < ' tcx > {
400- & self . var_values [ value]
400+ & self . var_values [ value. as_usize ( ) ]
401401 }
402402}
0 commit comments