Skip to content

Commit

Permalink
Use can_eq instead of Ty<'_> == Ty<'_>
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Mar 3, 2024
1 parent 89a3c19 commit 40f9dcc
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -426,17 +426,25 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
let (main_trait_predicate, o) = if let ty::PredicateKind::Clause(
ty::ClauseKind::Trait(root_pred)
) = root_obligation.predicate.kind().skip_binder()
&& !trait_predicate.self_ty().skip_binder().has_escaping_bound_vars()
&& !root_pred.self_ty().has_escaping_bound_vars()
// The type of the leaf predicate is (roughly) the same as the type
// from the root predicate, as a proxy for "we care about the root"
// FIXME: this doesn't account for trivial derefs, but works as a first
// approximation.
&& (
// `T: Trait` && `&&T: OtherTrait`, we want `OtherTrait`
trait_predicate.self_ty().skip_binder()
== root_pred.self_ty().peel_refs()
self.can_eq(
obligation.param_env,
trait_predicate.self_ty().skip_binder(),
root_pred.self_ty().peel_refs(),
)
// `&str: Iterator` && `&str: IntoIterator`, we want `IntoIterator`
|| trait_predicate.self_ty().skip_binder()
== root_pred.self_ty()
|| self.can_eq(
obligation.param_env,
trait_predicate.self_ty().skip_binder(),
root_pred.self_ty(),
)
)
// The leaf trait and the root trait are different, so as to avoid
// talking about `&mut T: Trait` and instead remain talking about
Expand Down

0 comments on commit 40f9dcc

Please sign in to comment.