File tree 3 files changed +36
-0
lines changed
compiler/rustc_trait_selection/src/solve
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 {
79
79
AliasBound ( usize ) ,
80
80
}
81
81
82
+ /// Methods used to assemble candidates for either trait or projection goals.
82
83
pub ( super ) trait GoalKind < ' tcx > : TypeFoldable < ' tcx > + Copy + Eq {
83
84
fn self_ty ( self ) -> Ty < ' tcx > ;
84
85
@@ -148,6 +149,11 @@ pub(super) trait GoalKind<'tcx>: TypeFoldable<'tcx> + Copy + Eq {
148
149
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
149
150
goal : Goal < ' tcx , Self > ,
150
151
) -> QueryResult < ' tcx > ;
152
+
153
+ fn consider_builtin_discriminant_kind_candidate (
154
+ ecx : & mut EvalCtxt < ' _ , ' tcx > ,
155
+ goal : Goal < ' tcx , Self > ,
156
+ ) -> QueryResult < ' tcx > ;
151
157
}
152
158
153
159
impl < ' tcx > EvalCtxt < ' _ , ' tcx > {
@@ -280,6 +286,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
280
286
G :: consider_builtin_future_candidate ( self , goal)
281
287
} else if lang_items. gen_trait ( ) == Some ( trait_def_id) {
282
288
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)
283
291
} else {
284
292
Err ( NoSolution )
285
293
} ;
Original file line number Diff line number Diff line change @@ -551,6 +551,26 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
551
551
. to_predicate ( tcx) ,
552
552
)
553
553
}
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
+ }
554
574
}
555
575
556
576
/// 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> {
236
236
. to_predicate ( tcx) ,
237
237
)
238
238
}
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
+ }
239
247
}
240
248
241
249
impl < ' tcx > EvalCtxt < ' _ , ' tcx > {
You can’t perform that action at this time.
0 commit comments