Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/infer/coerce.rs')
-rw-r--r--crates/hir-ty/src/infer/coerce.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/crates/hir-ty/src/infer/coerce.rs b/crates/hir-ty/src/infer/coerce.rs
index ff6de61ba6..cfbbc9dd6c 100644
--- a/crates/hir-ty/src/infer/coerce.rs
+++ b/crates/hir-ty/src/infer/coerce.rs
@@ -276,6 +276,23 @@ impl InferenceTable<'_> {
return success(simple(Adjust::NeverToAny)(to_ty.clone()), to_ty.clone(), vec![]);
}
+ // If we are coercing into an ATPIT, coerce into its proxy inference var, instead.
+ let mut to_ty = to_ty;
+ let _to;
+ if let Some(atpit_table) = &self.atpit_coercion_table {
+ if let TyKind::OpaqueType(opaque_ty_id, _) = to_ty.kind(Interner) {
+ if !matches!(
+ from_ty.kind(Interner),
+ TyKind::InferenceVar(..) | TyKind::OpaqueType(..)
+ ) {
+ if let Some(ty) = atpit_table.get(opaque_ty_id) {
+ _to = ty.clone();
+ to_ty = &_to;
+ }
+ }
+ }
+ }
+
// Consider coercing the subtype to a DST
if let Ok(ret) = self.try_coerce_unsized(&from_ty, to_ty) {
return Ok(ret);