diff --git a/compiler/rustc_type_ir/src/fast_reject.rs b/compiler/rustc_type_ir/src/fast_reject.rs index a514cf9d9052f..c0329b4f6226d 100644 --- a/compiler/rustc_type_ir/src/fast_reject.rs +++ b/compiler/rustc_type_ir/src/fast_reject.rs @@ -233,7 +233,7 @@ impl true, @@ -245,7 +245,14 @@ impl panic!("kind mismatch: {obl:?} {imp:?}"), } - }) + }; + + // Specialize the common `(1, 1)` case to avoid iterator machinery. + if let ([obl], [imp]) = (obligation_args.as_slice(), impl_args.as_slice()) { + return may_unify((*obl, *imp)); + } + + iter::zip(obligation_args.iter(), impl_args.iter()).all(may_unify) } fn types_may_unify_inner(self, lhs: I::Ty, rhs: I::Ty, depth: usize) -> bool {