@@ -6,7 +6,9 @@ pub use self::RegionVariableOrigin::*;
66pub use self :: SubregionOrigin :: * ;
77pub use self :: ValuePairs :: * ;
88pub use combine:: ObligationEmittingRelation ;
9+ use rustc_data_structures:: captures:: Captures ;
910use rustc_data_structures:: undo_log:: UndoLogs ;
11+ use rustc_middle:: infer:: unify_key:: { ConstVidKey , EffectVidKey } ;
1012
1113use self :: opaque_types:: OpaqueTypeStorage ;
1214pub ( crate ) use self :: undo_log:: { InferCtxtUndoLogs , Snapshot , UndoLog } ;
@@ -40,7 +42,6 @@ use rustc_span::{Span, DUMMY_SP};
4042
4143use std:: cell:: { Cell , RefCell } ;
4244use std:: fmt;
43- use std:: marker:: PhantomData ;
4445
4546use self :: combine:: CombineFields ;
4647use self :: error_reporting:: TypeErrCtxt ;
@@ -85,7 +86,7 @@ pub struct InferOk<'tcx, T> {
8586pub type InferResult < ' tcx , T > = Result < InferOk < ' tcx , T > , TypeError < ' tcx > > ;
8687
8788pub type UnitResult < ' tcx > = RelateResult < ' tcx , ( ) > ; // "unify result"
88- pub type FixupResult < ' tcx , T > = Result < T , FixupError < ' tcx > > ; // "fixup result"
89+ pub type FixupResult < T > = Result < T , FixupError > ; // "fixup result"
8990
9091pub ( crate ) type UnificationTable < ' a , ' tcx , T > = ut:: UnificationTable <
9192 ut:: InPlace < T , & ' a mut ut:: UnificationStorage < T > , & ' a mut InferCtxtUndoLogs < ' tcx > > ,
@@ -108,7 +109,7 @@ pub struct InferCtxtInner<'tcx> {
108109 type_variable_storage : type_variable:: TypeVariableStorage < ' tcx > ,
109110
110111 /// Map from const parameter variable to the kind of const it represents.
111- const_unification_storage : ut:: UnificationTableStorage < ty :: ConstVid < ' tcx > > ,
112+ const_unification_storage : ut:: UnificationTableStorage < ConstVidKey < ' tcx > > ,
112113
113114 /// Map from integral variable to the kind of integer it represents.
114115 int_unification_storage : ut:: UnificationTableStorage < ty:: IntVid > ,
@@ -117,7 +118,7 @@ pub struct InferCtxtInner<'tcx> {
117118 float_unification_storage : ut:: UnificationTableStorage < ty:: FloatVid > ,
118119
119120 /// Map from effect variable to the effect param it represents.
120- effect_unification_storage : ut:: UnificationTableStorage < ty :: EffectVid < ' tcx > > ,
121+ effect_unification_storage : ut:: UnificationTableStorage < EffectVidKey < ' tcx > > ,
121122
122123 /// Tracks the set of region variables and the constraints between them.
123124 ///
@@ -224,11 +225,11 @@ impl<'tcx> InferCtxtInner<'tcx> {
224225 }
225226
226227 #[ inline]
227- fn const_unification_table ( & mut self ) -> UnificationTable < ' _ , ' tcx , ty :: ConstVid < ' tcx > > {
228+ fn const_unification_table ( & mut self ) -> UnificationTable < ' _ , ' tcx , ConstVidKey < ' tcx > > {
228229 self . const_unification_storage . with_log ( & mut self . undo_log )
229230 }
230231
231- fn effect_unification_table ( & mut self ) -> UnificationTable < ' _ , ' tcx , ty :: EffectVid < ' tcx > > {
232+ fn effect_unification_table ( & mut self ) -> UnificationTable < ' _ , ' tcx , EffectVidKey < ' tcx > > {
232233 self . effect_unification_storage . with_log ( & mut self . undo_log )
233234 }
234235
@@ -359,7 +360,7 @@ impl<'tcx> ty::InferCtxtLike for InferCtxt<'tcx> {
359360 }
360361 }
361362
362- fn universe_of_ct ( & self , ct : ty:: InferConst < ' tcx > ) -> Option < ty:: UniverseIndex > {
363+ fn universe_of_ct ( & self , ct : ty:: InferConst ) -> Option < ty:: UniverseIndex > {
363364 use ty:: InferConst :: * ;
364365 match ct {
365366 // Same issue as with `universe_of_ty`
@@ -548,11 +549,11 @@ pub enum NllRegionVariableOrigin {
548549
549550// FIXME(eddyb) investigate overlap between this and `TyOrConstInferVar`.
550551#[ derive( Copy , Clone , Debug ) ]
551- pub enum FixupError < ' tcx > {
552+ pub enum FixupError {
552553 UnresolvedIntTy ( IntVid ) ,
553554 UnresolvedFloatTy ( FloatVid ) ,
554555 UnresolvedTy ( TyVid ) ,
555- UnresolvedConst ( ConstVid < ' tcx > ) ,
556+ UnresolvedConst ( ConstVid ) ,
556557}
557558
558559/// See the `region_obligations` field for more information.
@@ -563,7 +564,7 @@ pub struct RegionObligation<'tcx> {
563564 pub origin : SubregionOrigin < ' tcx > ,
564565}
565566
566- impl < ' tcx > fmt:: Display for FixupError < ' tcx > {
567+ impl fmt:: Display for FixupError {
567568 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
568569 use self :: FixupError :: * ;
569570
@@ -794,7 +795,7 @@ impl<'tcx> InferCtxt<'tcx> {
794795 let mut table = inner. effect_unification_table ( ) ;
795796
796797 ( 0 ..table. len ( ) )
797- . map ( |i| ty:: EffectVid { index : i as u32 , phantom : PhantomData } )
798+ . map ( |i| ty:: EffectVid :: from_usize ( i ) )
798799 . filter ( |& vid| table. probe_value ( vid) . is_none ( ) )
799800 . map ( |v| {
800801 ty:: Const :: new_infer ( self . tcx , ty:: InferConst :: EffectVar ( v) , self . tcx . types . bool )
@@ -1072,15 +1073,20 @@ impl<'tcx> InferCtxt<'tcx> {
10721073 . inner
10731074 . borrow_mut ( )
10741075 . const_unification_table ( )
1075- . new_key ( ConstVarValue { origin, val : ConstVariableValue :: Unknown { universe } } ) ;
1076+ . new_key ( ConstVarValue { origin, val : ConstVariableValue :: Unknown { universe } } )
1077+ . vid ;
10761078 ty:: Const :: new_var ( self . tcx , vid, ty)
10771079 }
10781080
1079- pub fn next_const_var_id ( & self , origin : ConstVariableOrigin ) -> ConstVid < ' tcx > {
1080- self . inner . borrow_mut ( ) . const_unification_table ( ) . new_key ( ConstVarValue {
1081- origin,
1082- val : ConstVariableValue :: Unknown { universe : self . universe ( ) } ,
1083- } )
1081+ pub fn next_const_var_id ( & self , origin : ConstVariableOrigin ) -> ConstVid {
1082+ self . inner
1083+ . borrow_mut ( )
1084+ . const_unification_table ( )
1085+ . new_key ( ConstVarValue {
1086+ origin,
1087+ val : ConstVariableValue :: Unknown { universe : self . universe ( ) } ,
1088+ } )
1089+ . vid
10841090 }
10851091
10861092 fn next_int_var_id ( & self ) -> IntVid {
@@ -1194,11 +1200,15 @@ impl<'tcx> InferCtxt<'tcx> {
11941200 ) ,
11951201 span,
11961202 } ;
1197- let const_var_id =
1198- self . inner . borrow_mut ( ) . const_unification_table ( ) . new_key ( ConstVarValue {
1203+ let const_var_id = self
1204+ . inner
1205+ . borrow_mut ( )
1206+ . const_unification_table ( )
1207+ . new_key ( ConstVarValue {
11991208 origin,
12001209 val : ConstVariableValue :: Unknown { universe : self . universe ( ) } ,
1201- } ) ;
1210+ } )
1211+ . vid ;
12021212 ty:: Const :: new_var (
12031213 self . tcx ,
12041214 const_var_id,
@@ -1213,7 +1223,7 @@ impl<'tcx> InferCtxt<'tcx> {
12131223 }
12141224
12151225 pub fn var_for_effect ( & self , param : & ty:: GenericParamDef ) -> GenericArg < ' tcx > {
1216- let effect_vid = self . inner . borrow_mut ( ) . effect_unification_table ( ) . new_key ( None ) ;
1226+ let effect_vid = self . inner . borrow_mut ( ) . effect_unification_table ( ) . new_key ( None ) . vid ;
12171227 let ty = self
12181228 . tcx
12191229 . type_of ( param. def_id )
@@ -1333,12 +1343,12 @@ impl<'tcx> InferCtxt<'tcx> {
13331343 self . inner . borrow_mut ( ) . type_variables ( ) . root_var ( var)
13341344 }
13351345
1336- pub fn root_const_var ( & self , var : ty:: ConstVid < ' tcx > ) -> ty:: ConstVid < ' tcx > {
1337- self . inner . borrow_mut ( ) . const_unification_table ( ) . find ( var)
1346+ pub fn root_const_var ( & self , var : ty:: ConstVid ) -> ty:: ConstVid {
1347+ self . inner . borrow_mut ( ) . const_unification_table ( ) . find ( var) . vid
13381348 }
13391349
1340- pub fn root_effect_var ( & self , var : ty:: EffectVid < ' tcx > ) -> ty:: EffectVid < ' tcx > {
1341- self . inner . borrow_mut ( ) . effect_unification_table ( ) . find ( var)
1350+ pub fn root_effect_var ( & self , var : ty:: EffectVid ) -> ty:: EffectVid {
1351+ self . inner . borrow_mut ( ) . effect_unification_table ( ) . find ( var) . vid
13421352 }
13431353
13441354 /// Resolves an int var to a rigid int type, if it was constrained to one,
@@ -1402,17 +1412,14 @@ impl<'tcx> InferCtxt<'tcx> {
14021412 value. visit_with ( & mut resolve:: UnresolvedTypeOrConstFinder :: new ( self ) ) . break_value ( )
14031413 }
14041414
1405- pub fn probe_const_var (
1406- & self ,
1407- vid : ty:: ConstVid < ' tcx > ,
1408- ) -> Result < ty:: Const < ' tcx > , ty:: UniverseIndex > {
1415+ pub fn probe_const_var ( & self , vid : ty:: ConstVid ) -> Result < ty:: Const < ' tcx > , ty:: UniverseIndex > {
14091416 match self . inner . borrow_mut ( ) . const_unification_table ( ) . probe_value ( vid) . val {
14101417 ConstVariableValue :: Known { value } => Ok ( value) ,
14111418 ConstVariableValue :: Unknown { universe } => Err ( universe) ,
14121419 }
14131420 }
14141421
1415- pub fn probe_effect_var ( & self , vid : EffectVid < ' tcx > ) -> Option < EffectVarValue < ' tcx > > {
1422+ pub fn probe_effect_var ( & self , vid : EffectVid ) -> Option < EffectVarValue < ' tcx > > {
14161423 self . inner . borrow_mut ( ) . effect_unification_table ( ) . probe_value ( vid)
14171424 }
14181425
@@ -1423,7 +1430,7 @@ impl<'tcx> InferCtxt<'tcx> {
14231430 ///
14241431 /// This method is idempotent, but it not typically not invoked
14251432 /// except during the writeback phase.
1426- pub fn fully_resolve < T : TypeFoldable < TyCtxt < ' tcx > > > ( & self , value : T ) -> FixupResult < ' tcx , T > {
1433+ pub fn fully_resolve < T : TypeFoldable < TyCtxt < ' tcx > > > ( & self , value : T ) -> FixupResult < T > {
14271434 match resolve:: fully_resolve ( self , value) {
14281435 Ok ( value) => {
14291436 if value. has_non_region_infer ( ) {
@@ -1647,11 +1654,11 @@ impl<'tcx> InferCtxt<'tcx> {
16471654 #[ inline]
16481655 pub fn is_ty_infer_var_definitely_unchanged < ' a > (
16491656 & ' a self ,
1650- ) -> ( impl Fn ( TyOrConstInferVar < ' tcx > ) -> bool + ' a ) {
1657+ ) -> ( impl Fn ( TyOrConstInferVar ) -> bool + Captures < ' tcx > + ' a ) {
16511658 // This hoists the borrow/release out of the loop body.
16521659 let inner = self . inner . try_borrow ( ) ;
16531660
1654- return move |infer_var : TyOrConstInferVar < ' tcx > | match ( infer_var, & inner) {
1661+ return move |infer_var : TyOrConstInferVar | match ( infer_var, & inner) {
16551662 ( TyOrConstInferVar :: Ty ( ty_var) , Ok ( inner) ) => {
16561663 use self :: type_variable:: TypeVariableValue ;
16571664
@@ -1674,7 +1681,7 @@ impl<'tcx> InferCtxt<'tcx> {
16741681 /// inference variables), and it handles both `Ty` and `ty::Const` without
16751682 /// having to resort to storing full `GenericArg`s in `stalled_on`.
16761683 #[ inline( always) ]
1677- pub fn ty_or_const_infer_var_changed ( & self , infer_var : TyOrConstInferVar < ' tcx > ) -> bool {
1684+ pub fn ty_or_const_infer_var_changed ( & self , infer_var : TyOrConstInferVar ) -> bool {
16781685 match infer_var {
16791686 TyOrConstInferVar :: Ty ( v) => {
16801687 use self :: type_variable:: TypeVariableValue ;
@@ -1781,7 +1788,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
17811788/// Helper for [InferCtxt::ty_or_const_infer_var_changed] (see comment on that), currently
17821789/// used only for `traits::fulfill`'s list of `stalled_on` inference variables.
17831790#[ derive( Copy , Clone , Debug ) ]
1784- pub enum TyOrConstInferVar < ' tcx > {
1791+ pub enum TyOrConstInferVar {
17851792 /// Equivalent to `ty::Infer(ty::TyVar(_))`.
17861793 Ty ( TyVid ) ,
17871794 /// Equivalent to `ty::Infer(ty::IntVar(_))`.
@@ -1790,12 +1797,12 @@ pub enum TyOrConstInferVar<'tcx> {
17901797 TyFloat ( FloatVid ) ,
17911798
17921799 /// Equivalent to `ty::ConstKind::Infer(ty::InferConst::Var(_))`.
1793- Const ( ConstVid < ' tcx > ) ,
1800+ Const ( ConstVid ) ,
17941801 /// Equivalent to `ty::ConstKind::Infer(ty::InferConst::EffectVar(_))`.
1795- Effect ( EffectVid < ' tcx > ) ,
1802+ Effect ( EffectVid ) ,
17961803}
17971804
1798- impl < ' tcx > TyOrConstInferVar < ' tcx > {
1805+ impl < ' tcx > TyOrConstInferVar {
17991806 /// Tries to extract an inference variable from a type or a constant, returns `None`
18001807 /// for types other than `ty::Infer(_)` (or `InferTy::Fresh*`) and
18011808 /// for constants other than `ty::ConstKind::Infer(_)` (or `InferConst::Fresh`).
0 commit comments