@@ -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
}
@@ -339,64 +337,64 @@ TrivialTypeTraversalAndLiftImpls! {
339
337
}
340
338
341
339
impl < ' 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
+
342
373
/// Creates dummy var values which should not be used in a
343
374
/// canonical response.
344
375
pub fn dummy ( ) -> CanonicalVarValues < ' tcx > {
345
- CanonicalVarValues { var_values : Default :: default ( ) }
376
+ CanonicalVarValues { var_values : ty :: List :: empty ( ) }
346
377
}
347
378
348
379
#[ inline]
349
380
pub fn len ( & self ) -> usize {
350
381
self . var_values . len ( )
351
382
}
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
- }
385
383
}
386
384
387
385
impl < ' a , ' tcx > IntoIterator for & ' a CanonicalVarValues < ' tcx > {
388
386
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 > > > ;
390
388
391
389
fn into_iter ( self ) -> Self :: IntoIter {
392
- self . var_values . iter ( ) . cloned ( )
390
+ self . var_values . iter ( )
393
391
}
394
392
}
395
393
396
394
impl < ' tcx > Index < BoundVar > for CanonicalVarValues < ' tcx > {
397
395
type Output = GenericArg < ' tcx > ;
398
396
399
397
fn index ( & self , value : BoundVar ) -> & GenericArg < ' tcx > {
400
- & self . var_values [ value]
398
+ & self . var_values [ value. as_usize ( ) ]
401
399
}
402
400
}
0 commit comments