Skip to content

Commit aade63a

Browse files
committed
Fast reject for NeedsNonConstDrop
1 parent cdeba02 commit aade63a

File tree

1 file changed

+11
-1
lines changed
  • compiler/rustc_const_eval/src/transform/check_consts

1 file changed

+11
-1
lines changed

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,17 @@ impl Qualif for NeedsNonConstDrop {
111111
qualifs.needs_drop
112112
}
113113

114-
fn in_any_value_of_ty(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool {
114+
fn in_any_value_of_ty(cx: &ConstCx<'_, 'tcx>, mut ty: Ty<'tcx>) -> bool {
115+
// Avoid selecting for simple cases.
116+
match ty::util::needs_drop_components(ty, &cx.tcx.data_layout).as_deref() {
117+
Ok([]) => return false,
118+
Err(ty::util::AlwaysRequiresDrop) => return true,
119+
// If we've got a single component, select with that
120+
// to increase the chance that we hit the selection cache.
121+
Ok([t]) => ty = t,
122+
Ok([..]) => {}
123+
}
124+
115125
let drop_trait = if let Some(did) = cx.tcx.lang_items().drop_trait() {
116126
did
117127
} else {

0 commit comments

Comments
 (0)