Skip to content

Commit e1bf3a1

Browse files
authored
Rollup merge of #107427 - detrumi:builtin-impl-candidates, r=compiler-errors
Add candidates for DiscriminantKind builtin Part of #107379
2 parents 7221383 + f29000e commit e1bf3a1

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

compiler/rustc_trait_selection/src/solve/assembly.rs

+8
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ pub(super) enum CandidateSource {
8181
AliasBound,
8282
}
8383

84+
/// Methods used to assemble candidates for either trait or projection goals.
8485
pub(super) trait GoalKind<'tcx>: TypeFoldable<'tcx> + Copy + Eq {
8586
fn self_ty(self) -> Ty<'tcx>;
8687

@@ -188,6 +189,11 @@ pub(super) trait GoalKind<'tcx>: TypeFoldable<'tcx> + Copy + Eq {
188189
ecx: &mut EvalCtxt<'_, 'tcx>,
189190
goal: Goal<'tcx, Self>,
190191
) -> Vec<CanonicalResponse<'tcx>>;
192+
193+
fn consider_builtin_discriminant_kind_candidate(
194+
ecx: &mut EvalCtxt<'_, 'tcx>,
195+
goal: Goal<'tcx, Self>,
196+
) -> QueryResult<'tcx>;
191197
}
192198

193199
impl<'tcx> EvalCtxt<'_, 'tcx> {
@@ -320,6 +326,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
320326
G::consider_builtin_generator_candidate(self, goal)
321327
} else if lang_items.unsize_trait() == Some(trait_def_id) {
322328
G::consider_builtin_unsize_candidate(self, goal)
329+
} else if lang_items.discriminant_kind_trait() == Some(trait_def_id) {
330+
G::consider_builtin_discriminant_kind_candidate(self, goal)
323331
} else {
324332
Err(NoSolution)
325333
};

compiler/rustc_trait_selection/src/solve/project_goals.rs

+9
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,15 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
581581
) -> Vec<super::CanonicalResponse<'tcx>> {
582582
bug!("`Unsize` does not have an associated type: {:?}", goal);
583583
}
584+
585+
fn consider_builtin_discriminant_kind_candidate(
586+
ecx: &mut EvalCtxt<'_, 'tcx>,
587+
goal: Goal<'tcx, Self>,
588+
) -> QueryResult<'tcx> {
589+
let discriminant = goal.predicate.self_ty().discriminant_ty(ecx.tcx());
590+
ecx.infcx
591+
.probe(|_| ecx.eq_term_and_make_canonical_response(goal, Certainty::Yes, discriminant))
592+
}
584593
}
585594

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

compiler/rustc_trait_selection/src/solve/trait_goals.rs

+8
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,14 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
439439

440440
responses
441441
}
442+
443+
fn consider_builtin_discriminant_kind_candidate(
444+
ecx: &mut EvalCtxt<'_, 'tcx>,
445+
_goal: Goal<'tcx, Self>,
446+
) -> QueryResult<'tcx> {
447+
// `DiscriminantKind` is automatically implemented for every type.
448+
ecx.make_canonical_response(Certainty::Yes)
449+
}
442450
}
443451

444452
impl<'tcx> EvalCtxt<'_, 'tcx> {

0 commit comments

Comments
 (0)