Skip to content

Commit 5e0859c

Browse files
trait_goals: param-env candidates
1 parent 8f3aa6d commit 5e0859c

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

compiler/rustc_trait_selection/src/solve/assembly.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ pub(super) trait GoalKind<'tcx>: TypeFoldable<'tcx> + Copy {
5656
goal: Goal<'tcx, Self>,
5757
object_bounds: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
5858
);
59+
60+
fn consider_param_env_candidates(
61+
acx: &mut AssemblyCtxt<'_, 'tcx, Self>,
62+
goal: Goal<'tcx, Self>,
63+
);
5964
}
6065

6166
/// An abstraction which correctly deals with the canonical results for candidates.
@@ -83,6 +88,8 @@ impl<'a, 'tcx, G: GoalKind<'tcx>> AssemblyCtxt<'a, 'tcx, G> {
8388

8489
acx.assemble_bound_candidates(goal);
8590

91+
acx.assemble_param_env_candidates(goal);
92+
8693
acx.candidates
8794
}
8895

@@ -171,4 +178,8 @@ impl<'a, 'tcx, G: GoalKind<'tcx>> AssemblyCtxt<'a, 'tcx, G> {
171178
_ => {}
172179
}
173180
}
181+
182+
fn assemble_param_env_candidates(&mut self, goal: Goal<'tcx, G>) {
183+
G::consider_param_env_candidates(self, goal);
184+
}
174185
}

compiler/rustc_trait_selection/src/solve/project_goals.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,13 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
227227
) {
228228
todo!()
229229
}
230+
231+
fn consider_param_env_candidates(
232+
_acx: &mut AssemblyCtxt<'_, 'tcx, Self>,
233+
_goal: Goal<'tcx, Self>,
234+
) {
235+
todo!()
236+
}
230237
}
231238

232239
/// This behavior is also implemented in `rustc_ty_utils` and in the old `project` code.

compiler/rustc_trait_selection/src/solve/trait_goals.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,28 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
169169
acx.try_insert_candidate(CandidateSource::ObjectAutoBound, Certainty::Yes);
170170
}
171171
}
172+
173+
fn consider_param_env_candidates(
174+
acx: &mut AssemblyCtxt<'_, 'tcx, Self>,
175+
goal: Goal<'tcx, Self>,
176+
) {
177+
for (idx, predicate) in goal.param_env.caller_bounds().iter().enumerate() {
178+
let Some(poly_trait_pred) = predicate.to_opt_poly_trait_pred() else { continue };
179+
if poly_trait_pred.skip_binder().def_id() != goal.predicate.def_id() {
180+
continue;
181+
};
182+
// FIXME: constness? polarity?
183+
let poly_trait_ref = poly_trait_pred.map_bound(|trait_pred| trait_pred.trait_ref);
184+
// FIXME: Faster to do a filter first with a rejection context?
185+
186+
match_poly_trait_ref_against_goal(
187+
acx,
188+
goal,
189+
poly_trait_ref,
190+
CandidateSource::ParamEnv(idx),
191+
);
192+
}
193+
}
172194
}
173195

174196
fn match_poly_trait_ref_against_goal<'tcx>(

0 commit comments

Comments
 (0)