Skip to content

Commit 82f92d8

Browse files
committed
Use can_eq instead of Ty<'_> == Ty<'_>
1 parent 6022301 commit 82f92d8

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -419,17 +419,25 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
419419
let (main_trait_predicate, o) = if let ty::PredicateKind::Clause(
420420
ty::ClauseKind::Trait(root_pred)
421421
) = root_obligation.predicate.kind().skip_binder()
422+
&& !trait_predicate.self_ty().skip_binder().has_escaping_bound_vars()
423+
&& !root_pred.self_ty().has_escaping_bound_vars()
422424
// The type of the leaf predicate is (roughly) the same as the type
423425
// from the root predicate, as a proxy for "we care about the root"
424426
// FIXME: this doesn't account for trivial derefs, but works as a first
425427
// approximation.
426428
&& (
427429
// `T: Trait` && `&&T: OtherTrait`, we want `OtherTrait`
428-
trait_predicate.self_ty().skip_binder()
429-
== root_pred.self_ty().peel_refs()
430+
self.can_eq(
431+
obligation.param_env,
432+
trait_predicate.self_ty().skip_binder(),
433+
root_pred.self_ty().peel_refs(),
434+
)
430435
// `&str: Iterator` && `&str: IntoIterator`, we want `IntoIterator`
431-
|| trait_predicate.self_ty().skip_binder()
432-
== root_pred.self_ty()
436+
|| self.can_eq(
437+
obligation.param_env,
438+
trait_predicate.self_ty().skip_binder(),
439+
root_pred.self_ty(),
440+
)
433441
)
434442
// The leaf trait and the root trait are different, so as to avoid
435443
// talking about `&mut T: Trait` and instead remain talking about

0 commit comments

Comments
 (0)