File tree 4 files changed +41
-0
lines changed
compiler/rustc_trait_selection/src/solve
tests/ui/traits/new-solver
4 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -209,6 +209,11 @@ pub(super) trait GoalKind<'tcx>: TypeFoldable<TyCtxt<'tcx>> + Copy + Eq {
209
209
ecx : & mut EvalCtxt < ' _ , ' tcx > ,
210
210
goal : Goal < ' tcx , Self > ,
211
211
) -> QueryResult < ' tcx > ;
212
+
213
+ fn consider_builtin_destruct_candidate (
214
+ ecx : & mut EvalCtxt < ' _ , ' tcx > ,
215
+ goal : Goal < ' tcx , Self > ,
216
+ ) -> QueryResult < ' tcx > ;
212
217
}
213
218
214
219
impl < ' tcx > EvalCtxt < ' _ , ' tcx > {
@@ -336,6 +341,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
336
341
G :: consider_builtin_unsize_candidate ( self , goal)
337
342
} else if lang_items. discriminant_kind_trait ( ) == Some ( trait_def_id) {
338
343
G :: consider_builtin_discriminant_kind_candidate ( self , goal)
344
+ } else if lang_items. destruct_trait ( ) == Some ( trait_def_id) {
345
+ G :: consider_builtin_destruct_candidate ( self , goal)
339
346
} else {
340
347
Err ( NoSolution )
341
348
} ;
Original file line number Diff line number Diff line change @@ -483,6 +483,13 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
483
483
ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
484
484
} )
485
485
}
486
+
487
+ fn consider_builtin_destruct_candidate (
488
+ _ecx : & mut EvalCtxt < ' _ , ' tcx > ,
489
+ goal : Goal < ' tcx , Self > ,
490
+ ) -> QueryResult < ' tcx > {
491
+ bug ! ( "`Destruct` does not have an associated type: {:?}" , goal) ;
492
+ }
486
493
}
487
494
488
495
/// 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 @@ -513,6 +513,20 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
513
513
// `DiscriminantKind` is automatically implemented for every type.
514
514
ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
515
515
}
516
+
517
+ fn consider_builtin_destruct_candidate (
518
+ ecx : & mut EvalCtxt < ' _ , ' tcx > ,
519
+ goal : Goal < ' tcx , Self > ,
520
+ ) -> QueryResult < ' tcx > {
521
+ if !goal. param_env . is_const ( ) {
522
+ // `Destruct` is automatically implemented for every type in
523
+ // non-const environments.
524
+ ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
525
+ } else {
526
+ // FIXME(-Ztrait-solver=next): Implement this when we get const working in the new solver
527
+ Err ( NoSolution )
528
+ }
529
+ }
516
530
}
517
531
518
532
impl < ' tcx > EvalCtxt < ' _ , ' tcx > {
Original file line number Diff line number Diff line change
1
+ // compile-flags: -Ztrait-solver=next
2
+ // check-pass
3
+
4
+ #![ feature( const_trait_impl) ]
5
+
6
+ fn foo ( _: impl std:: marker:: Destruct ) { }
7
+
8
+ struct MyAdt ;
9
+
10
+ fn main ( ) {
11
+ foo ( 1 ) ;
12
+ foo ( MyAdt ) ;
13
+ }
You can’t perform that action at this time.
0 commit comments