Some remaining cleanups

This commit is contained in:
Florian Diebold 2021-05-21 18:20:56 +02:00
parent e9d1550001
commit 67f1a08fd8
3 changed files with 13 additions and 18 deletions

View File

@ -373,10 +373,6 @@ impl<'a> InferenceContext<'a> {
self.table.unify(ty1, ty2)
}
fn unify_inner(&mut self, ty1: &Ty, ty2: &Ty) -> InferResult {
self.table.unify_inner(ty1, ty2)
}
fn resolve_ty_shallow(&mut self, ty: &Ty) -> Ty {
self.resolve_obligations_as_possible();
self.table.resolve_ty_shallow(ty)

View File

@ -146,7 +146,7 @@ impl<'a> InferenceContext<'a> {
}
_ => {
// Otherwise, just use unification rules.
self.unify_inner(&from_ty, to_ty)
self.table.try_unify(&from_ty, to_ty)
}
}
}
@ -155,7 +155,7 @@ impl<'a> InferenceContext<'a> {
let (_is_ref, from_mt, from_inner) = match from_ty.kind(&Interner) {
TyKind::Ref(mt, _, ty) => (true, mt, ty),
TyKind::Raw(mt, ty) => (false, mt, ty),
_ => return self.unify_inner(&from_ty, to_ty),
_ => return self.table.try_unify(&from_ty, to_ty),
};
coerce_mutabilities(*from_mt, to_mt)?;
@ -163,7 +163,7 @@ impl<'a> InferenceContext<'a> {
// Check that the types which they point at are compatible.
let from_raw = TyKind::Raw(to_mt, from_inner.clone()).intern(&Interner);
// FIXME: behavior differs based on is_ref once we're computing adjustments
self.unify_inner(&from_raw, to_ty)
self.table.try_unify(&from_raw, to_ty)
}
/// Reborrows `&mut A` to `&mut B` and `&(mut) A` to `&B`.
@ -174,7 +174,7 @@ impl<'a> InferenceContext<'a> {
TyKind::Ref(mt, _, _) => {
coerce_mutabilities(*mt, to_mt)?;
}
_ => return self.unify_inner(&from_ty, to_ty),
_ => return self.table.try_unify(&from_ty, to_ty),
};
// NOTE: this code is mostly copied and adapted from rustc, and
@ -228,7 +228,7 @@ impl<'a> InferenceContext<'a> {
// from `&mut T` to `&U`.
let lt = static_lifetime(); // FIXME: handle lifetimes correctly, see rustc
let derefd_from_ty = TyKind::Ref(to_mt, lt, referent_ty).intern(&Interner);
match self.unify_inner(&derefd_from_ty, to_ty) {
match self.table.try_unify(&derefd_from_ty, to_ty) {
Ok(result) => {
found = Some(result);
break;
@ -274,7 +274,7 @@ impl<'a> InferenceContext<'a> {
Ok(ok)
}
_ => self.unify_inner(&from_ty, to_ty),
_ => self.table.try_unify(&from_ty, to_ty),
}
}
@ -299,10 +299,10 @@ impl<'a> InferenceContext<'a> {
{
let from_unsafe =
TyKind::Function(safe_to_unsafe_fn_ty(from_fn_ptr.clone())).intern(&Interner);
return self.unify_inner(&from_unsafe, to_ty);
return self.table.try_unify(&from_unsafe, to_ty);
}
}
self.unify_inner(&from_ty, to_ty)
self.table.try_unify(&from_ty, to_ty)
}
/// Attempts to coerce from the type of a non-capturing closure into a
@ -323,9 +323,9 @@ impl<'a> InferenceContext<'a> {
// `unsafe fn(arg0,arg1,...) -> _`
let safety = fn_ty.sig.safety;
let pointer_ty = coerce_closure_fn_ty(from_substs, safety);
self.unify_inner(&pointer_ty, to_ty)
self.table.try_unify(&pointer_ty, to_ty)
}
_ => self.unify_inner(&from_ty, to_ty),
_ => self.table.try_unify(&from_ty, to_ty),
}
}

View File

@ -70,7 +70,7 @@ impl<T: HasInterner<Interner = Interner>> Canonicalized<T> {
let ty = ctx.normalize_associated_types_in(new_vars.apply(ty.clone(), &Interner));
ctx.unify(var.assert_ty_ref(&Interner), &ty);
} else {
let _ = ctx.unify_inner(&var, &new_vars.apply(v.clone(), &Interner));
let _ = ctx.try_unify(&var, &new_vars.apply(v.clone(), &Interner));
}
}
}
@ -300,9 +300,8 @@ impl<'a> InferenceTable<'a> {
}
/// Unify two types and register new trait goals that arise from that.
// TODO give these two functions better names
pub(crate) fn unify(&mut self, ty1: &Ty, ty2: &Ty) -> bool {
let result = if let Ok(r) = self.unify_inner(ty1, ty2) {
let result = if let Ok(r) = self.try_unify(ty1, ty2) {
r
} else {
return false;
@ -313,7 +312,7 @@ impl<'a> InferenceTable<'a> {
/// Unify two types and return new trait goals arising from it, so the
/// caller needs to deal with them.
pub(crate) fn unify_inner<T: Zip<Interner>>(&mut self, t1: &T, t2: &T) -> InferResult {
pub(crate) fn try_unify<T: Zip<Interner>>(&mut self, t1: &T, t2: &T) -> InferResult {
match self.var_unification_table.relate(
&Interner,
&self.db,