Skip to content

Commit 5bae0b6

Browse files
committed
trait_sel: extend fast path with constness
Extends the fast path for `Sized` traits to include `const {Meta,}Sized`.
1 parent ed381e2 commit 5bae0b6

File tree

1 file changed

+17
-0
lines changed
  • compiler/rustc_trait_selection/src/traits

1 file changed

+17
-0
lines changed

compiler/rustc_trait_selection/src/traits/util.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,23 @@ pub fn sizedness_fast_path<'tcx>(
547547
}
548548
}
549549

550+
// Likewise, determining if a sizedness trait is implemented const-ly is a trivial
551+
// determination that can happen in the fast path.
552+
//
553+
// NOTE: Keep this in sync with `evaluate_host_effect_for_sizedness_goal` in the old solver,
554+
// `const_conditions_for_sizedness` in the new solver.
555+
if let ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(host_pred)) =
556+
predicate.kind().skip_binder()
557+
{
558+
let is_sizedness = tcx.is_lang_item(host_pred.def_id(), LangItem::Sized)
559+
|| tcx.is_lang_item(host_pred.def_id(), LangItem::MetaSized);
560+
561+
if is_sizedness && !host_pred.self_ty().has_non_const_sizedness() {
562+
debug!("fast path -- host effect");
563+
return true;
564+
}
565+
}
566+
550567
false
551568
}
552569

0 commit comments

Comments
 (0)