@@ -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 }
@@ -339,64 +337,64 @@ TrivialTypeTraversalAndLiftImpls! {
339337}
340338
341339impl < ' tcx > CanonicalVarValues < ' tcx > {
340+ // Given a list of canonical variables, construct a set of values which are
341+ // the identity response.
342+ pub fn make_identity (
343+ tcx : TyCtxt < ' tcx > ,
344+ infos : CanonicalVarInfos < ' tcx > ,
345+ ) -> CanonicalVarValues < ' tcx > {
346+ CanonicalVarValues {
347+ var_values : tcx. mk_substs ( infos. iter ( ) . enumerate ( ) . map (
348+ |( i, info) | -> ty:: GenericArg < ' tcx > {
349+ match info. kind {
350+ CanonicalVarKind :: Ty ( _) | CanonicalVarKind :: PlaceholderTy ( _) => tcx
351+ . mk_ty ( ty:: Bound ( ty:: INNERMOST , ty:: BoundVar :: from_usize ( i) . into ( ) ) )
352+ . into ( ) ,
353+ CanonicalVarKind :: Region ( _) | CanonicalVarKind :: PlaceholderRegion ( _) => {
354+ let br = ty:: BoundRegion {
355+ var : ty:: BoundVar :: from_usize ( i) ,
356+ kind : ty:: BrAnon ( i as u32 , None ) ,
357+ } ;
358+ tcx. mk_region ( ty:: ReLateBound ( ty:: INNERMOST , br) ) . into ( )
359+ }
360+ CanonicalVarKind :: Const ( _, ty)
361+ | CanonicalVarKind :: PlaceholderConst ( _, ty) => tcx
362+ . mk_const (
363+ ty:: ConstKind :: Bound ( ty:: INNERMOST , ty:: BoundVar :: from_usize ( i) ) ,
364+ ty,
365+ )
366+ . into ( ) ,
367+ }
368+ } ,
369+ ) ) ,
370+ }
371+ }
372+
342373 /// Creates dummy var values which should not be used in a
343374 /// canonical response.
344375 pub fn dummy ( ) -> CanonicalVarValues < ' tcx > {
345- CanonicalVarValues { var_values : Default :: default ( ) }
376+ CanonicalVarValues { var_values : ty :: List :: empty ( ) }
346377 }
347378
348379 #[ inline]
349380 pub fn len ( & self ) -> usize {
350381 self . var_values . len ( )
351382 }
352-
353- /// Makes an identity substitution from this one: each bound var
354- /// is matched to the same bound var, preserving the original kinds.
355- /// For example, if we have:
356- /// `self.var_values == [Type(u32), Lifetime('a), Type(u64)]`
357- /// we'll return a substitution `subst` with:
358- /// `subst.var_values == [Type(^0), Lifetime(^1), Type(^2)]`.
359- pub fn make_identity ( & self , tcx : TyCtxt < ' tcx > ) -> Self {
360- use crate :: ty:: subst:: GenericArgKind ;
361-
362- 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 ( )
374- }
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 ( ) ,
383- }
384- }
385383}
386384
387385impl < ' a , ' tcx > IntoIterator for & ' a CanonicalVarValues < ' tcx > {
388386 type Item = GenericArg < ' tcx > ;
389- type IntoIter = :: std:: iter:: Cloned < :: std:: slice:: Iter < ' a , GenericArg < ' tcx > > > ;
387+ type IntoIter = :: std:: iter:: Copied < :: std:: slice:: Iter < ' a , GenericArg < ' tcx > > > ;
390388
391389 fn into_iter ( self ) -> Self :: IntoIter {
392- self . var_values . iter ( ) . cloned ( )
390+ self . var_values . iter ( )
393391 }
394392}
395393
396394impl < ' tcx > Index < BoundVar > for CanonicalVarValues < ' tcx > {
397395 type Output = GenericArg < ' tcx > ;
398396
399397 fn index ( & self , value : BoundVar ) -> & GenericArg < ' tcx > {
400- & self . var_values [ value]
398+ & self . var_values [ value. as_usize ( ) ]
401399 }
402400}
0 commit comments