Add candidates for DiscriminantKind builtin
This commit is contained in:
parent
11d96b5930
commit
5fd4f5bceb
3 changed files with 36 additions and 0 deletions
|
@ -81,6 +81,7 @@ pub(super) enum CandidateSource {
|
||||||
AliasBound,
|
AliasBound,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Methods used to assemble candidates for either trait or projection goals.
|
||||||
pub(super) trait GoalKind<'tcx>: TypeFoldable<'tcx> + Copy + Eq {
|
pub(super) trait GoalKind<'tcx>: TypeFoldable<'tcx> + Copy + Eq {
|
||||||
fn self_ty(self) -> Ty<'tcx>;
|
fn self_ty(self) -> Ty<'tcx>;
|
||||||
|
|
||||||
|
@ -188,6 +189,11 @@ pub(super) trait GoalKind<'tcx>: TypeFoldable<'tcx> + Copy + Eq {
|
||||||
ecx: &mut EvalCtxt<'_, 'tcx>,
|
ecx: &mut EvalCtxt<'_, 'tcx>,
|
||||||
goal: Goal<'tcx, Self>,
|
goal: Goal<'tcx, Self>,
|
||||||
) -> Vec<CanonicalResponse<'tcx>>;
|
) -> Vec<CanonicalResponse<'tcx>>;
|
||||||
|
|
||||||
|
fn consider_builtin_discriminant_kind_candidate(
|
||||||
|
ecx: &mut EvalCtxt<'_, 'tcx>,
|
||||||
|
goal: Goal<'tcx, Self>,
|
||||||
|
) -> QueryResult<'tcx>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> EvalCtxt<'_, 'tcx> {
|
impl<'tcx> EvalCtxt<'_, 'tcx> {
|
||||||
|
@ -320,6 +326,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
||||||
G::consider_builtin_generator_candidate(self, goal)
|
G::consider_builtin_generator_candidate(self, goal)
|
||||||
} else if lang_items.unsize_trait() == Some(trait_def_id) {
|
} else if lang_items.unsize_trait() == Some(trait_def_id) {
|
||||||
G::consider_builtin_unsize_candidate(self, goal)
|
G::consider_builtin_unsize_candidate(self, goal)
|
||||||
|
} else if lang_items.discriminant_kind_trait() == Some(trait_def_id) {
|
||||||
|
G::consider_builtin_discriminant_kind_candidate(self, goal)
|
||||||
} else {
|
} else {
|
||||||
Err(NoSolution)
|
Err(NoSolution)
|
||||||
};
|
};
|
||||||
|
|
|
@ -581,6 +581,26 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
|
||||||
) -> Vec<super::CanonicalResponse<'tcx>> {
|
) -> Vec<super::CanonicalResponse<'tcx>> {
|
||||||
bug!("`Unsize` does not have an associated type: {:?}", goal);
|
bug!("`Unsize` does not have an associated type: {:?}", goal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn consider_builtin_discriminant_kind_candidate(
|
||||||
|
ecx: &mut EvalCtxt<'_, 'tcx>,
|
||||||
|
goal: Goal<'tcx, Self>,
|
||||||
|
) -> QueryResult<'tcx> {
|
||||||
|
let self_ty = goal.predicate.self_ty();
|
||||||
|
|
||||||
|
let tcx = ecx.tcx();
|
||||||
|
let term = self_ty.discriminant_ty(tcx).into();
|
||||||
|
|
||||||
|
Self::consider_assumption(
|
||||||
|
ecx,
|
||||||
|
goal,
|
||||||
|
ty::Binder::dummy(ty::ProjectionPredicate {
|
||||||
|
projection_ty: tcx.mk_alias_ty(goal.predicate.def_id(), [self_ty]),
|
||||||
|
term,
|
||||||
|
})
|
||||||
|
.to_predicate(tcx),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This behavior is also implemented in `rustc_ty_utils` and in the old `project` code.
|
/// This behavior is also implemented in `rustc_ty_utils` and in the old `project` code.
|
||||||
|
|
|
@ -439,6 +439,14 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
|
||||||
|
|
||||||
responses
|
responses
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn consider_builtin_discriminant_kind_candidate(
|
||||||
|
ecx: &mut EvalCtxt<'_, 'tcx>,
|
||||||
|
_goal: Goal<'tcx, Self>,
|
||||||
|
) -> QueryResult<'tcx> {
|
||||||
|
// `DiscriminantKind` is automatically implemented for every type.
|
||||||
|
ecx.make_canonical_response(Certainty::Yes)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> EvalCtxt<'_, 'tcx> {
|
impl<'tcx> EvalCtxt<'_, 'tcx> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue