File tree Expand file tree Collapse file tree 4 files changed +41
-0
lines changed
compiler/rustc_trait_selection/src/solve
tests/ui/traits/new-solver Expand file tree Collapse file tree 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 {
209209 ecx : & mut EvalCtxt < ' _ , ' tcx > ,
210210 goal : Goal < ' tcx , Self > ,
211211 ) -> QueryResult < ' tcx > ;
212+
213+ fn consider_builtin_destruct_candidate (
214+ ecx : & mut EvalCtxt < ' _ , ' tcx > ,
215+ goal : Goal < ' tcx , Self > ,
216+ ) -> QueryResult < ' tcx > ;
212217}
213218
214219impl < ' tcx > EvalCtxt < ' _ , ' tcx > {
@@ -336,6 +341,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
336341 G :: consider_builtin_unsize_candidate ( self , goal)
337342 } else if lang_items. discriminant_kind_trait ( ) == Some ( trait_def_id) {
338343 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)
339346 } else {
340347 Err ( NoSolution )
341348 } ;
Original file line number Diff line number Diff line change @@ -483,6 +483,13 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
483483 ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
484484 } )
485485 }
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+ }
486493}
487494
488495/// 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> {
513513 // `DiscriminantKind` is automatically implemented for every type.
514514 ecx. evaluate_added_goals_and_make_canonical_response ( Certainty :: Yes )
515515 }
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+ }
516530}
517531
518532impl < ' 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