internal: allow ambiguous unsize coercion.
This commit is contained in:
parent
3981373b93
commit
72002b401d
1 changed files with 9 additions and 6 deletions
|
|
@ -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<InferOk<(Vec<Adjustment>, 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<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 @@ 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() };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue