@@ -794,12 +794,17 @@ fn assemble_candidates_from_param_env<'cx, 'tcx>(
794794 obligation: &ProjectionTermObligation<'tcx>,
795795 candidate_set: &mut ProjectionCandidateSet<'tcx>,
796796) {
797- assemble_candidates_from_clauses (
797+ assemble_candidates_from_projection_clauses (
798798 selcx,
799799 obligation,
800800 candidate_set,
801801 ProjectionCandidate::ParamEnv,
802- obligation.param_env.caller_bounds().all_clauses(selcx.tcx()).iter(),
802+ obligation
803+ .param_env
804+ .caller_bounds()
805+ .non_trait_clauses()
806+ .iter()
807+ .filter_map(|i| i.as_projection_clause()),
803808 false,
804809 );
805810}
@@ -914,60 +919,74 @@ fn assemble_candidates_from_object_ty<'cx, 'tcx>(
914919 );
915920}
916921
922+ fn assemble_candidates_from_clauses<'cx, 'tcx>(
923+ selcx: &mut SelectionContext<'cx, 'tcx>,
924+ obligation: &ProjectionTermObligation<'tcx>,
925+ candidate_set: &mut ProjectionCandidateSet<'tcx>,
926+ ctor: fn(ty::PolyProjectionClause<'tcx>) -> ProjectionCandidate<'tcx>,
927+ env_clauses: impl Iterator<Item = ty::Clause<'tcx>>,
928+ potentially_unnormalized_candidates: bool,
929+ ) {
930+ assemble_candidates_from_projection_clauses(
931+ selcx,
932+ obligation,
933+ candidate_set,
934+ ctor,
935+ env_clauses.filter_map(|i| i.as_projection_clause()),
936+ potentially_unnormalized_candidates,
937+ );
938+ }
939+
917940#[instrument(
918941 level = "debug",
919942 skip(selcx, candidate_set, ctor, env_clauses, potentially_unnormalized_candidates)
920943)]
921- fn assemble_candidates_from_clauses <'cx, 'tcx>(
944+ fn assemble_candidates_from_projection_clauses <'cx, 'tcx>(
922945 selcx: &mut SelectionContext<'cx, 'tcx>,
923946 obligation: &ProjectionTermObligation<'tcx>,
924947 candidate_set: &mut ProjectionCandidateSet<'tcx>,
925948 ctor: fn(ty::PolyProjectionClause<'tcx>) -> ProjectionCandidate<'tcx>,
926- env_clauses: impl Iterator<Item = ty::Clause <'tcx>>,
949+ env_clauses: impl Iterator<Item = ty::PolyProjectionClause <'tcx>>,
927950 potentially_unnormalized_candidates: bool,
928951) {
929952 let infcx = selcx.infcx;
930953 let drcx = DeepRejectCtxt::relate_rigid_rigid(selcx.tcx());
931954 for clause in env_clauses {
932- let bound_clause = clause.kind();
933- if let ty::ClauseKind::Projection(data) = clause.kind().skip_binder() {
934- let data = bound_clause.rebind(data);
935- if data.item_def_id() != obligation.predicate.expect_projection_def_id() {
936- continue;
937- }
955+ if clause.item_def_id() != obligation.predicate.expect_projection_def_id() {
956+ continue;
957+ }
938958
939- if !drcx
940- .args_may_unify(obligation.predicate.args, data .skip_binder().projection_term.args)
941- {
942- continue;
943- }
959+ if !drcx
960+ .args_may_unify(obligation.predicate.args, clause .skip_binder().projection_term.args)
961+ {
962+ continue;
963+ }
944964
945- let is_match = infcx.probe(|_| {
946- selcx.match_projection_projections(
947- obligation,
948- data ,
949- potentially_unnormalized_candidates,
950- )
951- });
965+ let is_match = infcx.probe(|_| {
966+ selcx.match_projection_projections(
967+ obligation,
968+ clause ,
969+ potentially_unnormalized_candidates,
970+ )
971+ });
952972
953- match is_match {
954- ProjectionMatchesProjection::Yes => {
955- candidate_set.push_candidate(ctor(data ));
973+ match is_match {
974+ ProjectionMatchesProjection::Yes => {
975+ candidate_set.push_candidate(ctor(clause ));
956976
957- if potentially_unnormalized_candidates
958- && !obligation.predicate.has_non_region_infer()
959- {
960- // HACK: Pick the first trait def candidate for a fully
961- // inferred predicate. This is to allow duplicates that
962- // differ only in normalization.
963- return;
964- }
965- }
966- ProjectionMatchesProjection::Ambiguous => {
967- candidate_set.mark_ambiguous();
977+ if potentially_unnormalized_candidates
978+ && !obligation.predicate.has_non_region_infer()
979+ {
980+ // HACK: Pick the first trait def candidate for a fully
981+ // inferred predicate. This is to allow duplicates that
982+ // differ only in normalization.
983+ return;
968984 }
969- ProjectionMatchesProjection::No => {}
970985 }
986+ ProjectionMatchesProjection::Ambiguous => {
987+ candidate_set.mark_ambiguous();
988+ }
989+ ProjectionMatchesProjection::No => {}
971990 }
972991 }
973992}
0 commit comments