diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index 76755eb481db7..5a69d4c8df384 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -4974,8 +4974,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { .as_ref() .and_then(|typeck| typeck.node_type_opt(expr.hir_id)) && let Some(pred) = predicate.as_clause() - && let ty::ClauseKind::Trait(pred) = pred.kind().skip_binder() - && self.can_eq(param_env, pred.self_ty(), expr_ty) + && let Some(pred) = pred.as_trait_clause() + && self + .infcx + .enter_forall(pred, |pred| self.can_eq(param_env, pred.self_ty(), expr_ty)) { (expr_ty, expr) } else { diff --git a/tests/ui/impl-trait/diagnostics/incorrect-skip-binder-for-item-bound.next.stderr b/tests/ui/impl-trait/diagnostics/incorrect-skip-binder-for-item-bound.next.stderr index edb3f36cd7560..13162d5ea13a5 100644 --- a/tests/ui/impl-trait/diagnostics/incorrect-skip-binder-for-item-bound.next.stderr +++ b/tests/ui/impl-trait/diagnostics/incorrect-skip-binder-for-item-bound.next.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `for<'a> u8: From<&'a ()>` is not satisfied - --> $DIR/incorrect-skip-binder-for-item-bound.rs:19:15 + --> $DIR/incorrect-skip-binder-for-item-bound.rs:16:15 | LL | fn hello() -> impl for<'a> A<'a, Assoc: Into + 'static + Copy> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'a> From<&'a ()>` is not implemented for `u8` diff --git a/tests/ui/impl-trait/diagnostics/incorrect-skip-binder-for-item-bound.old.stderr b/tests/ui/impl-trait/diagnostics/incorrect-skip-binder-for-item-bound.old.stderr new file mode 100644 index 0000000000000..13162d5ea13a5 --- /dev/null +++ b/tests/ui/impl-trait/diagnostics/incorrect-skip-binder-for-item-bound.old.stderr @@ -0,0 +1,25 @@ +error[E0277]: the trait bound `for<'a> u8: From<&'a ()>` is not satisfied + --> $DIR/incorrect-skip-binder-for-item-bound.rs:16:15 + | +LL | fn hello() -> impl for<'a> A<'a, Assoc: Into + 'static + Copy> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `for<'a> From<&'a ()>` is not implemented for `u8` + | +help: `u8` implements trait `From` + --> $SRC_DIR/core/src/convert/num.rs:LL:COL + | + = note: `From` + ::: $SRC_DIR/core/src/convert/num.rs:LL:COL + | + = note: in this macro invocation + --> $SRC_DIR/core/src/ascii/ascii_char.rs:LL:COL + | + = note: `From` + ::: $SRC_DIR/core/src/ascii/ascii_char.rs:LL:COL + | + = note: in this macro invocation + = note: required for `&'a ()` to implement `for<'a> Into` + = note: this error originates in the macro `impl_from_bool` which comes from the expansion of the macro `into_int_impl` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/impl-trait/diagnostics/incorrect-skip-binder-for-item-bound.rs b/tests/ui/impl-trait/diagnostics/incorrect-skip-binder-for-item-bound.rs index 65a7d9442311e..fe1121af77f69 100644 --- a/tests/ui/impl-trait/diagnostics/incorrect-skip-binder-for-item-bound.rs +++ b/tests/ui/impl-trait/diagnostics/incorrect-skip-binder-for-item-bound.rs @@ -1,9 +1,6 @@ //@ revisions: old next //@ ignore-compare-mode-next-solver (explicit revisions) //@[next] compile-flags: -Znext-solver -//@[old] failure-status: 101 -//@[old] dont-check-compiler-stderr -//@[old] known-bug: #139381 //@ needs-rustc-debug-assertions // An ICE caused by an incorrect `skip_binder()` in diagnostics code, see #139381. @@ -17,7 +14,7 @@ impl<'a> A<'a> for () { } fn hello() -> impl for<'a> A<'a, Assoc: Into + 'static + Copy> { - //[next]~^ ERROR: the trait bound `for<'a> u8: From<&'a ()>` is not satisfied + //~^ ERROR: the trait bound `for<'a> u8: From<&'a ()>` is not satisfied () }