@@ -1222,8 +1222,29 @@ impl<'tcx> InferCtxt<'tcx> {
12221222 self . deeply_resolve_ignoring_regions ( t) . to_string ( )
12231223 }
12241224
1225- /// If `TyVar(vid)` resolves to a type, return that type. Else, return the
1226- /// universe index of `TyVar(vid)`.
1225+ /// If `TyVar(vid)` resolves to a type, return that type.
1226+ /// Else, return the universe index of `TyVar(vid)`.
1227+ ///
1228+ /// Also return the root `TyVid` of `vid`.
1229+ /// This is more efficient than calling [`try_resolve_ty_var`](Self::try_resolve_ty_var)
1230+ /// followed by [`root_ty_var`](Self::root_ty_var).
1231+ pub fn try_resolve_ty_var_with_root (
1232+ & self ,
1233+ vid : TyVid ,
1234+ ) -> ( Result < Ty < ' tcx > , ty:: UniverseIndex > , TyVid ) {
1235+ let ( root, value) = self . inner . borrow_mut ( ) . type_variables ( ) . probe_with_root_vid ( vid) ;
1236+
1237+ (
1238+ match value {
1239+ TypeVariableValue :: Known { value } => Ok ( self . shallow_resolve_non_recursive ( value) ) ,
1240+ TypeVariableValue :: Unknown { universe } => Err ( universe) ,
1241+ } ,
1242+ root,
1243+ )
1244+ }
1245+
1246+ /// If `TyVar(vid)` resolves to a type, return that type.
1247+ /// Else, return the universe index of `TyVar(vid)`.
12271248 pub fn try_resolve_ty_var ( & self , vid : TyVid ) -> Result < Ty < ' tcx > , ty:: UniverseIndex > {
12281249 let value = self . inner . borrow_mut ( ) . type_variables ( ) . probe ( vid) ;
12291250
@@ -1235,12 +1256,8 @@ impl<'tcx> InferCtxt<'tcx> {
12351256
12361257 /// If `vid` resolves to a type, return that type. Otherwise return the root variable id for `vid`.
12371258 pub fn shallow_resolve_ty_var_or_get_root ( & self , vid : TyVid ) -> Result < Ty < ' tcx > , TyVid > {
1238- let ( root, value) = self . inner . borrow_mut ( ) . type_variables ( ) . probe_with_root_vid ( vid) ;
1239-
1240- match value {
1241- TypeVariableValue :: Known { value } => Ok ( self . shallow_resolve_non_recursive ( value) ) ,
1242- TypeVariableValue :: Unknown { universe : _ } => Err ( root) ,
1243- }
1259+ let ( res, root) = self . try_resolve_ty_var_with_root ( vid) ;
1260+ res. map_err ( |_| root)
12441261 }
12451262
12461263 /// Resolve a type variable to a type, if known.
@@ -1441,7 +1458,7 @@ impl<'tcx> InferCtxt<'tcx> {
14411458 }
14421459 }
14431460
1444- pub fn root_var ( & self , var : ty:: TyVid ) -> ty:: TyVid {
1461+ pub fn root_ty_var ( & self , var : ty:: TyVid ) -> ty:: TyVid {
14451462 self . inner . borrow_mut ( ) . type_variables ( ) . root_var ( var)
14461463 }
14471464
@@ -1529,6 +1546,29 @@ impl<'tcx> InferCtxt<'tcx> {
15291546 value. fold_with ( & mut r)
15301547 }
15311548
1549+ /// If `ConstVar(vid)` resolves to a const, return that const.
1550+ /// Else, return the universe index of `ConstVar(vid)`.
1551+ ///
1552+ /// Also return the root `ConstVid` of `vid`.
1553+ /// This is more efficient than calling [`try_resolve_const_var`](Self::try_resolve_const_var)
1554+ /// followed by [`root_const_var`](Self::root_const_var).
1555+ pub fn try_resolve_const_var_with_root (
1556+ & self ,
1557+ vid : ty:: ConstVid ,
1558+ ) -> ( Result < ty:: Const < ' tcx > , ty:: UniverseIndex > , ty:: ConstVid ) {
1559+ let ( root, value) =
1560+ self . inner . borrow_mut ( ) . const_unification_table ( ) . inlined_probe_key_value ( vid) ;
1561+ (
1562+ match value {
1563+ ConstVariableValue :: Known { value } => Ok ( value) ,
1564+ ConstVariableValue :: Unknown { origin : _, universe } => Err ( universe) ,
1565+ } ,
1566+ root. vid ,
1567+ )
1568+ }
1569+
1570+ /// If `ConstVar(vid)` resolves to a const, return that const.
1571+ /// Else, return the universe index of `ConstVar(vid)`.
15321572 pub fn try_resolve_const_var (
15331573 & self ,
15341574 vid : ty:: ConstVid ,
0 commit comments