Inline fold_infer_ty
This commit is contained in:
@@ -41,7 +41,7 @@ use rustc_middle::ty::fold::BoundVarReplacerDelegate;
|
|||||||
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
|
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
|
||||||
use rustc_middle::ty::relate::RelateResult;
|
use rustc_middle::ty::relate::RelateResult;
|
||||||
use rustc_middle::ty::visit::TypeVisitableExt;
|
use rustc_middle::ty::visit::TypeVisitableExt;
|
||||||
use rustc_middle::ty::{self, GenericParamDefKind, InferConst, InferTy, Ty, TyCtxt};
|
use rustc_middle::ty::{self, GenericParamDefKind, InferConst, Ty, TyCtxt};
|
||||||
use rustc_middle::ty::{ConstVid, EffectVid, FloatVid, IntVid, TyVid};
|
use rustc_middle::ty::{ConstVid, EffectVid, FloatVid, IntVid, TyVid};
|
||||||
use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgs, GenericArgsRef};
|
use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgs, GenericArgsRef};
|
||||||
use rustc_middle::{bug, span_bug};
|
use rustc_middle::{bug, span_bug};
|
||||||
@@ -1248,12 +1248,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn shallow_resolve(&self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
pub fn shallow_resolve(&self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
if let ty::Infer(v) = ty.kind() { self.fold_infer_ty(*v).unwrap_or(ty) } else { ty }
|
if let ty::Infer(v) = *ty.kind() {
|
||||||
}
|
|
||||||
|
|
||||||
// This is separate from `shallow_resolve` to keep that method small and inlinable.
|
|
||||||
#[inline(never)]
|
|
||||||
fn fold_infer_ty(&self, v: InferTy) -> Option<Ty<'tcx>> {
|
|
||||||
match v {
|
match v {
|
||||||
ty::TyVar(v) => {
|
ty::TyVar(v) => {
|
||||||
// Not entirely obvious: if `typ` is a type variable,
|
// Not entirely obvious: if `typ` is a type variable,
|
||||||
@@ -1269,23 +1264,28 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||||||
// Note: if these two lines are combined into one we get
|
// Note: if these two lines are combined into one we get
|
||||||
// dynamic borrow errors on `self.inner`.
|
// dynamic borrow errors on `self.inner`.
|
||||||
let known = self.inner.borrow_mut().type_variables().probe(v).known();
|
let known = self.inner.borrow_mut().type_variables().probe(v).known();
|
||||||
known.map(|t| self.shallow_resolve(t))
|
known.map_or(ty, |t| self.shallow_resolve(t))
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::IntVar(v) => match self.inner.borrow_mut().int_unification_table().probe_value(v) {
|
ty::IntVar(v) => {
|
||||||
ty::IntVarValue::Unknown => None,
|
match self.inner.borrow_mut().int_unification_table().probe_value(v) {
|
||||||
ty::IntVarValue::IntType(ty) => Some(Ty::new_int(self.tcx, ty)),
|
ty::IntVarValue::Unknown => ty,
|
||||||
ty::IntVarValue::UintType(ty) => Some(Ty::new_uint(self.tcx, ty)),
|
ty::IntVarValue::IntType(ty) => Ty::new_int(self.tcx, ty),
|
||||||
},
|
ty::IntVarValue::UintType(ty) => Ty::new_uint(self.tcx, ty),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ty::FloatVar(v) => {
|
ty::FloatVar(v) => {
|
||||||
match self.inner.borrow_mut().float_unification_table().probe_value(v) {
|
match self.inner.borrow_mut().float_unification_table().probe_value(v) {
|
||||||
ty::FloatVarValue::Unknown => None,
|
ty::FloatVarValue::Unknown => ty,
|
||||||
ty::FloatVarValue::Known(ty) => Some(Ty::new_float(self.tcx, ty)),
|
ty::FloatVarValue::Known(ty) => Ty::new_float(self.tcx, ty),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => None,
|
ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_) => ty,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user