Skip to content

Commit c623ae1

Browse files
Inline fold_infer_ty
1 parent 8179ee5 commit c623ae1

File tree

1 file changed

+34
-34
lines changed
  • compiler/rustc_infer/src/infer

1 file changed

+34
-34
lines changed

compiler/rustc_infer/src/infer/mod.rs

+34-34
Original file line numberDiff line numberDiff line change
@@ -1248,44 +1248,44 @@ impl<'tcx> InferCtxt<'tcx> {
12481248
}
12491249

12501250
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+
}
12741269

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+
}
12801277

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+
}
12851283
}
1286-
}
12871284

1288-
ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => None,
1285+
ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => ty,
1286+
}
1287+
} else {
1288+
ty
12891289
}
12901290
}
12911291

0 commit comments

Comments
 (0)