File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed
compiler/rustc_trait_selection/src/solve Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,7 @@ pub(super) enum CandidateSource {
7979 AliasBound ( usize ) ,
8080}
8181
82+ /// Methods used to assemble candidates for either trait or projection goals.
8283pub ( super ) trait GoalKind < ' tcx > : TypeFoldable < ' tcx > + Copy + Eq {
8384 fn self_ty ( self ) -> Ty < ' tcx > ;
8485
@@ -148,6 +149,11 @@ pub(super) trait GoalKind<'tcx>: TypeFoldable<'tcx> + Copy + Eq {
148149 ecx : & mut EvalCtxt < ' _ , ' tcx > ,
149150 goal : Goal < ' tcx , Self > ,
150151 ) -> QueryResult < ' tcx > ;
152+
153+ fn consider_builtin_discriminant_kind_candidate (
154+ ecx : & mut EvalCtxt < ' _ , ' tcx > ,
155+ goal : Goal < ' tcx , Self > ,
156+ ) -> QueryResult < ' tcx > ;
151157}
152158
153159impl < ' tcx > EvalCtxt < ' _ , ' tcx > {
@@ -280,6 +286,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
280286 G :: consider_builtin_future_candidate ( self , goal)
281287 } else if lang_items. gen_trait ( ) == Some ( trait_def_id) {
282288 G :: consider_builtin_generator_candidate ( self , goal)
289+ } else if lang_items. discriminant_kind_trait ( ) == Some ( trait_def_id) {
290+ G :: consider_builtin_discriminant_kind_candidate ( self , goal)
283291 } else {
284292 Err ( NoSolution )
285293 } ;
Original file line number Diff line number Diff line change @@ -551,6 +551,26 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
551551 . to_predicate ( tcx) ,
552552 )
553553 }
554+
555+ fn consider_builtin_discriminant_kind_candidate (
556+ ecx : & mut EvalCtxt < ' _ , ' tcx > ,
557+ goal : Goal < ' tcx , Self > ,
558+ ) -> QueryResult < ' tcx > {
559+ let self_ty = goal. predicate . self_ty ( ) ;
560+
561+ let tcx = ecx. tcx ( ) ;
562+ let term = self_ty. discriminant_ty ( tcx) . into ( ) ;
563+
564+ Self :: consider_assumption (
565+ ecx,
566+ goal,
567+ ty:: Binder :: dummy ( ty:: ProjectionPredicate {
568+ projection_ty : tcx. mk_alias_ty ( goal. predicate . def_id ( ) , [ self_ty] ) ,
569+ term,
570+ } )
571+ . to_predicate ( tcx) ,
572+ )
573+ }
554574}
555575
556576/// This behavior is also implemented in `rustc_ty_utils` and in the old `project` code.
Original file line number Diff line number Diff line change @@ -236,6 +236,14 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
236236 . to_predicate ( tcx) ,
237237 )
238238 }
239+
240+ fn consider_builtin_discriminant_kind_candidate (
241+ ecx : & mut EvalCtxt < ' _ , ' tcx > ,
242+ _goal : Goal < ' tcx , Self > ,
243+ ) -> QueryResult < ' tcx > {
244+ // `DiscriminantKind` is automatically implemented for every type.
245+ ecx. make_canonical_response ( Certainty :: Yes )
246+ }
239247}
240248
241249impl < ' tcx > EvalCtxt < ' _ , ' tcx > {
You can’t perform that action at this time.
0 commit comments