@@ -41,7 +41,7 @@ use rustc_middle::ty::fold::BoundVarReplacerDelegate;
4141use rustc_middle:: ty:: fold:: { TypeFoldable , TypeFolder , TypeSuperFoldable } ;
4242use rustc_middle:: ty:: relate:: RelateResult ;
4343use rustc_middle:: ty:: visit:: TypeVisitableExt ;
44- use rustc_middle:: ty:: { self , GenericParamDefKind , InferConst , InferTy , Ty , TyCtxt } ;
44+ use rustc_middle:: ty:: { self , GenericParamDefKind , InferConst , Ty , TyCtxt } ;
4545use rustc_middle:: ty:: { ConstVid , EffectVid , FloatVid , IntVid , TyVid } ;
4646use rustc_middle:: ty:: { GenericArg , GenericArgKind , GenericArgs , GenericArgsRef } ;
4747use rustc_middle:: { bug, span_bug} ;
@@ -1250,44 +1250,44 @@ impl<'tcx> InferCtxt<'tcx> {
12501250 }
12511251
12521252 pub fn shallow_resolve ( & self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
1253- if let ty:: Infer ( v) = ty. kind ( ) { self . fold_infer_ty ( * v) . unwrap_or ( ty) } else { ty }
1254- }
1255-
1256- // This is separate from `shallow_resolve` to keep that method small and inlinable.
1257- #[ inline( never) ]
1258- fn fold_infer_ty ( & self , v : InferTy ) -> Option < Ty < ' tcx > > {
1259- match v {
1260- ty:: TyVar ( v) => {
1261- // Not entirely obvious: if `typ` is a type variable,
1262- // it can be resolved to an int/float variable, which
1263- // can then be recursively resolved, hence the
1264- // recursion. Note though that we prevent type
1265- // variables from unifying to other type variables
1266- // directly (though they may be embedded
1267- // structurally), and we prevent cycles in any case,
1268- // so this recursion should always be of very limited
1269- // depth.
1270- //
1271- // Note: if these two lines are combined into one we get
1272- // dynamic borrow errors on `self.inner`.
1273- let known = self . inner . borrow_mut ( ) . type_variables ( ) . probe ( v) . known ( ) ;
1274- known. map ( |t| self . shallow_resolve ( t) )
1275- }
1253+ if let ty:: Infer ( v) = * ty. kind ( ) {
1254+ match v {
1255+ ty:: TyVar ( v) => {
1256+ // Not entirely obvious: if `typ` is a type variable,
1257+ // it can be resolved to an int/float variable, which
1258+ // can then be recursively resolved, hence the
1259+ // recursion. Note though that we prevent type
1260+ // variables from unifying to other type variables
1261+ // directly (though they may be embedded
1262+ // structurally), and we prevent cycles in any case,
1263+ // so this recursion should always be of very limited
1264+ // depth.
1265+ //
1266+ // Note: if these two lines are combined into one we get
1267+ // dynamic borrow errors on `self.inner`.
1268+ let known = self . inner . borrow_mut ( ) . type_variables ( ) . probe ( v) . known ( ) ;
1269+ known. map_or ( ty, |t| self . shallow_resolve ( t) )
1270+ }
12761271
1277- ty:: IntVar ( v) => match self . inner . borrow_mut ( ) . int_unification_table ( ) . probe_value ( v) {
1278- ty:: IntVarValue :: Unknown => None ,
1279- ty:: IntVarValue :: IntType ( ty) => Some ( Ty :: new_int ( self . tcx , ty) ) ,
1280- ty:: IntVarValue :: UintType ( ty) => Some ( Ty :: new_uint ( self . tcx , ty) ) ,
1281- } ,
1272+ ty:: IntVar ( v) => {
1273+ match self . inner . borrow_mut ( ) . int_unification_table ( ) . probe_value ( v) {
1274+ ty:: IntVarValue :: Unknown => ty,
1275+ ty:: IntVarValue :: IntType ( ty) => Ty :: new_int ( self . tcx , ty) ,
1276+ ty:: IntVarValue :: UintType ( ty) => Ty :: new_uint ( self . tcx , ty) ,
1277+ }
1278+ }
12821279
1283- ty:: FloatVar ( v) => {
1284- match self . inner . borrow_mut ( ) . float_unification_table ( ) . probe_value ( v) {
1285- ty:: FloatVarValue :: Unknown => None ,
1286- ty:: FloatVarValue :: Known ( ty) => Some ( Ty :: new_float ( self . tcx , ty) ) ,
1280+ ty:: FloatVar ( v) => {
1281+ match self . inner . borrow_mut ( ) . float_unification_table ( ) . probe_value ( v) {
1282+ ty:: FloatVarValue :: Unknown => ty,
1283+ ty:: FloatVarValue :: Known ( ty) => Ty :: new_float ( self . tcx , ty) ,
1284+ }
12871285 }
1288- }
12891286
1290- ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) => None ,
1287+ ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) => ty,
1288+ }
1289+ } else {
1290+ ty
12911291 }
12921292 }
12931293
0 commit comments