From aade63aeee43e0a7cc4772d87e0eae54ac5e8496 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Wed, 15 Sep 2021 13:26:12 +0000 Subject: [PATCH] Fast reject for NeedsNonConstDrop --- .../src/transform/check_consts/qualifs.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 dc3927ed85b3d..cb9b4bcb77a85 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 {