internal: allow ambiguous unsize coercion.
This commit is contained in:
parent
3981373b93
commit
72002b401d
@ -17,8 +17,8 @@
|
||||
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<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),
|
||||
};
|
||||
|
||||
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 @@ fn try_coerce_unsized(&mut self, from_ty: &Ty, to_ty: &Ty) -> CoerceResult {
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
@ -575,8 +575,11 @@ fn try_coerce_unsized(&mut self, from_ty: &Ty, to_ty: &Ty) -> CoerceResult {
|
||||
},
|
||||
);
|
||||
}
|
||||
// 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() };
|
||||
|
Loading…
Reference in New Issue
Block a user