Skip to content

Commit a34c927

Browse files
Implement non-const Destruct trait in new solver
1 parent 439292b commit a34c927

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

compiler/rustc_trait_selection/src/solve/assembly.rs

+7
Original file line numberDiff line numberDiff 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

214219
impl<'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
};

compiler/rustc_trait_selection/src/solve/project_goals.rs

+7
Original file line numberDiff line numberDiff 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.

compiler/rustc_trait_selection/src/solve/trait_goals.rs

+14
Original file line numberDiff line numberDiff 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

518532
impl<'tcx> EvalCtxt<'_, 'tcx> {
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}

0 commit comments

Comments
 (0)