summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-01-18 17:01:52 -0800
committerMichael Goulet <michael@errs.io>2022-01-18 17:01:52 -0800
commitba87be05cfa8f9a02d673a64aa2ee83976d80e60 (patch)
treea66d71d29d35fceed9131b245af9a02e3132ea2a /compiler/rustc_const_eval/src
parent33e5efbd586cbdc683cb54949fe163755c57e9e8 (diff)
downloadrust-ba87be05cfa8f9a02d673a64aa2ee83976d80e60.tar.gz
rust-ba87be05cfa8f9a02d673a64aa2ee83976d80e60.zip
Short-circuit some trivially const Drop types
Diffstat (limited to 'compiler/rustc_const_eval/src')
-rw-r--r--compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs19
1 files changed, 9 insertions, 10 deletions
diff --git a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs
index 1269f2207d5..8dfdbf5d9dd 100644
--- a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs
+++ b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs
@@ -146,15 +146,10 @@ impl Qualif for NeedsNonConstDrop {
         qualifs.needs_non_const_drop
     }
 
-    fn in_any_value_of_ty<'tcx>(cx: &ConstCx<'_, 'tcx>, mut ty: Ty<'tcx>) -> bool {
-        // Avoid selecting for simple cases.
-        match ty::util::needs_drop_components(ty, &cx.tcx.data_layout).as_deref() {
-            Ok([]) => return false,
-            Err(ty::util::AlwaysRequiresDrop) => return true,
-            // If we've got a single component, select with that
-            // to increase the chance that we hit the selection cache.
-            Ok([t]) => ty = t,
-            Ok([..]) => {}
+    fn in_any_value_of_ty<'tcx>(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool {
+        // Avoid selecting for simple cases, such as builtin types.
+        if ty::util::trivial_const_drop(ty) {
+            return false;
         }
 
         let Some(drop_trait) = cx.tcx.lang_items().drop_trait() else {
@@ -187,11 +182,15 @@ impl Qualif for NeedsNonConstDrop {
                 impl_src,
                 ImplSource::ConstDrop(_) | ImplSource::Param(_, ty::BoundConstness::ConstIfConst)
             ) {
-                // If our const drop candidate is not ConstDrop or implied by param,
+                // If our const drop candidate is not ConstDrop or implied by the param env,
                 // then it's bad
                 return true;
             }
 
+            if impl_src.borrow_nested_obligations().is_empty() {
+                return false;
+            }
+
             // If we successfully found one, then select all of the predicates
             // implied by our const drop impl.
             let mut fcx = FulfillmentContext::new();