about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/transform
diff options
context:
space:
mode:
authorDeadbeef <ent3rm4n@gmail.com>2021-09-15 13:26:12 +0000
committerDeadbeef <ent3rm4n@gmail.com>2021-09-15 13:26:12 +0000
commitaade63aeee43e0a7cc4772d87e0eae54ac5e8496 (patch)
treeff949946a00abd7114676048f03463c351516e7e /compiler/rustc_const_eval/src/transform
parentcdeba02ff71416e014f7130f75166890688be986 (diff)
downloadrust-aade63aeee43e0a7cc4772d87e0eae54ac5e8496.tar.gz
rust-aade63aeee43e0a7cc4772d87e0eae54ac5e8496.zip
Fast reject for NeedsNonConstDrop
Diffstat (limited to 'compiler/rustc_const_eval/src/transform')
-rw-r--r--compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs12
1 files changed, 11 insertions, 1 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 dc3927ed85b..cb9b4bcb77a 100644
--- a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs
+++ b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs
@@ -111,7 +111,17 @@ impl Qualif for NeedsNonConstDrop {
         qualifs.needs_drop
     }
 
-    fn in_any_value_of_ty(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool {
+    fn in_any_value_of_ty(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([..]) => {}
+        }
+
         let drop_trait = if let Some(did) = cx.tcx.lang_items().drop_trait() {
             did
         } else {