about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <github333195615777966@oli-obk.de>2025-04-29 10:20:16 +0000
committerOli Scherer <github333195615777966@oli-obk.de>2025-04-29 10:39:54 +0000
commita1c70590b26943370975dd04986739901a31f5db (patch)
tree4aeb49fa9d4e008e48de5340f5e1f9481bdef495
parent923ca85a18e576ac0b132e6adf41541285f55ccc (diff)
downloadrust-a1c70590b26943370975dd04986739901a31f5db.tar.gz
rust-a1c70590b26943370975dd04986739901a31f5db.zip
Treat `ManuallyDrop` as `~const Destruct`
-rw-r--r--compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs3
-rw-r--r--compiler/rustc_trait_selection/src/traits/effects.rs3
-rw-r--r--tests/ui/traits/const-traits/drop-manually-drop.new.stderr11
-rw-r--r--tests/ui/traits/const-traits/drop-manually-drop.old.stderr11
-rw-r--r--tests/ui/traits/const-traits/drop-manually-drop.rs2
5 files changed, 7 insertions, 23 deletions
diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs
index 035bfff89b5..b16f74cd8e4 100644
--- a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs
+++ b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs
@@ -724,6 +724,9 @@ pub(in crate::solve) fn const_conditions_for_destruct<I: Interner>(
     let destruct_def_id = cx.require_lang_item(TraitSolverLangItem::Destruct);
 
     match self_ty.kind() {
+        // `ManuallyDrop` is trivially `~const Destruct` as we do not run any drop glue on it.
+        ty::Adt(adt_def, _) if adt_def.is_manually_drop() => Ok(vec![]),
+
         // An ADT is `~const Destruct` only if all of the fields are,
         // *and* if there is a `Drop` impl, that `Drop` impl is also `~const`.
         ty::Adt(adt_def, args) => {
diff --git a/compiler/rustc_trait_selection/src/traits/effects.rs b/compiler/rustc_trait_selection/src/traits/effects.rs
index defbafac20b..1b5dcef2e59 100644
--- a/compiler/rustc_trait_selection/src/traits/effects.rs
+++ b/compiler/rustc_trait_selection/src/traits/effects.rs
@@ -252,6 +252,9 @@ fn evaluate_host_effect_for_destruct_goal<'tcx>(
     let self_ty = obligation.predicate.self_ty();
 
     let const_conditions = match *self_ty.kind() {
+        // `ManuallyDrop` is trivially `~const Destruct` as we do not run any drop glue on it.
+        ty::Adt(adt_def, _) if adt_def.is_manually_drop() => thin_vec![],
+
         // An ADT is `~const Destruct` only if all of the fields are,
         // *and* if there is a `Drop` impl, that `Drop` impl is also `~const`.
         ty::Adt(adt_def, args) => {
diff --git a/tests/ui/traits/const-traits/drop-manually-drop.new.stderr b/tests/ui/traits/const-traits/drop-manually-drop.new.stderr
deleted file mode 100644
index ab152f73897..00000000000
--- a/tests/ui/traits/const-traits/drop-manually-drop.new.stderr
+++ /dev/null
@@ -1,11 +0,0 @@
-error[E0493]: destructor of `ConstDropper<Moose>` cannot be evaluated at compile-time
-  --> $DIR/drop-manually-drop.rs:21:14
-   |
-LL | const fn foo(_var: ConstDropper<Moose>) {}
-   |              ^^^^                        - value is dropped here
-   |              |
-   |              the destructor for this type cannot be evaluated in constant functions
-
-error: aborting due to 1 previous error
-
-For more information about this error, try `rustc --explain E0493`.
diff --git a/tests/ui/traits/const-traits/drop-manually-drop.old.stderr b/tests/ui/traits/const-traits/drop-manually-drop.old.stderr
deleted file mode 100644
index ab152f73897..00000000000
--- a/tests/ui/traits/const-traits/drop-manually-drop.old.stderr
+++ /dev/null
@@ -1,11 +0,0 @@
-error[E0493]: destructor of `ConstDropper<Moose>` cannot be evaluated at compile-time
-  --> $DIR/drop-manually-drop.rs:21:14
-   |
-LL | const fn foo(_var: ConstDropper<Moose>) {}
-   |              ^^^^                        - value is dropped here
-   |              |
-   |              the destructor for this type cannot be evaluated in constant functions
-
-error: aborting due to 1 previous error
-
-For more information about this error, try `rustc --explain E0493`.
diff --git a/tests/ui/traits/const-traits/drop-manually-drop.rs b/tests/ui/traits/const-traits/drop-manually-drop.rs
index 9dd3c1e2281..62e8a815f10 100644
--- a/tests/ui/traits/const-traits/drop-manually-drop.rs
+++ b/tests/ui/traits/const-traits/drop-manually-drop.rs
@@ -1,5 +1,6 @@
 //@[new] compile-flags: -Znext-solver
 //@ revisions: old new
+//@ check-pass
 
 #![feature(const_destruct)]
 #![feature(const_trait_impl)]
@@ -19,6 +20,5 @@ impl<T> const Drop for ConstDropper<T> {
 }
 
 const fn foo(_var: ConstDropper<Moose>) {}
-//~^ ERROR destructor of `ConstDropper<Moose>` cannot be evaluated at compile-time
 
 fn main() {}