Skip to content

Commit 72002b4

Browse files
committed
internal: allow ambiguous unsize coercion.
1 parent 3981373 commit 72002b4

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

crates/hir_ty/src/infer/coerce.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use crate::{
1717
Adjust, Adjustment, AutoBorrow, InferOk, InferResult, InferenceContext, OverloadedDeref,
1818
PointerCast, TypeError, TypeMismatch,
1919
},
20-
static_lifetime, Canonical, DomainGoal, FnPointer, FnSig, InEnvironment, Interner, Solution,
21-
Substitution, Ty, TyBuilder, TyExt, TyKind,
20+
static_lifetime, Canonical, DomainGoal, FnPointer, FnSig, Guidance, InEnvironment, Interner,
21+
Solution, Substitution, Ty, TyBuilder, TyExt, TyKind,
2222
};
2323

2424
pub(crate) type CoerceResult = Result<InferOk<(Vec<Adjustment>, Ty)>, TypeError>;
@@ -541,7 +541,7 @@ impl<'a> InferenceContext<'a> {
541541
_ => return Err(TypeError),
542542
};
543543

544-
let trait_ref = {
544+
let coerce_unsized_tref = {
545545
let b = TyBuilder::trait_ref(self.db, coerce_unsized_trait);
546546
if b.remaining() != 2 {
547547
// The CoerceUnsized trait should have two generic params: Self and T.
@@ -551,7 +551,7 @@ impl<'a> InferenceContext<'a> {
551551
};
552552

553553
let goal: InEnvironment<DomainGoal> =
554-
InEnvironment::new(&self.trait_env.env, trait_ref.cast(&Interner));
554+
InEnvironment::new(&self.trait_env.env, coerce_unsized_tref.cast(&Interner));
555555

556556
let canonicalized = self.canonicalize(goal);
557557

@@ -575,8 +575,11 @@ impl<'a> InferenceContext<'a> {
575575
},
576576
);
577577
}
578-
// FIXME: should we accept ambiguous results here?
579-
_ => return Err(TypeError),
578+
Solution::Ambig(guidance) => {
579+
if let Guidance::Definite(subst) = guidance {
580+
canonicalized.apply_solution(&mut self.table, subst);
581+
}
582+
}
580583
};
581584
let unsize =
582585
Adjustment { kind: Adjust::Pointer(PointerCast::Unsize), target: to_ty.clone() };

0 commit comments

Comments
 (0)