Skip to content

Commit a1c7059

Browse files
committed
Treat ManuallyDrop as ~const Destruct
1 parent 923ca85 commit a1c7059

File tree

5 files changed

+7
-23
lines changed

5 files changed

+7
-23
lines changed

compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs

+3
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,9 @@ pub(in crate::solve) fn const_conditions_for_destruct<I: Interner>(
724724
let destruct_def_id = cx.require_lang_item(TraitSolverLangItem::Destruct);
725725

726726
match self_ty.kind() {
727+
// `ManuallyDrop` is trivially `~const Destruct` as we do not run any drop glue on it.
728+
ty::Adt(adt_def, _) if adt_def.is_manually_drop() => Ok(vec![]),
729+
727730
// An ADT is `~const Destruct` only if all of the fields are,
728731
// *and* if there is a `Drop` impl, that `Drop` impl is also `~const`.
729732
ty::Adt(adt_def, args) => {

compiler/rustc_trait_selection/src/traits/effects.rs

+3
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ fn evaluate_host_effect_for_destruct_goal<'tcx>(
252252
let self_ty = obligation.predicate.self_ty();
253253

254254
let const_conditions = match *self_ty.kind() {
255+
// `ManuallyDrop` is trivially `~const Destruct` as we do not run any drop glue on it.
256+
ty::Adt(adt_def, _) if adt_def.is_manually_drop() => thin_vec![],
257+
255258
// An ADT is `~const Destruct` only if all of the fields are,
256259
// *and* if there is a `Drop` impl, that `Drop` impl is also `~const`.
257260
ty::Adt(adt_def, args) => {

tests/ui/traits/const-traits/drop-manually-drop.new.stderr

-11
This file was deleted.

tests/ui/traits/const-traits/drop-manually-drop.old.stderr

-11
This file was deleted.

tests/ui/traits/const-traits/drop-manually-drop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//@[new] compile-flags: -Znext-solver
22
//@ revisions: old new
3+
//@ check-pass
34

45
#![feature(const_destruct)]
56
#![feature(const_trait_impl)]
@@ -19,6 +20,5 @@ impl<T> const Drop for ConstDropper<T> {
1920
}
2021

2122
const fn foo(_var: ConstDropper<Moose>) {}
22-
//~^ ERROR destructor of `ConstDropper<Moose>` cannot be evaluated at compile-time
2323

2424
fn main() {}

0 commit comments

Comments
 (0)