internal: allow ambiguous unsize coercion.

This commit is contained in:
Dawer 2021-06-09 11:49:12 +05:00
parent 3981373b93
commit 72002b401d

View File

@ -17,8 +17,8 @@
Adjust, Adjustment, AutoBorrow, InferOk, InferResult, InferenceContext, OverloadedDeref, Adjust, Adjustment, AutoBorrow, InferOk, InferResult, InferenceContext, OverloadedDeref,
PointerCast, TypeError, TypeMismatch, PointerCast, TypeError, TypeMismatch,
}, },
static_lifetime, Canonical, DomainGoal, FnPointer, FnSig, InEnvironment, Interner, Solution, static_lifetime, Canonical, DomainGoal, FnPointer, FnSig, Guidance, InEnvironment, Interner,
Substitution, Ty, TyBuilder, TyExt, TyKind, Solution, Substitution, Ty, TyBuilder, TyExt, TyKind,
}; };
pub(crate) type CoerceResult = Result<InferOk<(Vec<Adjustment>, Ty)>, TypeError>; pub(crate) type CoerceResult = Result<InferOk<(Vec<Adjustment>, Ty)>, TypeError>;
@ -541,7 +541,7 @@ fn try_coerce_unsized(&mut self, from_ty: &Ty, to_ty: &Ty) -> CoerceResult {
_ => return Err(TypeError), _ => return Err(TypeError),
}; };
let trait_ref = { let coerce_unsized_tref = {
let b = TyBuilder::trait_ref(self.db, coerce_unsized_trait); let b = TyBuilder::trait_ref(self.db, coerce_unsized_trait);
if b.remaining() != 2 { if b.remaining() != 2 {
// The CoerceUnsized trait should have two generic params: Self and T. // The CoerceUnsized trait should have two generic params: Self and T.
@ -551,7 +551,7 @@ fn try_coerce_unsized(&mut self, from_ty: &Ty, to_ty: &Ty) -> CoerceResult {
}; };
let goal: InEnvironment<DomainGoal> = let goal: InEnvironment<DomainGoal> =
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); let canonicalized = self.canonicalize(goal);
@ -575,8 +575,11 @@ fn try_coerce_unsized(&mut self, from_ty: &Ty, to_ty: &Ty) -> CoerceResult {
}, },
); );
} }
// FIXME: should we accept ambiguous results here? Solution::Ambig(guidance) => {
_ => return Err(TypeError), if let Guidance::Definite(subst) = guidance {
canonicalized.apply_solution(&mut self.table, subst);
}
}
}; };
let unsize = let unsize =
Adjustment { kind: Adjust::Pointer(PointerCast::Unsize), target: to_ty.clone() }; Adjustment { kind: Adjust::Pointer(PointerCast::Unsize), target: to_ty.clone() };