diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs index d2e999a730f7..0e6b474486aa 100644 --- a/crates/hir_ty/src/infer/coerce.rs +++ b/crates/hir_ty/src/infer/coerce.rs @@ -17,8 +17,8 @@ use crate::{ Adjust, Adjustment, AutoBorrow, InferOk, InferResult, InferenceContext, OverloadedDeref, PointerCast, TypeError, TypeMismatch, }, - static_lifetime, Canonical, DomainGoal, FnPointer, FnSig, InEnvironment, Interner, Solution, - Substitution, Ty, TyBuilder, TyExt, TyKind, + static_lifetime, Canonical, DomainGoal, FnPointer, FnSig, Guidance, InEnvironment, Interner, + Solution, Substitution, Ty, TyBuilder, TyExt, TyKind, }; pub(crate) type CoerceResult = Result, Ty)>, TypeError>; @@ -541,7 +541,7 @@ impl<'a> InferenceContext<'a> { _ => return Err(TypeError), }; - let trait_ref = { + let coerce_unsized_tref = { let b = TyBuilder::trait_ref(self.db, coerce_unsized_trait); if b.remaining() != 2 { // The CoerceUnsized trait should have two generic params: Self and T. @@ -551,7 +551,7 @@ impl<'a> InferenceContext<'a> { }; let goal: InEnvironment = - InEnvironment::new(&self.trait_env.env, trait_ref.cast(&Interner)); + InEnvironment::new(&self.trait_env.env, coerce_unsized_tref.cast(&Interner)); let canonicalized = self.canonicalize(goal); @@ -575,8 +575,11 @@ impl<'a> InferenceContext<'a> { }, ); } - // FIXME: should we accept ambiguous results here? - _ => return Err(TypeError), + Solution::Ambig(guidance) => { + if let Guidance::Definite(subst) = guidance { + canonicalized.apply_solution(&mut self.table, subst); + } + } }; let unsize = Adjustment { kind: Adjust::Pointer(PointerCast::Unsize), target: to_ty.clone() };