Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions compiler/rustc_type_ir/src/fast_reject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl<I: Interner, const INSTANTIATE_LHS_WITH_INFER: bool, const INSTANTIATE_RHS_
// No need to decrement the depth here as this function is only
// recursively reachable via `types_may_unify_inner` which already
// increments the depth for us.
iter::zip(obligation_args.iter(), impl_args.iter()).all(|(obl, imp)| {
let may_unify = |(obl, imp): (I::GenericArg, I::GenericArg)| {
match (obl.kind(), imp.kind()) {
// We don't fast reject based on regions.
(ty::GenericArgKind::Lifetime(_), ty::GenericArgKind::Lifetime(_)) => true,
Expand All @@ -245,7 +245,14 @@ impl<I: Interner, const INSTANTIATE_LHS_WITH_INFER: bool, const INSTANTIATE_RHS_
}
_ => 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 {
Expand Down
Loading