@@ -6,7 +6,9 @@ pub use self::RegionVariableOrigin::*;
6
6
pub use self :: SubregionOrigin :: * ;
7
7
pub use self :: ValuePairs :: * ;
8
8
pub use combine:: ObligationEmittingRelation ;
9
+ use rustc_data_structures:: captures:: Captures ;
9
10
use rustc_data_structures:: undo_log:: UndoLogs ;
11
+ use rustc_middle:: infer:: unify_key:: { ConstVidKey , EffectVidKey } ;
10
12
11
13
use self :: opaque_types:: OpaqueTypeStorage ;
12
14
pub ( crate ) use self :: undo_log:: { InferCtxtUndoLogs , Snapshot , UndoLog } ;
@@ -40,7 +42,6 @@ use rustc_span::{Span, DUMMY_SP};
40
42
41
43
use std:: cell:: { Cell , RefCell } ;
42
44
use std:: fmt;
43
- use std:: marker:: PhantomData ;
44
45
45
46
use self :: combine:: CombineFields ;
46
47
use self :: error_reporting:: TypeErrCtxt ;
@@ -85,7 +86,7 @@ pub struct InferOk<'tcx, T> {
85
86
pub type InferResult < ' tcx , T > = Result < InferOk < ' tcx , T > , TypeError < ' tcx > > ;
86
87
87
88
pub 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"
89
90
90
91
pub ( crate ) type UnificationTable < ' a , ' tcx , T > = ut:: UnificationTable <
91
92
ut:: InPlace < T , & ' a mut ut:: UnificationStorage < T > , & ' a mut InferCtxtUndoLogs < ' tcx > > ,
@@ -108,7 +109,7 @@ pub struct InferCtxtInner<'tcx> {
108
109
type_variable_storage : type_variable:: TypeVariableStorage < ' tcx > ,
109
110
110
111
/// 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 > > ,
112
113
113
114
/// Map from integral variable to the kind of integer it represents.
114
115
int_unification_storage : ut:: UnificationTableStorage < ty:: IntVid > ,
@@ -117,7 +118,7 @@ pub struct InferCtxtInner<'tcx> {
117
118
float_unification_storage : ut:: UnificationTableStorage < ty:: FloatVid > ,
118
119
119
120
/// 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 > > ,
121
122
122
123
/// Tracks the set of region variables and the constraints between them.
123
124
///
@@ -224,11 +225,11 @@ impl<'tcx> InferCtxtInner<'tcx> {
224
225
}
225
226
226
227
#[ inline]
227
- fn const_unification_table ( & mut self ) -> UnificationTable < ' _ , ' tcx , ty :: ConstVid < ' tcx > > {
228
+ fn const_unification_table ( & mut self ) -> UnificationTable < ' _ , ' tcx , ConstVidKey < ' tcx > > {
228
229
self . const_unification_storage . with_log ( & mut self . undo_log )
229
230
}
230
231
231
- fn effect_unification_table ( & mut self ) -> UnificationTable < ' _ , ' tcx , ty :: EffectVid < ' tcx > > {
232
+ fn effect_unification_table ( & mut self ) -> UnificationTable < ' _ , ' tcx , EffectVidKey < ' tcx > > {
232
233
self . effect_unification_storage . with_log ( & mut self . undo_log )
233
234
}
234
235
@@ -359,7 +360,7 @@ impl<'tcx> ty::InferCtxtLike for InferCtxt<'tcx> {
359
360
}
360
361
}
361
362
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 > {
363
364
use ty:: InferConst :: * ;
364
365
match ct {
365
366
// Same issue as with `universe_of_ty`
@@ -548,11 +549,11 @@ pub enum NllRegionVariableOrigin {
548
549
549
550
// FIXME(eddyb) investigate overlap between this and `TyOrConstInferVar`.
550
551
#[ derive( Copy , Clone , Debug ) ]
551
- pub enum FixupError < ' tcx > {
552
+ pub enum FixupError {
552
553
UnresolvedIntTy ( IntVid ) ,
553
554
UnresolvedFloatTy ( FloatVid ) ,
554
555
UnresolvedTy ( TyVid ) ,
555
- UnresolvedConst ( ConstVid < ' tcx > ) ,
556
+ UnresolvedConst ( ConstVid ) ,
556
557
}
557
558
558
559
/// See the `region_obligations` field for more information.
@@ -563,7 +564,7 @@ pub struct RegionObligation<'tcx> {
563
564
pub origin : SubregionOrigin < ' tcx > ,
564
565
}
565
566
566
- impl < ' tcx > fmt:: Display for FixupError < ' tcx > {
567
+ impl fmt:: Display for FixupError {
567
568
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
568
569
use self :: FixupError :: * ;
569
570
@@ -794,7 +795,7 @@ impl<'tcx> InferCtxt<'tcx> {
794
795
let mut table = inner. effect_unification_table ( ) ;
795
796
796
797
( 0 ..table. len ( ) )
797
- . map ( |i| ty:: EffectVid { index : i as u32 , phantom : PhantomData } )
798
+ . map ( |i| ty:: EffectVid :: from_usize ( i ) )
798
799
. filter ( |& vid| table. probe_value ( vid) . is_none ( ) )
799
800
. map ( |v| {
800
801
ty:: Const :: new_infer ( self . tcx , ty:: InferConst :: EffectVar ( v) , self . tcx . types . bool )
@@ -1072,15 +1073,20 @@ impl<'tcx> InferCtxt<'tcx> {
1072
1073
. inner
1073
1074
. borrow_mut ( )
1074
1075
. const_unification_table ( )
1075
- . new_key ( ConstVarValue { origin, val : ConstVariableValue :: Unknown { universe } } ) ;
1076
+ . new_key ( ConstVarValue { origin, val : ConstVariableValue :: Unknown { universe } } )
1077
+ . vid ;
1076
1078
ty:: Const :: new_var ( self . tcx , vid, ty)
1077
1079
}
1078
1080
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
1084
1090
}
1085
1091
1086
1092
fn next_int_var_id ( & self ) -> IntVid {
@@ -1194,11 +1200,15 @@ impl<'tcx> InferCtxt<'tcx> {
1194
1200
) ,
1195
1201
span,
1196
1202
} ;
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 {
1199
1208
origin,
1200
1209
val : ConstVariableValue :: Unknown { universe : self . universe ( ) } ,
1201
- } ) ;
1210
+ } )
1211
+ . vid ;
1202
1212
ty:: Const :: new_var (
1203
1213
self . tcx ,
1204
1214
const_var_id,
@@ -1213,7 +1223,7 @@ impl<'tcx> InferCtxt<'tcx> {
1213
1223
}
1214
1224
1215
1225
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 ;
1217
1227
let ty = self
1218
1228
. tcx
1219
1229
. type_of ( param. def_id )
@@ -1333,12 +1343,12 @@ impl<'tcx> InferCtxt<'tcx> {
1333
1343
self . inner . borrow_mut ( ) . type_variables ( ) . root_var ( var)
1334
1344
}
1335
1345
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
1338
1348
}
1339
1349
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
1342
1352
}
1343
1353
1344
1354
/// Resolves an int var to a rigid int type, if it was constrained to one,
@@ -1402,17 +1412,14 @@ impl<'tcx> InferCtxt<'tcx> {
1402
1412
value. visit_with ( & mut resolve:: UnresolvedTypeOrConstFinder :: new ( self ) ) . break_value ( )
1403
1413
}
1404
1414
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 > {
1409
1416
match self . inner . borrow_mut ( ) . const_unification_table ( ) . probe_value ( vid) . val {
1410
1417
ConstVariableValue :: Known { value } => Ok ( value) ,
1411
1418
ConstVariableValue :: Unknown { universe } => Err ( universe) ,
1412
1419
}
1413
1420
}
1414
1421
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 > > {
1416
1423
self . inner . borrow_mut ( ) . effect_unification_table ( ) . probe_value ( vid)
1417
1424
}
1418
1425
@@ -1423,7 +1430,7 @@ impl<'tcx> InferCtxt<'tcx> {
1423
1430
///
1424
1431
/// This method is idempotent, but it not typically not invoked
1425
1432
/// 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 > {
1427
1434
match resolve:: fully_resolve ( self , value) {
1428
1435
Ok ( value) => {
1429
1436
if value. has_non_region_infer ( ) {
@@ -1647,11 +1654,11 @@ impl<'tcx> InferCtxt<'tcx> {
1647
1654
#[ inline]
1648
1655
pub fn is_ty_infer_var_definitely_unchanged < ' a > (
1649
1656
& ' a self ,
1650
- ) -> ( impl Fn ( TyOrConstInferVar < ' tcx > ) -> bool + ' a ) {
1657
+ ) -> ( impl Fn ( TyOrConstInferVar ) -> bool + Captures < ' tcx > + ' a ) {
1651
1658
// This hoists the borrow/release out of the loop body.
1652
1659
let inner = self . inner . try_borrow ( ) ;
1653
1660
1654
- return move |infer_var : TyOrConstInferVar < ' tcx > | match ( infer_var, & inner) {
1661
+ return move |infer_var : TyOrConstInferVar | match ( infer_var, & inner) {
1655
1662
( TyOrConstInferVar :: Ty ( ty_var) , Ok ( inner) ) => {
1656
1663
use self :: type_variable:: TypeVariableValue ;
1657
1664
@@ -1674,7 +1681,7 @@ impl<'tcx> InferCtxt<'tcx> {
1674
1681
/// inference variables), and it handles both `Ty` and `ty::Const` without
1675
1682
/// having to resort to storing full `GenericArg`s in `stalled_on`.
1676
1683
#[ 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 {
1678
1685
match infer_var {
1679
1686
TyOrConstInferVar :: Ty ( v) => {
1680
1687
use self :: type_variable:: TypeVariableValue ;
@@ -1781,7 +1788,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
1781
1788
/// Helper for [InferCtxt::ty_or_const_infer_var_changed] (see comment on that), currently
1782
1789
/// used only for `traits::fulfill`'s list of `stalled_on` inference variables.
1783
1790
#[ derive( Copy , Clone , Debug ) ]
1784
- pub enum TyOrConstInferVar < ' tcx > {
1791
+ pub enum TyOrConstInferVar {
1785
1792
/// Equivalent to `ty::Infer(ty::TyVar(_))`.
1786
1793
Ty ( TyVid ) ,
1787
1794
/// Equivalent to `ty::Infer(ty::IntVar(_))`.
@@ -1790,12 +1797,12 @@ pub enum TyOrConstInferVar<'tcx> {
1790
1797
TyFloat ( FloatVid ) ,
1791
1798
1792
1799
/// Equivalent to `ty::ConstKind::Infer(ty::InferConst::Var(_))`.
1793
- Const ( ConstVid < ' tcx > ) ,
1800
+ Const ( ConstVid ) ,
1794
1801
/// Equivalent to `ty::ConstKind::Infer(ty::InferConst::EffectVar(_))`.
1795
- Effect ( EffectVid < ' tcx > ) ,
1802
+ Effect ( EffectVid ) ,
1796
1803
}
1797
1804
1798
- impl < ' tcx > TyOrConstInferVar < ' tcx > {
1805
+ impl < ' tcx > TyOrConstInferVar {
1799
1806
/// Tries to extract an inference variable from a type or a constant, returns `None`
1800
1807
/// for types other than `ty::Infer(_)` (or `InferTy::Fresh*`) and
1801
1808
/// for constants other than `ty::ConstKind::Infer(_)` (or `InferConst::Fresh`).
0 commit comments