about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-11-21 23:20:59 +0000
committerMichael Goulet <michael@errs.io>2024-11-22 17:01:02 +0000
commit69a38de97755780a5d78c655da2c953ba58ae18f (patch)
treef2bd84ef4fa96470fa31daee440bea8926bb8f61 /compiler
parentaf0d566e76a709caa2a89123202f583cbcc877e2 (diff)
downloadrust-69a38de97755780a5d78c655da2c953ba58ae18f.tar.gz
rust-69a38de97755780a5d78c655da2c953ba58ae18f.zip
Check drop is trivial before checking ty needs drop
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_const_eval/src/check_consts/qualifs.rs7
-rw-r--r--compiler/rustc_feature/src/unstable.rs2
-rw-r--r--compiler/rustc_middle/src/ty/context.rs5
3 files changed, 11 insertions, 3 deletions
diff --git a/compiler/rustc_const_eval/src/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/check_consts/qualifs.rs
index accce883e39..39eb1a7db78 100644
--- a/compiler/rustc_const_eval/src/check_consts/qualifs.rs
+++ b/compiler/rustc_const_eval/src/check_consts/qualifs.rs
@@ -175,6 +175,11 @@ impl Qualif for NeedsNonConstDrop {
             return false;
         }
 
+        // If this doesn't need drop at all, then don't select `~const Destruct`.
+        if !ty.needs_drop(cx.tcx, cx.typing_env) {
+            return false;
+        }
+
         // We check that the type is `~const Destruct` since that will verify that
         // the type is both `~const Drop` (if a drop impl exists for the adt), *and*
         // that the components of this type are also `~const Destruct`. This
@@ -203,7 +208,7 @@ impl Qualif for NeedsNonConstDrop {
         // in its value since:
         // 1. The destructor may have `~const` bounds which are not present on the type.
         //   Someone needs to check that those are satisfied.
-        //   While this could be done instead satisfied by checking that the `~const Drop`
+        //   While this could be instead satisfied by checking that the `~const Drop`
         //   impl holds (i.e. replicating part of the `in_any_value_of_ty` logic above),
         //   even in this case, we have another problem, which is,
         // 2. The destructor may *modify* the operand being dropped, so even if we
diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs
index b9a75fedcbe..b376b0d652f 100644
--- a/compiler/rustc_feature/src/unstable.rs
+++ b/compiler/rustc_feature/src/unstable.rs
@@ -426,7 +426,7 @@ declare_features! (
     (unstable, const_async_blocks, "1.53.0", Some(85368)),
     /// Allows `const || {}` closures in const contexts.
     (incomplete, const_closures, "1.68.0", Some(106003)),
-    /// Uwu
+    /// Allows using `~const Destruct` bounds and calling drop impls in const contexts.
     (unstable, const_destruct, "CURRENT_RUSTC_VERSION", Some(133214)),
     /// Allows `for _ in _` loops in const contexts.
     (unstable, const_for, "1.56.0", Some(87575)),
diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs
index 4a0d50c153c..1bd19a6031a 100644
--- a/compiler/rustc_middle/src/ty/context.rs
+++ b/compiler/rustc_middle/src/ty/context.rs
@@ -4,7 +4,7 @@
 
 pub mod tls;
 
-use std::assert_matches::assert_matches;
+use std::assert_matches::{assert_matches, debug_assert_matches};
 use std::borrow::Borrow;
 use std::cmp::Ordering;
 use std::hash::{Hash, Hasher};
@@ -377,14 +377,17 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
     }
 
     fn impl_is_const(self, def_id: DefId) -> bool {
+        debug_assert_matches!(self.def_kind(def_id), DefKind::Impl { of_trait: true });
         self.is_conditionally_const(def_id)
     }
 
     fn fn_is_const(self, def_id: DefId) -> bool {
+        debug_assert_matches!(self.def_kind(def_id), DefKind::Fn | DefKind::AssocFn);
         self.is_conditionally_const(def_id)
     }
 
     fn alias_has_const_conditions(self, def_id: DefId) -> bool {
+        debug_assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::OpaqueTy);
         self.is_conditionally_const(def_id)
     }