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