Skip to content

Commit 8be5720

Browse files
committed
hack for dyn
1 parent 61ed0bc commit 8be5720

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs

+29-24
Original file line numberDiff line numberDiff line change
@@ -887,8 +887,13 @@ where
887887
}
888888
}
889889

890-
let mut folder =
891-
ReplaceProjectionWith { ecx, param_env, mapping: replace_projection_with, nested: vec![] };
890+
let mut folder = ReplaceProjectionWith {
891+
ecx,
892+
param_env,
893+
mapping: replace_projection_with,
894+
self_ty: trait_ref.self_ty(),
895+
nested: vec![],
896+
};
892897
let folded_requirements = requirements.fold_with(&mut folder);
893898

894899
folder
@@ -902,6 +907,7 @@ struct ReplaceProjectionWith<'a, D: SolverDelegate<Interner = I>, I: Interner> {
902907
ecx: &'a EvalCtxt<'a, D>,
903908
param_env: I::ParamEnv,
904909
mapping: HashMap<I::DefId, ty::Binder<I, ty::ProjectionPredicate<I>>>,
910+
self_ty: I::Ty,
905911
nested: Vec<Goal<I, I::Predicate>>,
906912
}
907913

@@ -914,29 +920,28 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I>
914920

915921
fn fold_ty(&mut self, ty: I::Ty) -> I::Ty {
916922
if let ty::Alias(ty::Projection, alias_ty) = ty.kind() {
917-
if let Some(replacement) = self.mapping.get(&alias_ty.def_id) {
918-
// We may have a case where our object type's projection bound is higher-ranked,
919-
// but the where clauses we instantiated are not. We can solve this by instantiating
920-
// the binder at the usage site.
921-
let proj = self.ecx.instantiate_binder_with_infer(*replacement);
922-
// FIXME: Technically this equate could be fallible...
923-
self.nested.extend(
924-
self.ecx
925-
.eq_and_get_goals(
926-
self.param_env,
927-
alias_ty,
928-
proj.projection_term.expect_ty(self.ecx.cx()),
929-
)
930-
.expect(
931-
"expected to be able to unify goal projection with dyn's projection",
932-
),
933-
);
934-
proj.term.expect_ty()
935-
} else {
936-
ty.super_fold_with(self)
923+
if alias_ty.self_ty() == self.self_ty {
924+
if let Some(replacement) = self.mapping.get(&alias_ty.def_id) {
925+
// We may have a case where our object type's projection bound is higher-ranked,
926+
// but the where clauses we instantiated are not. We can solve this by instantiating
927+
// the binder at the usage site.
928+
let proj = self.ecx.instantiate_binder_with_infer(*replacement);
929+
// FIXME: Technically this equate could be fallible...
930+
self.nested.extend(
931+
self.ecx
932+
.eq_and_get_goals(
933+
self.param_env,
934+
alias_ty,
935+
proj.projection_term.expect_ty(self.ecx.cx()),
936+
)
937+
.expect(
938+
"expected to be able to unify goal projection with dyn's projection",
939+
),
940+
);
941+
return proj.term.expect_ty();
942+
}
937943
}
938-
} else {
939-
ty.super_fold_with(self)
940944
}
945+
ty.super_fold_with(self)
941946
}
942947
}

0 commit comments

Comments
 (0)