From 22f30e6b1c6f639040f01618a9f506b3f0dfe4bc Mon Sep 17 00:00:00 2001 From: panstromek Date: Fri, 2 Oct 2026 15:13:32 +0200 Subject: [PATCH] Outline unreachable from Clause::kind unreachable!() expands to panic("internal error: entered unreachable code"), which makes the happy path perform worse than plain argument-less call. --- compiler/rustc_middle/src/ty/predicate.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/ty/predicate.rs b/compiler/rustc_middle/src/ty/predicate.rs index b82fe2ac0e5ee..7870b20c7d304 100644 --- a/compiler/rustc_middle/src/ty/predicate.rs +++ b/compiler/rustc_middle/src/ty/predicate.rs @@ -171,9 +171,17 @@ impl<'tcx> Clause<'tcx> { } pub fn kind(self) -> ty::Binder<'tcx, ClauseKind<'tcx>> { + // Outline the unreachable! call to make the happy path faster. + // see: https://github.com/rust-lang/rust/pull/163657#issuecomment-5956974964 + #[cold] + #[inline(never)] + fn unreachable_inner() -> ! { + unreachable!() + } + self.0.internee.map_bound_no_validate_bound_vars(|kind| match kind { PredicateKind::Clause(clause) => clause, - _ => unreachable!(), + _ => unreachable_inner(), }) }