From a78f0076abbbf61f7b68ce5c323639037c8a72de Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 16 May 2021 15:56:27 +0200 Subject: Make resolve_ty_shallow return Ty --- crates/hir_ty/src/infer.rs | 4 +--- crates/hir_ty/src/infer/coerce.rs | 8 +++----- crates/hir_ty/src/infer/unify.rs | 9 +++------ 3 files changed, 7 insertions(+), 14 deletions(-) (limited to 'crates/hir_ty/src') diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index 97e7c5f8c..8cfc84b86 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs @@ -13,8 +13,6 @@ //! to certain types. To record this, we use the union-find implementation from //! the `ena` crate, which is extracted from rustc. -use std::borrow::Cow; - use std::ops::Index; use std::sync::Arc; @@ -384,7 +382,7 @@ impl<'a> InferenceContext<'a> { self.table.resolve_ty_as_possible(ty) } - fn resolve_ty_shallow<'b>(&mut self, ty: &'b Ty) -> Cow<'b, Ty> { + fn resolve_ty_shallow(&mut self, ty: &Ty) -> Ty { self.table.resolve_ty_shallow(ty) } diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs index 911343cb9..c85c088f7 100644 --- a/crates/hir_ty/src/infer/coerce.rs +++ b/crates/hir_ty/src/infer/coerce.rs @@ -23,7 +23,7 @@ impl<'a> InferenceContext<'a> { if to_ty.is_unknown() { return true; } - let from_ty = self.resolve_ty_shallow(from_ty).into_owned(); + let from_ty = self.resolve_ty_shallow(from_ty); let to_ty = self.resolve_ty_shallow(to_ty); match self.coerce_inner(from_ty, &to_ty) { Ok(_result) => { @@ -46,9 +46,7 @@ impl<'a> InferenceContext<'a> { /// least upper bound. pub(super) fn coerce_merge_branch(&mut self, ty1: &Ty, ty2: &Ty) -> Ty { let ty1 = self.resolve_ty_shallow(ty1); - let ty1 = ty1.as_ref(); let ty2 = self.resolve_ty_shallow(ty2); - let ty2 = ty2.as_ref(); // Special case: two function types. Try to coerce both to // pointers to have a chance at getting a match. See // https://github.com/rust-lang/rust/blob/7b805396bf46dce972692a6846ce2ad8481c5f85/src/librustc_typeck/check/coercion.rs#L877-L916 @@ -80,9 +78,9 @@ impl<'a> InferenceContext<'a> { // type is a type variable and the new one is `!`, trying it the other // way around first would mean we make the type variable `!`, instead of // just marking it as possibly diverging. - if self.coerce(ty2, ty1) { + if self.coerce(&ty2, &ty1) { ty1.clone() - } else if self.coerce(ty1, ty2) { + } else if self.coerce(&ty1, &ty2) { ty2.clone() } else { // TODO record a type mismatch diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs index 75e04e8b5..278127c69 100644 --- a/crates/hir_ty/src/infer/unify.rs +++ b/crates/hir_ty/src/infer/unify.rs @@ -1,6 +1,6 @@ //! Unification and canonicalization logic. -use std::{borrow::Cow, fmt, mem, sync::Arc}; +use std::{fmt, mem, sync::Arc}; use chalk_ir::{ cast::Cast, fold::Fold, interner::HasInterner, zip::Zip, FloatTy, IntTy, TyVariableKind, @@ -340,11 +340,8 @@ impl<'a> InferenceTable<'a> { /// If `ty` is a type variable with known type, returns that type; /// otherwise, return ty. - // FIXME this could probably just return Ty - pub(crate) fn resolve_ty_shallow<'b>(&mut self, ty: &'b Ty) -> Cow<'b, Ty> { - self.var_unification_table - .normalize_ty_shallow(&Interner, ty) - .map_or(Cow::Borrowed(ty), Cow::Owned) + pub(crate) fn resolve_ty_shallow(&mut self, ty: &Ty) -> Ty { + self.var_unification_table.normalize_ty_shallow(&Interner, ty).unwrap_or_else(|| ty.clone()) } /// Resolves the type as far as currently possible, replacing type variables -- cgit v1.2.3