about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-09-26 16:10:47 +0000
committerbors <bors@rust-lang.org>2025-09-26 16:10:47 +0000
commit54a8a1db604e4caff93e26e167ad4a6fde9f0681 (patch)
tree4ad8eb2c873b1431c53293cfd0d6c25fc6b853f5
parenta8858111044a9391ac7558f969d3bf62ef43222d (diff)
parentc2e39c2f20c568b96fe89c751e65bbbe9116231c (diff)
downloadrust-54a8a1db604e4caff93e26e167ad4a6fde9f0681.tar.gz
rust-54a8a1db604e4caff93e26e167ad4a6fde9f0681.zip
Auto merge of #146885 - lcnr:method-selection-opaques, r=BoxyUwU
support opaque types in method selection

See my notes in https://hackmd.io/4ILASx3mQ3u_gW9r1JyqCw.

This PR builds on https://github.com/rust-lang/rust/pull/145993 and allows not-yet defined opaque types as self types in the `method_autoderef_chain`.

E.g. for `Box<impl Deref<impl Foo>>` this results in the autoderef chain `Box<impl Deref> -> ?deref_hidden_ty -> ?foo_hidden_ty`. Method selection stays ambiguous if the final autoderef step is still an infer var unless that var is an opaque.

TODO: treating opaques as rigid jank.

r? `@BoxyUwU`
-rw-r--r--compiler/rustc_hir_typeck/src/expr.rs3
-rw-r--r--compiler/rustc_hir_typeck/src/method/confirm.rs4
-rw-r--r--compiler/rustc_hir_typeck/src/method/probe.rs267
-rw-r--r--compiler/rustc_infer/src/infer/canonical/query_response.rs20
-rw-r--r--compiler/rustc_middle/src/arena.rs1
-rw-r--r--compiler/rustc_middle/src/query/mod.rs6
-rw-r--r--compiler/rustc_middle/src/traits/query.rs13
-rw-r--r--compiler/rustc_middle/src/traits/solve.rs45
-rw-r--r--compiler/rustc_middle/src/ty/context.rs17
-rw-r--r--compiler/rustc_middle/src/ty/structural_impls.rs1
-rw-r--r--compiler/rustc_next_trait_solver/src/canonical/mod.rs8
-rw-r--r--compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs10
-rw-r--r--compiler/rustc_next_trait_solver/src/solve/mod.rs1
-rw-r--r--compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs11
-rw-r--r--compiler/rustc_type_ir/src/interner.rs8
-rw-r--r--compiler/rustc_type_ir/src/solve/mod.rs13
-rw-r--r--tests/ui/closures/deduce-signature/obligation-with-leaking-placeholders.next.stderr2
-rw-r--r--tests/ui/impl-trait/call_method_ambiguous.next.stderr17
-rw-r--r--tests/ui/impl-trait/call_method_ambiguous.rs3
-rw-r--r--tests/ui/impl-trait/call_method_on_inherent_impl.next.stderr17
-rw-r--r--tests/ui/impl-trait/call_method_on_inherent_impl.rs3
-rw-r--r--tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.current.stderr2
-rw-r--r--tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.next.stderr18
-rw-r--r--tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.rs3
-rw-r--r--tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.current.stderr (renamed from tests/ui/impl-trait/call_method_on_inherent_impl_ref.current.stderr)4
-rw-r--r--tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.next.stderr19
-rw-r--r--tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.rs24
-rw-r--r--tests/ui/impl-trait/call_method_on_inherent_impl_ref-ok.rs (renamed from tests/ui/impl-trait/call_method_on_inherent_impl_ref.rs)12
-rw-r--r--tests/ui/impl-trait/call_method_on_inherent_impl_ref.next.stderr31
-rw-r--r--tests/ui/impl-trait/hidden-type-is-opaque-2.default.stderr4
-rw-r--r--tests/ui/impl-trait/hidden-type-is-opaque-2.next.stderr4
-rw-r--r--tests/ui/impl-trait/method-resolution4.next.stderr9
-rw-r--r--tests/ui/impl-trait/method/broken-deref-chain.current.stderr19
-rw-r--r--tests/ui/impl-trait/method/broken-deref-chain.rs47
-rw-r--r--tests/ui/impl-trait/method/method-resolution.rs (renamed from tests/ui/impl-trait/method-resolution.rs)0
-rw-r--r--tests/ui/impl-trait/method/method-resolution2.next.stderr (renamed from tests/ui/impl-trait/method-resolution2.next.stderr)0
-rw-r--r--tests/ui/impl-trait/method/method-resolution2.rs (renamed from tests/ui/impl-trait/method-resolution2.rs)0
-rw-r--r--tests/ui/impl-trait/method/method-resolution3.current.stderr (renamed from tests/ui/impl-trait/method-resolution3.current.stderr)0
-rw-r--r--tests/ui/impl-trait/method/method-resolution3.next.stderr (renamed from tests/ui/impl-trait/method-resolution3.next.stderr)0
-rw-r--r--tests/ui/impl-trait/method/method-resolution3.rs (renamed from tests/ui/impl-trait/method-resolution3.rs)0
-rw-r--r--tests/ui/impl-trait/method/method-resolution4.rs (renamed from tests/ui/impl-trait/method-resolution4.rs)3
-rw-r--r--tests/ui/impl-trait/method/method-resolution5-deref-no-constrain.current.stderr19
-rw-r--r--tests/ui/impl-trait/method/method-resolution5-deref-no-constrain.rs23
-rw-r--r--tests/ui/impl-trait/method/method-resolution5-deref.rs30
-rw-r--r--tests/ui/impl-trait/method/would-constrain-opaque.current.stderr29
-rw-r--r--tests/ui/impl-trait/method/would-constrain-opaque.next.stderr27
-rw-r--r--tests/ui/impl-trait/method/would-constrain-opaque.rs39
-rw-r--r--tests/ui/impl-trait/recursive-bound-eval.next.stderr9
-rw-r--r--tests/ui/impl-trait/recursive-bound-eval.rs6
-rw-r--r--tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr17
-rw-r--r--tests/ui/impl-trait/recursive-coroutine-boxed.rs3
-rw-r--r--tests/ui/inference/need_type_info/incompat-call-after-qualified-path-0.stderr2
-rw-r--r--tests/ui/inference/need_type_info/incompat-call-after-qualified-path-1.stderr2
-rw-r--r--tests/ui/issues/issue-2151.stderr2
-rw-r--r--tests/ui/lazy-type-alias-impl-trait/branches3.stderr8
-rw-r--r--tests/ui/proc-macro/quote/not-repeatable.rs4
-rw-r--r--tests/ui/proc-macro/quote/not-repeatable.stderr11
-rw-r--r--tests/ui/repeat-expr/copy-inference-side-effects-are-lazy.stderr4
-rw-r--r--tests/ui/span/issue-42234-unknown-receiver-type.stderr4
-rw-r--r--tests/ui/type-alias-impl-trait/closures_in_branches.stderr4
-rw-r--r--tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.next.stderr10
-rw-r--r--tests/ui/type-inference/regression-issue-81317.stderr2
-rw-r--r--tests/ui/typeck/issue-13853.rs2
-rw-r--r--tests/ui/typeck/issue-13853.stderr12
64 files changed, 647 insertions, 291 deletions
diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs
index 7adbee7ff28..d1ce0afddf9 100644
--- a/compiler/rustc_hir_typeck/src/expr.rs
+++ b/compiler/rustc_hir_typeck/src/expr.rs
@@ -1633,8 +1633,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         expected: Expectation<'tcx>,
     ) -> Ty<'tcx> {
         let rcvr_t = self.check_expr(rcvr);
-        // no need to check for bot/err -- callee does that
-        let rcvr_t = self.structurally_resolve_type(rcvr.span, rcvr_t);
+        let rcvr_t = self.try_structurally_resolve_type(rcvr.span, rcvr_t);
 
         match self.lookup_method(rcvr_t, segment, segment.ident.span, expr, rcvr, args) {
             Ok(method) => {
diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs
index a23910a2006..b23e7ae8e77 100644
--- a/compiler/rustc_hir_typeck/src/method/confirm.rs
+++ b/compiler/rustc_hir_typeck/src/method/confirm.rs
@@ -172,7 +172,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
         // Commit the autoderefs by calling `autoderef` again, but this
         // time writing the results into the various typeck results.
         let mut autoderef = self.autoderef(self.call_expr.span, unadjusted_self_ty);
-        let Some((ty, n)) = autoderef.nth(pick.autoderefs) else {
+        let Some((mut target, n)) = autoderef.nth(pick.autoderefs) else {
             return Ty::new_error_with_message(
                 self.tcx,
                 DUMMY_SP,
@@ -182,8 +182,6 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
         assert_eq!(n, pick.autoderefs);
 
         let mut adjustments = self.adjust_steps(&autoderef);
-        let mut target = self.structurally_resolve_type(autoderef.span(), ty);
-
         match pick.autoref_or_ptr_adjustment {
             Some(probe::AutorefOrPtrAdjustment::Autoref { mutbl, unsize }) => {
                 let region = self.next_region_var(RegionVariableOrigin::Autoref(self.span));
diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs
index 4185f7f6996..12f80a197b1 100644
--- a/compiler/rustc_hir_typeck/src/method/probe.rs
+++ b/compiler/rustc_hir_typeck/src/method/probe.rs
@@ -13,7 +13,7 @@ use rustc_hir::def::DefKind;
 use rustc_hir_analysis::autoderef::{self, Autoderef};
 use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
 use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk, TyCtxtInferExt};
-use rustc_infer::traits::ObligationCauseCode;
+use rustc_infer::traits::{ObligationCauseCode, PredicateObligation, query};
 use rustc_middle::middle::stability;
 use rustc_middle::ty::elaborate::supertrait_def_ids;
 use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams, simplify_type};
@@ -30,7 +30,8 @@ use rustc_span::edit_distance::{
 use rustc_span::{DUMMY_SP, Ident, Span, Symbol, sym};
 use rustc_trait_selection::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
 use rustc_trait_selection::infer::InferCtxtExt as _;
-use rustc_trait_selection::traits::query::CanonicalTyGoal;
+use rustc_trait_selection::solve::Goal;
+use rustc_trait_selection::traits::query::CanonicalMethodAutoderefStepsGoal;
 use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
 use rustc_trait_selection::traits::query::method_autoderef::{
     CandidateStep, MethodAutoderefBadTy, MethodAutoderefStepsResult,
@@ -389,10 +390,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         OP: FnOnce(ProbeContext<'_, 'tcx>) -> Result<R, MethodError<'tcx>>,
     {
         let mut orig_values = OriginalQueryValues::default();
-        let query_input = self.canonicalize_query(
-            ParamEnvAnd { param_env: self.param_env, value: self_ty },
-            &mut orig_values,
-        );
+        let predefined_opaques_in_body = if self.next_trait_solver() {
+            self.tcx.mk_predefined_opaques_in_body_from_iter(
+                self.inner.borrow_mut().opaque_types().iter_opaque_types().map(|(k, v)| (k, v.ty)),
+            )
+        } else {
+            ty::List::empty()
+        };
+        let value = query::MethodAutoderefSteps { predefined_opaques_in_body, self_ty };
+        let query_input = self
+            .canonicalize_query(ParamEnvAnd { param_env: self.param_env, value }, &mut orig_values);
 
         let steps = match mode {
             Mode::MethodCall => self.tcx.method_autoderef_steps(query_input),
@@ -403,13 +410,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 // special handling for this "trivial case" is a good idea.
 
                 let infcx = &self.infcx;
-                let (ParamEnvAnd { param_env: _, value: self_ty }, var_values) =
+                let (ParamEnvAnd { param_env: _, value }, var_values) =
                     infcx.instantiate_canonical(span, &query_input.canonical);
+                let query::MethodAutoderefSteps { predefined_opaques_in_body: _, self_ty } = value;
                 debug!(?self_ty, ?query_input, "probe_op: Mode::Path");
                 MethodAutoderefStepsResult {
                     steps: infcx.tcx.arena.alloc_from_iter([CandidateStep {
                         self_ty: self
                             .make_query_response_ignoring_pending_obligations(var_values, self_ty),
+                        self_ty_is_opaque: false,
                         autoderefs: 0,
                         from_unsafe_deref: false,
                         unsize: false,
@@ -479,6 +488,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                     ty::Infer(ty::TyVar(_)) => {
                         let raw_ptr_call = bad_ty.reached_raw_pointer
                             && !self.tcx.features().arbitrary_self_types();
+                        // FIXME: Ideally we'd use the span of the self-expr here,
+                        // not of the method path.
                         let mut err = self.err_ctxt().emit_inference_failure_err(
                             self.body_id,
                             span,
@@ -553,12 +564,44 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
 
 pub(crate) fn method_autoderef_steps<'tcx>(
     tcx: TyCtxt<'tcx>,
-    goal: CanonicalTyGoal<'tcx>,
+    goal: CanonicalMethodAutoderefStepsGoal<'tcx>,
 ) -> MethodAutoderefStepsResult<'tcx> {
     debug!("method_autoderef_steps({:?})", goal);
 
     let (ref infcx, goal, inference_vars) = tcx.infer_ctxt().build_with_canonical(DUMMY_SP, &goal);
-    let ParamEnvAnd { param_env, value: self_ty } = goal;
+    let ParamEnvAnd {
+        param_env,
+        value: query::MethodAutoderefSteps { predefined_opaques_in_body, self_ty },
+    } = goal;
+    for (key, ty) in predefined_opaques_in_body {
+        let prev =
+            infcx.register_hidden_type_in_storage(key, ty::OpaqueHiddenType { span: DUMMY_SP, ty });
+        // It may be possible that two entries in the opaque type storage end up
+        // with the same key after resolving contained inference variables.
+        //
+        // We could put them in the duplicate list but don't have to. The opaques we
+        // encounter here are already tracked in the caller, so there's no need to
+        // also store them here. We'd take them out when computing the query response
+        // and then discard them, as they're already present in the input.
+        //
+        // Ideally we'd drop duplicate opaque type definitions when computing
+        // the canonical input. This is more annoying to implement and may cause a
+        // perf regression, so we do it inside of the query for now.
+        if let Some(prev) = prev {
+            debug!(?key, ?ty, ?prev, "ignore duplicate in `opaque_types_storage`");
+        }
+    }
+
+    // We accept not-yet-defined opaque types in the autoderef
+    // chain to support recursive calls. We do error if the final
+    // infer var is not an opaque.
+    let self_ty_is_opaque = |ty: Ty<'_>| {
+        if let &ty::Infer(ty::TyVar(vid)) = ty.kind() {
+            infcx.has_opaques_with_sub_unified_hidden_type(vid)
+        } else {
+            false
+        }
+    };
 
     // If arbitrary self types is not enabled, we follow the chain of
     // `Deref<Target=T>`. If arbitrary self types is enabled, we instead
@@ -593,6 +636,7 @@ pub(crate) fn method_autoderef_steps<'tcx>(
                 let step = CandidateStep {
                     self_ty: infcx
                         .make_query_response_ignoring_pending_obligations(inference_vars, ty),
+                    self_ty_is_opaque: self_ty_is_opaque(ty),
                     autoderefs: d,
                     from_unsafe_deref: reached_raw_pointer,
                     unsize: false,
@@ -613,6 +657,7 @@ pub(crate) fn method_autoderef_steps<'tcx>(
                 let step = CandidateStep {
                     self_ty: infcx
                         .make_query_response_ignoring_pending_obligations(inference_vars, ty),
+                    self_ty_is_opaque: self_ty_is_opaque(ty),
                     autoderefs: d,
                     from_unsafe_deref: reached_raw_pointer,
                     unsize: false,
@@ -629,7 +674,11 @@ pub(crate) fn method_autoderef_steps<'tcx>(
     };
     let final_ty = autoderef_via_deref.final_ty();
     let opt_bad_ty = match final_ty.kind() {
-        ty::Infer(ty::TyVar(_)) | ty::Error(_) => Some(MethodAutoderefBadTy {
+        ty::Infer(ty::TyVar(_)) if !self_ty_is_opaque(final_ty) => Some(MethodAutoderefBadTy {
+            reached_raw_pointer,
+            ty: infcx.make_query_response_ignoring_pending_obligations(inference_vars, final_ty),
+        }),
+        ty::Error(_) => Some(MethodAutoderefBadTy {
             reached_raw_pointer,
             ty: infcx.make_query_response_ignoring_pending_obligations(inference_vars, final_ty),
         }),
@@ -640,6 +689,7 @@ pub(crate) fn method_autoderef_steps<'tcx>(
                     inference_vars,
                     Ty::new_slice(infcx.tcx, *elem_ty),
                 ),
+                self_ty_is_opaque: false,
                 autoderefs,
                 // this could be from an unsafe deref if we had
                 // a *mut/const [T; N]
@@ -655,7 +705,8 @@ pub(crate) fn method_autoderef_steps<'tcx>(
     };
 
     debug!("method_autoderef_steps: steps={:?} opt_bad_ty={:?}", steps, opt_bad_ty);
-
+    // Need to empty the opaque types storage before it gets dropped.
+    let _ = infcx.take_opaque_types();
     MethodAutoderefStepsResult {
         steps: tcx.arena.alloc_from_iter(steps),
         opt_bad_ty: opt_bad_ty.map(|ty| &*tcx.arena.alloc(ty)),
@@ -1203,7 +1254,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
                 !step.self_ty.value.references_error() && !step.from_unsafe_deref
             })
             .find_map(|step| {
-                let InferOk { value: self_ty, obligations: _ } = self
+                let InferOk { value: self_ty, obligations: instantiate_self_ty_obligations } = self
                     .fcx
                     .probe_instantiate_query_response(
                         self.span,
@@ -1214,7 +1265,12 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
                         span_bug!(self.span, "{:?} was applicable but now isn't?", step.self_ty)
                     });
 
-                let by_value_pick = self.pick_by_value_method(step, self_ty, pick_diag_hints);
+                let by_value_pick = self.pick_by_value_method(
+                    step,
+                    self_ty,
+                    &instantiate_self_ty_obligations,
+                    pick_diag_hints,
+                );
 
                 // Check for shadowing of a by-reference method by a by-value method (see comments on check_for_shadowing)
                 if let Some(by_value_pick) = by_value_pick {
@@ -1225,6 +1281,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
                                     by_value_pick,
                                     step,
                                     self_ty,
+                                    &instantiate_self_ty_obligations,
                                     mutbl,
                                     track_unstable_candidates,
                                 ) {
@@ -1239,6 +1296,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
                 let autoref_pick = self.pick_autorefd_method(
                     step,
                     self_ty,
+                    &instantiate_self_ty_obligations,
                     hir::Mutability::Not,
                     pick_diag_hints,
                     None,
@@ -1252,6 +1310,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
                                 autoref_pick,
                                 step,
                                 self_ty,
+                                &instantiate_self_ty_obligations,
                                 hir::Mutability::Mut,
                                 track_unstable_candidates,
                             ) {
@@ -1288,12 +1347,27 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
                 self.pick_autorefd_method(
                     step,
                     self_ty,
+                    &instantiate_self_ty_obligations,
                     hir::Mutability::Mut,
                     pick_diag_hints,
                     None,
                 )
-                .or_else(|| self.pick_const_ptr_method(step, self_ty, pick_diag_hints))
-                .or_else(|| self.pick_reborrow_pin_method(step, self_ty, pick_diag_hints))
+                .or_else(|| {
+                    self.pick_const_ptr_method(
+                        step,
+                        self_ty,
+                        &instantiate_self_ty_obligations,
+                        pick_diag_hints,
+                    )
+                })
+                .or_else(|| {
+                    self.pick_reborrow_pin_method(
+                        step,
+                        self_ty,
+                        &instantiate_self_ty_obligations,
+                        pick_diag_hints,
+                    )
+                })
             })
     }
 
@@ -1317,6 +1391,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
         possible_shadower: &Pick<'tcx>,
         step: &CandidateStep<'tcx>,
         self_ty: Ty<'tcx>,
+        instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
         mutbl: hir::Mutability,
         track_unstable_candidates: bool,
     ) -> Result<(), MethodError<'tcx>> {
@@ -1381,6 +1456,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
         let potentially_shadowed_pick = self.pick_autorefd_method(
             step,
             self_ty,
+            instantiate_self_ty_obligations,
             mutbl,
             &mut pick_diag_hints,
             Some(&pick_constraints),
@@ -1407,13 +1483,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
         &self,
         step: &CandidateStep<'tcx>,
         self_ty: Ty<'tcx>,
+        instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
         pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
     ) -> Option<PickResult<'tcx>> {
         if step.unsize {
             return None;
         }
 
-        self.pick_method(self_ty, pick_diag_hints, None).map(|r| {
+        self.pick_method(self_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(|r| {
             r.map(|mut pick| {
                 pick.autoderefs = step.autoderefs;
 
@@ -1450,6 +1527,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
         &self,
         step: &CandidateStep<'tcx>,
         self_ty: Ty<'tcx>,
+        instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
         mutbl: hir::Mutability,
         pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
         pick_constraints: Option<&PickConstraintsForShadowed>,
@@ -1466,7 +1544,13 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
         let region = tcx.lifetimes.re_erased;
 
         let autoref_ty = Ty::new_ref(tcx, region, self_ty, mutbl);
-        self.pick_method(autoref_ty, pick_diag_hints, pick_constraints).map(|r| {
+        self.pick_method(
+            autoref_ty,
+            instantiate_self_ty_obligations,
+            pick_diag_hints,
+            pick_constraints,
+        )
+        .map(|r| {
             r.map(|mut pick| {
                 pick.autoderefs = step.autoderefs;
                 pick.autoref_or_ptr_adjustment =
@@ -1482,6 +1566,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
         &self,
         step: &CandidateStep<'tcx>,
         self_ty: Ty<'tcx>,
+        instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
         pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
     ) -> Option<PickResult<'tcx>> {
         if !self.tcx.features().pin_ergonomics() {
@@ -1503,14 +1588,16 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
 
         let region = self.tcx.lifetimes.re_erased;
         let autopin_ty = Ty::new_pinned_ref(self.tcx, region, inner_ty, hir::Mutability::Not);
-        self.pick_method(autopin_ty, pick_diag_hints, None).map(|r| {
-            r.map(|mut pick| {
-                pick.autoderefs = step.autoderefs;
-                pick.autoref_or_ptr_adjustment =
-                    Some(AutorefOrPtrAdjustment::ReborrowPin(hir::Mutability::Not));
-                pick
-            })
-        })
+        self.pick_method(autopin_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(
+            |r| {
+                r.map(|mut pick| {
+                    pick.autoderefs = step.autoderefs;
+                    pick.autoref_or_ptr_adjustment =
+                        Some(AutorefOrPtrAdjustment::ReborrowPin(hir::Mutability::Not));
+                    pick
+                })
+            },
+        )
     }
 
     /// If `self_ty` is `*mut T` then this picks `*const T` methods. The reason why we have a
@@ -1520,6 +1607,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
         &self,
         step: &CandidateStep<'tcx>,
         self_ty: Ty<'tcx>,
+        instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
         pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
     ) -> Option<PickResult<'tcx>> {
         // Don't convert an unsized reference to ptr
@@ -1532,18 +1620,21 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
         };
 
         let const_ptr_ty = Ty::new_imm_ptr(self.tcx, ty);
-        self.pick_method(const_ptr_ty, pick_diag_hints, None).map(|r| {
-            r.map(|mut pick| {
-                pick.autoderefs = step.autoderefs;
-                pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::ToConstPtr);
-                pick
-            })
-        })
+        self.pick_method(const_ptr_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(
+            |r| {
+                r.map(|mut pick| {
+                    pick.autoderefs = step.autoderefs;
+                    pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::ToConstPtr);
+                    pick
+                })
+            },
+        )
     }
 
     fn pick_method(
         &self,
         self_ty: Ty<'tcx>,
+        instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
         pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
         pick_constraints: Option<&PickConstraintsForShadowed>,
     ) -> Option<PickResult<'tcx>> {
@@ -1553,8 +1644,13 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
             [("inherent", &self.inherent_candidates), ("extension", &self.extension_candidates)]
         {
             debug!("searching {} candidates", kind);
-            let res =
-                self.consider_candidates(self_ty, candidates, pick_diag_hints, pick_constraints);
+            let res = self.consider_candidates(
+                self_ty,
+                instantiate_self_ty_obligations,
+                candidates,
+                pick_diag_hints,
+                pick_constraints,
+            );
             if let Some(pick) = res {
                 return Some(pick);
             }
@@ -1563,6 +1659,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
         if self.private_candidate.get().is_none() {
             if let Some(Ok(pick)) = self.consider_candidates(
                 self_ty,
+                instantiate_self_ty_obligations,
                 &self.private_candidates,
                 &mut PickDiagHints {
                     unstable_candidates: None,
@@ -1579,6 +1676,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
     fn consider_candidates(
         &self,
         self_ty: Ty<'tcx>,
+        instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
         candidates: &[Candidate<'tcx>],
         pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
         pick_constraints: Option<&PickConstraintsForShadowed>,
@@ -1595,6 +1693,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
                     probe,
                     self.consider_probe(
                         self_ty,
+                        instantiate_self_ty_obligations,
                         probe,
                         &mut pick_diag_hints.unsatisfied_predicates,
                     ),
@@ -1779,10 +1878,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
         }
     }
 
-    #[instrument(level = "trace", skip(self, possibly_unsatisfied_predicates), ret)]
+    #[instrument(level = "debug", skip(self, possibly_unsatisfied_predicates), ret)]
     fn consider_probe(
         &self,
         self_ty: Ty<'tcx>,
+        instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
         probe: &Candidate<'tcx>,
         possibly_unsatisfied_predicates: &mut Vec<(
             ty::Predicate<'tcx>,
@@ -1790,8 +1890,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
             Option<ObligationCause<'tcx>>,
         )>,
     ) -> ProbeResult {
-        debug!("consider_probe: self_ty={:?} probe={:?}", self_ty, probe);
-
         self.probe(|snapshot| {
             let outer_universe = self.universe();
 
@@ -1799,6 +1897,21 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
             let cause = &self.misc(self.span);
             let ocx = ObligationCtxt::new_with_diagnostics(self);
 
+            // Subtle: we're not *really* instantiating the current self type while
+            // probing, but instead fully recompute the autoderef steps once we've got
+            // a final `Pick`. We can't nicely handle these obligations outside of a probe.
+            //
+            // We simply handle them for each candidate here for now. That's kinda scuffed
+            // and ideally we just put them into the `FnCtxt` right away. We need to consider
+            // them to deal with defining uses in `method_autoderef_steps`.
+            if self.next_trait_solver() {
+                ocx.register_obligations(instantiate_self_ty_obligations.iter().cloned());
+                let errors = ocx.select_where_possible();
+                if !errors.is_empty() {
+                    unreachable!("unexpected autoderef error {errors:?}");
+                }
+            }
+
             let mut trait_predicate = None;
             let (mut xform_self_ty, mut xform_ret_ty);
 
@@ -2041,6 +2154,12 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
                 }
             }
 
+            if self.infcx.next_trait_solver() {
+                if self.should_reject_candidate_due_to_opaque_treated_as_rigid(trait_predicate) {
+                    result = ProbeResult::NoMatch;
+                }
+            }
+
             // Previously, method probe used `evaluate_predicate` to determine if a predicate
             // was impossible to satisfy. This did a leak check, so we must also do a leak
             // check here to prevent backwards-incompatible ambiguity being introduced. See
@@ -2054,6 +2173,80 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
         })
     }
 
+    /// Trait candidates for not-yet-defined opaque types are a somewhat hacky.
+    ///
+    /// We want to only accept trait methods if they were hold even if the
+    /// opaque types were rigid. To handle this, we both check that for trait
+    /// candidates the goal were to hold even when treating opaques as rigid,
+    /// see [OpaqueTypesJank](rustc_trait_selection::solve::OpaqueTypesJank).
+    ///
+    /// We also check that all opaque types encountered as self types in the
+    /// autoderef chain don't get constrained when applying the candidate.
+    /// Importantly, this also handles calling methods taking `&self` on
+    /// `impl Trait` to reject the "by-self" candidate.
+    ///
+    /// This needs to happen at the end of `consider_probe` as we need to take
+    /// all the constraints from that into account.
+    #[instrument(level = "debug", skip(self), ret)]
+    fn should_reject_candidate_due_to_opaque_treated_as_rigid(
+        &self,
+        trait_predicate: Option<ty::Predicate<'tcx>>,
+    ) -> bool {
+        // This function is what hacky and doesn't perfectly do what we want it to.
+        // It's not soundness critical and we should be able to freely improve this
+        // in the future.
+        //
+        // Some concrete edge cases include the fact that `goal_may_hold_opaque_types_jank`
+        // also fails if there are any constraints opaques which are never used as a self
+        // type. We also allow where-bounds which are currently ambiguous but end up
+        // constraining an opaque later on.
+
+        // Check whether the trait candidate would not be applicable if the
+        // opaque type were rigid.
+        if let Some(predicate) = trait_predicate {
+            let goal = Goal { param_env: self.param_env, predicate };
+            if !self.infcx.goal_may_hold_opaque_types_jank(goal) {
+                return true;
+            }
+        }
+
+        // Check whether any opaque types in the autoderef chain have been
+        // constrained.
+        for step in self.steps {
+            if step.self_ty_is_opaque {
+                debug!(?step.autoderefs, ?step.self_ty, "self_type_is_opaque");
+                let constrained_opaque = self.probe(|_| {
+                    // If we fail to instantiate the self type of this
+                    // step, this part of the deref-chain is no longer
+                    // reachable. In this case we don't care about opaque
+                    // types there.
+                    let Ok(ok) = self.fcx.probe_instantiate_query_response(
+                        self.span,
+                        self.orig_steps_var_values,
+                        &step.self_ty,
+                    ) else {
+                        debug!("failed to instantiate self_ty");
+                        return false;
+                    };
+                    let ocx = ObligationCtxt::new(self);
+                    let self_ty = ocx.register_infer_ok_obligations(ok);
+                    if !ocx.select_where_possible().is_empty() {
+                        debug!("failed to prove instantiate self_ty obligations");
+                        return false;
+                    }
+
+                    !self.resolve_vars_if_possible(self_ty).is_ty_var()
+                });
+                if constrained_opaque {
+                    debug!("opaque type has been constrained");
+                    return true;
+                }
+            }
+        }
+
+        false
+    }
+
     /// Sometimes we get in a situation where we have multiple probes that are all impls of the
     /// same trait, but we don't know which impl to use. In this case, since in all cases the
     /// external interface of the method can be determined from the trait, it's ok not to decide.
diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs
index 5d1b4be9e57..b3959113d5d 100644
--- a/compiler/rustc_infer/src/infer/canonical/query_response.rs
+++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs
@@ -85,11 +85,29 @@ impl<'tcx> InferCtxt<'tcx> {
     where
         T: Debug + TypeFoldable<TyCtxt<'tcx>>,
     {
+        // While we ignore region constraints and pending obligations,
+        // we do return constrained opaque types to avoid unconstrained
+        // inference variables in the response. This is important as we want
+        // to check that opaques in deref steps stay unconstrained.
+        //
+        // This doesn't handle the more general case for non-opaques as
+        // ambiguous `Projection` obligations have same the issue.
+        let opaque_types = if self.next_trait_solver() {
+            self.inner
+                .borrow_mut()
+                .opaque_type_storage
+                .iter_opaque_types()
+                .map(|(k, v)| (k, v.ty))
+                .collect()
+        } else {
+            vec![]
+        };
+
         self.canonicalize_response(QueryResponse {
             var_values: inference_vars,
             region_constraints: QueryRegionConstraints::default(),
             certainty: Certainty::Proven, // Ambiguities are OK!
-            opaque_types: vec![],
+            opaque_types,
             value: answer,
         })
     }
diff --git a/compiler/rustc_middle/src/arena.rs b/compiler/rustc_middle/src/arena.rs
index 52fbe19c9f2..fa6a2db38ef 100644
--- a/compiler/rustc_middle/src/arena.rs
+++ b/compiler/rustc_middle/src/arena.rs
@@ -109,7 +109,6 @@ macro_rules! arena_types {
                     rustc_middle::ty::EarlyBinder<'tcx, rustc_middle::ty::Ty<'tcx>>
                 >,
             [] external_constraints: rustc_middle::traits::solve::ExternalConstraintsData<rustc_middle::ty::TyCtxt<'tcx>>,
-            [] predefined_opaques_in_body: rustc_middle::traits::solve::PredefinedOpaquesData<rustc_middle::ty::TyCtxt<'tcx>>,
             [decode] doc_link_resolutions: rustc_hir::def::DocLinkResMap,
             [] stripped_cfg_items: rustc_hir::attrs::StrippedCfgItem,
             [] mod_child: rustc_middle::metadata::ModChild,
diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs
index 0e645a3aae4..326df9239aa 100644
--- a/compiler/rustc_middle/src/query/mod.rs
+++ b/compiler/rustc_middle/src/query/mod.rs
@@ -124,7 +124,7 @@ use crate::query::plumbing::{
 };
 use crate::traits::query::{
     CanonicalAliasGoal, CanonicalDropckOutlivesGoal, CanonicalImpliedOutlivesBoundsGoal,
-    CanonicalPredicateGoal, CanonicalTyGoal, CanonicalTypeOpAscribeUserTypeGoal,
+    CanonicalMethodAutoderefStepsGoal, CanonicalPredicateGoal, CanonicalTypeOpAscribeUserTypeGoal,
     CanonicalTypeOpNormalizeGoal, CanonicalTypeOpProvePredicateGoal, DropckConstraint,
     DropckOutlivesResult, MethodAutoderefStepsResult, NoSolution, NormalizationResult,
     OutlivesBound,
@@ -2559,9 +2559,9 @@ rustc_queries! {
     }
 
     query method_autoderef_steps(
-        goal: CanonicalTyGoal<'tcx>
+        goal: CanonicalMethodAutoderefStepsGoal<'tcx>
     ) -> MethodAutoderefStepsResult<'tcx> {
-        desc { "computing autoderef types for `{}`", goal.canonical.value.value }
+        desc { "computing autoderef types for `{}`", goal.canonical.value.value.self_ty }
     }
 
     /// Used by `-Znext-solver` to compute proof trees.
diff --git a/compiler/rustc_middle/src/traits/query.rs b/compiler/rustc_middle/src/traits/query.rs
index 3f6faa1a572..c5cd7c54e4e 100644
--- a/compiler/rustc_middle/src/traits/query.rs
+++ b/compiler/rustc_middle/src/traits/query.rs
@@ -10,6 +10,7 @@ use rustc_span::Span;
 
 use crate::error::DropCheckOverflow;
 use crate::infer::canonical::{Canonical, CanonicalQueryInput, QueryResponse};
+use crate::traits::solve;
 pub use crate::traits::solve::NoSolution;
 use crate::ty::{self, GenericArg, Ty, TyCtxt};
 
@@ -67,7 +68,16 @@ pub mod type_op {
 pub type CanonicalAliasGoal<'tcx> =
     CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, ty::AliasTy<'tcx>>>;
 
-pub type CanonicalTyGoal<'tcx> = CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, Ty<'tcx>>>;
+pub type CanonicalMethodAutoderefStepsGoal<'tcx> =
+    CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, MethodAutoderefSteps<'tcx>>>;
+#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable, TypeFoldable, TypeVisitable)]
+pub struct MethodAutoderefSteps<'tcx> {
+    /// The list of opaque types currently in the storage.
+    ///
+    /// Only used by the new solver for now.
+    pub predefined_opaques_in_body: solve::PredefinedOpaques<'tcx>,
+    pub self_ty: Ty<'tcx>,
+}
 
 pub type CanonicalPredicateGoal<'tcx> =
     CanonicalQueryInput<'tcx, ty::ParamEnvAnd<'tcx, ty::Predicate<'tcx>>>;
@@ -144,6 +154,7 @@ impl<'tcx> FromIterator<DropckConstraint<'tcx>> for DropckConstraint<'tcx> {
 #[derive(Debug, HashStable)]
 pub struct CandidateStep<'tcx> {
     pub self_ty: Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
+    pub self_ty_is_opaque: bool,
     pub autoderefs: usize,
     /// `true` if the type results from a dereference of a raw pointer.
     /// when assembling candidates, we include these steps, but not when
diff --git a/compiler/rustc_middle/src/traits/solve.rs b/compiler/rustc_middle/src/traits/solve.rs
index ef5223de0e8..3343f270333 100644
--- a/compiler/rustc_middle/src/traits/solve.rs
+++ b/compiler/rustc_middle/src/traits/solve.rs
@@ -4,7 +4,7 @@ use rustc_type_ir as ir;
 pub use rustc_type_ir::solve::*;
 
 use crate::ty::{
-    self, FallibleTypeFolder, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor,
+    self, FallibleTypeFolder, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor,
     try_visit,
 };
 
@@ -15,16 +15,7 @@ pub type CandidateSource<'tcx> = ir::solve::CandidateSource<TyCtxt<'tcx>>;
 pub type CanonicalInput<'tcx, P = ty::Predicate<'tcx>> = ir::solve::CanonicalInput<TyCtxt<'tcx>, P>;
 pub type CanonicalResponse<'tcx> = ir::solve::CanonicalResponse<TyCtxt<'tcx>>;
 
-#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, HashStable)]
-pub struct PredefinedOpaques<'tcx>(pub(crate) Interned<'tcx, PredefinedOpaquesData<TyCtxt<'tcx>>>);
-
-impl<'tcx> std::ops::Deref for PredefinedOpaques<'tcx> {
-    type Target = PredefinedOpaquesData<TyCtxt<'tcx>>;
-
-    fn deref(&self) -> &Self::Target {
-        &self.0
-    }
-}
+pub type PredefinedOpaques<'tcx> = &'tcx ty::List<(ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)>;
 
 #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, HashStable)]
 pub struct ExternalConstraints<'tcx>(
@@ -93,35 +84,3 @@ impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for ExternalConstraints<'tcx> {
         self.normalization_nested_goals.visit_with(visitor)
     }
 }
-
-// FIXME: Having to clone `region_constraints` for folding feels bad and
-// probably isn't great wrt performance.
-//
-// Not sure how to fix this, maybe we should also intern `opaque_types` and
-// `region_constraints` here or something.
-impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for PredefinedOpaques<'tcx> {
-    fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
-        self,
-        folder: &mut F,
-    ) -> Result<Self, F::Error> {
-        Ok(FallibleTypeFolder::cx(folder).mk_predefined_opaques_in_body(PredefinedOpaquesData {
-            opaque_types: self
-                .opaque_types
-                .iter()
-                .map(|opaque| opaque.try_fold_with(folder))
-                .collect::<Result<_, F::Error>>()?,
-        }))
-    }
-
-    fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self {
-        TypeFolder::cx(folder).mk_predefined_opaques_in_body(PredefinedOpaquesData {
-            opaque_types: self.opaque_types.iter().map(|opaque| opaque.fold_with(folder)).collect(),
-        })
-    }
-}
-
-impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for PredefinedOpaques<'tcx> {
-    fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
-        self.opaque_types.visit_with(visitor)
-    }
-}
diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs
index 7d3e2c9965d..a42af7bb3e3 100644
--- a/compiler/rustc_middle/src/ty/context.rs
+++ b/compiler/rustc_middle/src/ty/context.rs
@@ -75,7 +75,7 @@ use crate::thir::Thir;
 use crate::traits;
 use crate::traits::solve::{
     self, CanonicalInput, ExternalConstraints, ExternalConstraintsData, PredefinedOpaques,
-    PredefinedOpaquesData, QueryResult, inspect,
+    QueryResult, inspect,
 };
 use crate::ty::predicate::ExistentialPredicateStableCmpExt as _;
 use crate::ty::{
@@ -116,7 +116,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
 
     fn mk_predefined_opaques_in_body(
         self,
-        data: PredefinedOpaquesData<Self>,
+        data: &[(ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)],
     ) -> Self::PredefinedOpaques {
         self.mk_predefined_opaques_in_body(data)
     }
@@ -941,7 +941,7 @@ pub struct CtxtInterners<'tcx> {
     layout: InternedSet<'tcx, LayoutData<FieldIdx, VariantIdx>>,
     adt_def: InternedSet<'tcx, AdtDefData>,
     external_constraints: InternedSet<'tcx, ExternalConstraintsData<TyCtxt<'tcx>>>,
-    predefined_opaques_in_body: InternedSet<'tcx, PredefinedOpaquesData<TyCtxt<'tcx>>>,
+    predefined_opaques_in_body: InternedSet<'tcx, List<(ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)>>,
     fields: InternedSet<'tcx, List<FieldIdx>>,
     local_def_ids: InternedSet<'tcx, List<LocalDefId>>,
     captures: InternedSet<'tcx, List<&'tcx ty::CapturedPlace<'tcx>>>,
@@ -2748,8 +2748,6 @@ direct_interners! {
     adt_def: pub mk_adt_def_from_data(AdtDefData): AdtDef -> AdtDef<'tcx>,
     external_constraints: pub mk_external_constraints(ExternalConstraintsData<TyCtxt<'tcx>>):
         ExternalConstraints -> ExternalConstraints<'tcx>,
-    predefined_opaques_in_body: pub mk_predefined_opaques_in_body(PredefinedOpaquesData<TyCtxt<'tcx>>):
-        PredefinedOpaques -> PredefinedOpaques<'tcx>,
 }
 
 macro_rules! slice_interners {
@@ -2786,6 +2784,7 @@ slice_interners!(
     offset_of: pub mk_offset_of((VariantIdx, FieldIdx)),
     patterns: pub mk_patterns(Pattern<'tcx>),
     outlives: pub mk_outlives(ty::ArgOutlivesPredicate<'tcx>),
+    predefined_opaques_in_body: pub mk_predefined_opaques_in_body((ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)),
 );
 
 impl<'tcx> TyCtxt<'tcx> {
@@ -3129,6 +3128,14 @@ impl<'tcx> TyCtxt<'tcx> {
         T::collect_and_apply(iter, |xs| self.mk_poly_existential_predicates(xs))
     }
 
+    pub fn mk_predefined_opaques_in_body_from_iter<I, T>(self, iter: I) -> T::Output
+    where
+        I: Iterator<Item = T>,
+        T: CollectAndApply<(ty::OpaqueTypeKey<'tcx>, Ty<'tcx>), PredefinedOpaques<'tcx>>,
+    {
+        T::collect_and_apply(iter, |xs| self.mk_predefined_opaques_in_body(xs))
+    }
+
     pub fn mk_clauses_from_iter<I, T>(self, iter: I) -> T::Output
     where
         I: Iterator<Item = T>,
diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs
index 11d109b463d..8dc4dfd677b 100644
--- a/compiler/rustc_middle/src/ty/structural_impls.rs
+++ b/compiler/rustc_middle/src/ty/structural_impls.rs
@@ -796,6 +796,7 @@ macro_rules! list_fold {
 
 list_fold! {
     &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>> : mk_poly_existential_predicates,
+    &'tcx ty::List<(ty::OpaqueTypeKey<'tcx>, Ty<'tcx>)>: mk_predefined_opaques_in_body,
     &'tcx ty::List<PlaceElem<'tcx>> : mk_place_elems,
     &'tcx ty::List<ty::Pattern<'tcx>> : mk_patterns,
     &'tcx ty::List<ty::ArgOutlivesPredicate<'tcx>> : mk_outlives,
diff --git a/compiler/rustc_next_trait_solver/src/canonical/mod.rs b/compiler/rustc_next_trait_solver/src/canonical/mod.rs
index e3520e238ed..b036ee6df7e 100644
--- a/compiler/rustc_next_trait_solver/src/canonical/mod.rs
+++ b/compiler/rustc_next_trait_solver/src/canonical/mod.rs
@@ -25,7 +25,7 @@ use crate::delegate::SolverDelegate;
 use crate::resolve::eager_resolve_vars;
 use crate::solve::{
     CanonicalInput, CanonicalResponse, Certainty, ExternalConstraintsData, Goal,
-    NestedNormalizationGoals, PredefinedOpaquesData, QueryInput, Response, inspect,
+    NestedNormalizationGoals, QueryInput, Response, inspect,
 };
 
 pub mod canonicalizer;
@@ -53,7 +53,7 @@ impl<I: Interner, T> ResponseT<I> for inspect::State<I, T> {
 pub(super) fn canonicalize_goal<D, I>(
     delegate: &D,
     goal: Goal<I, I::Predicate>,
-    opaque_types: Vec<(ty::OpaqueTypeKey<I>, I::Ty)>,
+    opaque_types: &[(ty::OpaqueTypeKey<I>, I::Ty)],
 ) -> (Vec<I::GenericArg>, CanonicalInput<I, I::Predicate>)
 where
     D: SolverDelegate<Interner = I>,
@@ -65,9 +65,7 @@ where
         &mut orig_values,
         QueryInput {
             goal,
-            predefined_opaques_in_body: delegate
-                .cx()
-                .mk_predefined_opaques_in_body(PredefinedOpaquesData { opaque_types }),
+            predefined_opaques_in_body: delegate.cx().mk_predefined_opaques_in_body(opaque_types),
         },
     );
     let query_input = ty::CanonicalQueryInput { canonical, typing_mode: delegate.typing_mode() };
diff --git a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs
index bb86357a85f..85110530ae9 100644
--- a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs
+++ b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs
@@ -194,7 +194,7 @@ where
     D: SolverDelegate<Interner = I>,
     I: Interner,
 {
-    #[instrument(level = "debug", skip(self))]
+    #[instrument(level = "debug", skip(self), ret)]
     fn evaluate_root_goal(
         &self,
         goal: Goal<I, I::Predicate>,
@@ -206,6 +206,7 @@ where
         })
     }
 
+    #[instrument(level = "debug", skip(self), ret)]
     fn root_goal_may_hold_opaque_types_jank(
         &self,
         goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
@@ -357,7 +358,7 @@ where
         f: impl FnOnce(&mut EvalCtxt<'_, D>, Goal<I, I::Predicate>) -> R,
     ) -> R {
         let (ref delegate, input, var_values) = D::build_with_canonical(cx, &canonical_input);
-        for &(key, ty) in &input.predefined_opaques_in_body.opaque_types {
+        for (key, ty) in input.predefined_opaques_in_body.iter() {
             let prev = delegate.register_hidden_type_in_storage(key, ty, I::Span::dummy());
             // It may be possible that two entries in the opaque type storage end up
             // with the same key after resolving contained inference variables.
@@ -467,7 +468,7 @@ where
         let opaque_types = self.delegate.clone_opaque_types_lookup_table();
         let (goal, opaque_types) = eager_resolve_vars(self.delegate, (goal, opaque_types));
 
-        let (orig_values, canonical_goal) = canonicalize_goal(self.delegate, goal, opaque_types);
+        let (orig_values, canonical_goal) = canonicalize_goal(self.delegate, goal, &opaque_types);
         let canonical_result = self.search_graph.evaluate_goal(
             self.cx(),
             canonical_goal,
@@ -548,7 +549,6 @@ where
                             .canonical
                             .value
                             .predefined_opaques_in_body
-                            .opaque_types
                             .len(),
                         stalled_vars,
                         sub_roots,
@@ -1557,7 +1557,7 @@ pub(super) fn evaluate_root_goal_for_proof_tree<D: SolverDelegate<Interner = I>,
     let opaque_types = delegate.clone_opaque_types_lookup_table();
     let (goal, opaque_types) = eager_resolve_vars(delegate, (goal, opaque_types));
 
-    let (orig_values, canonical_goal) = canonicalize_goal(delegate, goal, opaque_types);
+    let (orig_values, canonical_goal) = canonicalize_goal(delegate, goal, &opaque_types);
 
     let (canonical_result, final_revision) =
         delegate.cx().evaluate_root_goal_for_proof_tree_raw(canonical_goal);
diff --git a/compiler/rustc_next_trait_solver/src/solve/mod.rs b/compiler/rustc_next_trait_solver/src/solve/mod.rs
index afb86aaf8ab..a58caeecc33 100644
--- a/compiler/rustc_next_trait_solver/src/solve/mod.rs
+++ b/compiler/rustc_next_trait_solver/src/solve/mod.rs
@@ -381,6 +381,7 @@ where
 }
 
 /// The result of evaluating a goal.
+#[derive_where(Debug; I: Interner)]
 pub struct GoalEvaluation<I: Interner> {
     /// The goal we've evaluated. This is the input goal, but potentially with its
     /// inference variables resolved. This never applies any inference constraints
diff --git a/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs b/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs
index ae731505abf..34e0176d213 100644
--- a/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs
+++ b/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs
@@ -1,6 +1,6 @@
 use rustc_infer::traits::solve::Goal;
 use rustc_macros::extension;
-use rustc_middle::span_bug;
+use rustc_middle::{span_bug, ty};
 use rustc_next_trait_solver::solve::SolverDelegateEvalExt;
 
 use crate::infer::InferCtxt;
@@ -22,7 +22,7 @@ impl<'tcx> InferCtxt<'tcx> {
     /// for more details.
     fn predicate_may_hold_opaque_types_jank(&self, obligation: &PredicateObligation<'tcx>) -> bool {
         if self.next_trait_solver() {
-            <&SolverDelegate<'tcx>>::from(self).root_goal_may_hold_opaque_types_jank(Goal::new(
+            self.goal_may_hold_opaque_types_jank(Goal::new(
                 self.tcx,
                 obligation.param_env,
                 obligation.predicate,
@@ -32,6 +32,13 @@ impl<'tcx> InferCtxt<'tcx> {
         }
     }
 
+    /// See the comment on [OpaqueTypesJank](crate::solve::OpaqueTypesJank)
+    /// for more details.
+    fn goal_may_hold_opaque_types_jank(&self, goal: Goal<'tcx, ty::Predicate<'tcx>>) -> bool {
+        assert!(self.next_trait_solver());
+        <&SolverDelegate<'tcx>>::from(self).root_goal_may_hold_opaque_types_jank(goal)
+    }
+
     /// Evaluates whether the predicate can be satisfied in the given
     /// `ParamEnv`, and returns `false` if not certain. However, this is
     /// not entirely accurate if inference variables are involved.
diff --git a/compiler/rustc_type_ir/src/interner.rs b/compiler/rustc_type_ir/src/interner.rs
index cf58aec14a6..886d1a78bcb 100644
--- a/compiler/rustc_type_ir/src/interner.rs
+++ b/compiler/rustc_type_ir/src/interner.rs
@@ -11,9 +11,7 @@ use crate::inherent::*;
 use crate::ir_print::IrPrint;
 use crate::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem};
 use crate::relate::Relate;
-use crate::solve::{
-    CanonicalInput, ExternalConstraintsData, PredefinedOpaquesData, QueryResult, inspect,
-};
+use crate::solve::{CanonicalInput, ExternalConstraintsData, QueryResult, inspect};
 use crate::visit::{Flags, TypeVisitable};
 use crate::{self as ty, CanonicalParamEnvCacheEntry, search_graph};
 
@@ -70,10 +68,10 @@ pub trait Interner:
         + Hash
         + Eq
         + TypeFoldable<Self>
-        + Deref<Target = PredefinedOpaquesData<Self>>;
+        + SliceLike<Item = (ty::OpaqueTypeKey<Self>, Self::Ty)>;
     fn mk_predefined_opaques_in_body(
         self,
-        data: PredefinedOpaquesData<Self>,
+        data: &[(ty::OpaqueTypeKey<Self>, Self::Ty)],
     ) -> Self::PredefinedOpaques;
 
     type LocalDefIds: Copy
diff --git a/compiler/rustc_type_ir/src/solve/mod.rs b/compiler/rustc_type_ir/src/solve/mod.rs
index 1a1606d8268..9d9a8e49847 100644
--- a/compiler/rustc_type_ir/src/solve/mod.rs
+++ b/compiler/rustc_type_ir/src/solve/mod.rs
@@ -109,19 +109,6 @@ pub struct QueryInput<I: Interner, P> {
 
 impl<I: Interner, P: Eq> Eq for QueryInput<I, P> {}
 
-/// Opaques that are defined in the inference context before a query is called.
-#[derive_where(Clone, Hash, PartialEq, Debug, Default; I: Interner)]
-#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
-#[cfg_attr(
-    feature = "nightly",
-    derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext)
-)]
-pub struct PredefinedOpaquesData<I: Interner> {
-    pub opaque_types: Vec<(ty::OpaqueTypeKey<I>, I::Ty)>,
-}
-
-impl<I: Interner> Eq for PredefinedOpaquesData<I> {}
-
 /// Possible ways the given goal can be proven.
 #[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)]
 pub enum CandidateSource<I: Interner> {
diff --git a/tests/ui/closures/deduce-signature/obligation-with-leaking-placeholders.next.stderr b/tests/ui/closures/deduce-signature/obligation-with-leaking-placeholders.next.stderr
index 3d667f12371..4bb9047b303 100644
--- a/tests/ui/closures/deduce-signature/obligation-with-leaking-placeholders.next.stderr
+++ b/tests/ui/closures/deduce-signature/obligation-with-leaking-placeholders.next.stderr
@@ -5,7 +5,7 @@ LL |     needs_foo(|x| {
    |                ^
 ...
 LL |         x.to_string();
-   |         - type must be known at this point
+   |           --------- type must be known at this point
    |
 help: consider giving this closure parameter an explicit type
    |
diff --git a/tests/ui/impl-trait/call_method_ambiguous.next.stderr b/tests/ui/impl-trait/call_method_ambiguous.next.stderr
deleted file mode 100644
index 5251555f574..00000000000
--- a/tests/ui/impl-trait/call_method_ambiguous.next.stderr
+++ /dev/null
@@ -1,17 +0,0 @@
-error[E0282]: type annotations needed
-  --> $DIR/call_method_ambiguous.rs:26:13
-   |
-LL |         let mut iter = foo(n - 1, m);
-   |             ^^^^^^^^
-LL |
-LL |         assert_eq!(iter.get(), 1);
-   |                    ---- type must be known at this point
-   |
-help: consider giving `iter` an explicit type
-   |
-LL |         let mut iter: /* Type */ = foo(n - 1, m);
-   |                     ++++++++++++
-
-error: aborting due to 1 previous error
-
-For more information about this error, try `rustc --explain E0282`.
diff --git a/tests/ui/impl-trait/call_method_ambiguous.rs b/tests/ui/impl-trait/call_method_ambiguous.rs
index 6bcafc8ce14..021d6c22f79 100644
--- a/tests/ui/impl-trait/call_method_ambiguous.rs
+++ b/tests/ui/impl-trait/call_method_ambiguous.rs
@@ -1,6 +1,6 @@
 //@ revisions: current next
 //@[next] compile-flags: -Znext-solver
-//@[current] run-pass
+//@ run-pass
 
 trait Get {
     fn get(&mut self) -> u32;
@@ -24,7 +24,6 @@ where
 fn foo(n: usize, m: &mut ()) -> impl Get + use<'_> {
     if n > 0 {
         let mut iter = foo(n - 1, m);
-        //[next]~^ ERROR type annotations needed
         assert_eq!(iter.get(), 1);
     }
     m
diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl.next.stderr b/tests/ui/impl-trait/call_method_on_inherent_impl.next.stderr
deleted file mode 100644
index 271051f120a..00000000000
--- a/tests/ui/impl-trait/call_method_on_inherent_impl.next.stderr
+++ /dev/null
@@ -1,17 +0,0 @@
-error[E0282]: type annotations needed
-  --> $DIR/call_method_on_inherent_impl.rs:18:13
-   |
-LL |         let x = my_foo();
-   |             ^
-LL |
-LL |         x.my_debug();
-   |         - type must be known at this point
-   |
-help: consider giving `x` an explicit type
-   |
-LL |         let x: /* Type */ = my_foo();
-   |              ++++++++++++
-
-error: aborting due to 1 previous error
-
-For more information about this error, try `rustc --explain E0282`.
diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl.rs b/tests/ui/impl-trait/call_method_on_inherent_impl.rs
index 0e333c3260a..1dd38bc6717 100644
--- a/tests/ui/impl-trait/call_method_on_inherent_impl.rs
+++ b/tests/ui/impl-trait/call_method_on_inherent_impl.rs
@@ -1,6 +1,6 @@
 //@ revisions: current next
 //@[next] compile-flags: -Znext-solver
-//@[current] check-pass
+//@ check-pass
 
 trait MyDebug {
     fn my_debug(&self);
@@ -16,7 +16,6 @@ where
 fn my_foo() -> impl std::fmt::Debug {
     if false {
         let x = my_foo();
-        //[next]~^ ERROR type annotations needed
         x.my_debug();
     }
     ()
diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.current.stderr b/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.current.stderr
index 6ecb2b05fc5..e7104664470 100644
--- a/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.current.stderr
+++ b/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.current.stderr
@@ -1,5 +1,5 @@
 error[E0599]: no method named `my_debug` found for reference `&impl Debug` in the current scope
-  --> $DIR/call_method_on_inherent_impl_on_rigid_type.rs:16:11
+  --> $DIR/call_method_on_inherent_impl_on_rigid_type.rs:15:11
    |
 LL |         x.my_debug();
    |           ^^^^^^^^ method not found in `&impl Debug`
diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.next.stderr b/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.next.stderr
index 5fb0b8f1d14..de808259d40 100644
--- a/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.next.stderr
+++ b/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.next.stderr
@@ -1,17 +1,15 @@
-error[E0282]: type annotations needed for `&_`
-  --> $DIR/call_method_on_inherent_impl_on_rigid_type.rs:14:13
+error[E0599]: no method named `my_debug` found for reference `&_` in the current scope
+  --> $DIR/call_method_on_inherent_impl_on_rigid_type.rs:15:11
    |
-LL |         let x = &my_foo();
-   |             ^
-LL |
 LL |         x.my_debug();
-   |           -------- type must be known at this point
+   |           ^^^^^^^^ method not found in `&_`
    |
-help: consider giving `x` an explicit type, where the placeholders `_` are specified
+   = help: items from traits can only be used if the trait is implemented and in scope
+help: trait `MyDebug` which provides `my_debug` is implemented but not in scope; perhaps you want to import it
+   |
+LL + use MyDebug;
    |
-LL |         let x: &_ = &my_foo();
-   |              ++++
 
 error: aborting due to 1 previous error
 
-For more information about this error, try `rustc --explain E0282`.
+For more information about this error, try `rustc --explain E0599`.
diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.rs b/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.rs
index 7fb2ff3b2bc..0c9909efa1b 100644
--- a/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.rs
+++ b/tests/ui/impl-trait/call_method_on_inherent_impl_on_rigid_type.rs
@@ -12,9 +12,8 @@ impl MyDebug for &() {
 fn my_foo() -> impl std::fmt::Debug {
     if false {
         let x = &my_foo();
-        //[next]~^ ERROR: type annotations needed
         x.my_debug();
-        //[current]~^ ERROR: no method named `my_debug`
+        //~^ ERROR: no method named `my_debug`
     }
     ()
 }
diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl_ref.current.stderr b/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.current.stderr
index fb51bb7b417..71acbd1497d 100644
--- a/tests/ui/impl-trait/call_method_on_inherent_impl_ref.current.stderr
+++ b/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.current.stderr
@@ -1,5 +1,5 @@
 error[E0599]: no method named `my_debug` found for opaque type `impl Debug` in the current scope
-  --> $DIR/call_method_on_inherent_impl_ref.rs:19:11
+  --> $DIR/call_method_on_inherent_impl_ref-err.rs:18:11
    |
 LL |     fn my_debug(&self);
    |        -------- the method is available for `&impl Debug` here
@@ -9,7 +9,7 @@ LL |         x.my_debug();
    |
    = help: items from traits can only be used if the trait is implemented and in scope
 note: `MyDebug` defines an item `my_debug`, perhaps you need to implement it
-  --> $DIR/call_method_on_inherent_impl_ref.rs:4:1
+  --> $DIR/call_method_on_inherent_impl_ref-err.rs:4:1
    |
 LL | trait MyDebug {
    | ^^^^^^^^^^^^^
diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.next.stderr b/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.next.stderr
new file mode 100644
index 00000000000..523505e9802
--- /dev/null
+++ b/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.next.stderr
@@ -0,0 +1,19 @@
+error[E0599]: no method named `my_debug` found for type `_` in the current scope
+  --> $DIR/call_method_on_inherent_impl_ref-err.rs:18:11
+   |
+LL |     fn my_debug(&self);
+   |        -------- the method is available for `&_` here
+...
+LL |         x.my_debug();
+   |           ^^^^^^^^ method not found in `_`
+   |
+   = help: items from traits can only be used if the trait is implemented and in scope
+note: `MyDebug` defines an item `my_debug`, perhaps you need to implement it
+  --> $DIR/call_method_on_inherent_impl_ref-err.rs:4:1
+   |
+LL | trait MyDebug {
+   | ^^^^^^^^^^^^^
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.rs b/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.rs
new file mode 100644
index 00000000000..0ed09bc76a4
--- /dev/null
+++ b/tests/ui/impl-trait/call_method_on_inherent_impl_ref-err.rs
@@ -0,0 +1,24 @@
+//@ revisions: current next
+//@[next] compile-flags: -Znext-solver
+
+trait MyDebug {
+    fn my_debug(&self);
+}
+
+impl<T> MyDebug for &T
+where
+    T: std::fmt::Debug,
+{
+    fn my_debug(&self) {}
+}
+
+fn my_foo() -> impl std::fmt::Debug {
+    if false {
+        let x = my_foo();
+        x.my_debug();
+        //~^ ERROR no method named `my_debug` found
+    }
+    ()
+}
+
+fn main() {}
diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl_ref.rs b/tests/ui/impl-trait/call_method_on_inherent_impl_ref-ok.rs
index 4e4098b37f9..40739d6a0ce 100644
--- a/tests/ui/impl-trait/call_method_on_inherent_impl_ref.rs
+++ b/tests/ui/impl-trait/call_method_on_inherent_impl_ref-ok.rs
@@ -1,5 +1,6 @@
 //@ revisions: current next
 //@[next] compile-flags: -Znext-solver
+//@ check-pass
 
 trait MyDebug {
     fn my_debug(&self);
@@ -12,20 +13,9 @@ where
     fn my_debug(&self) {}
 }
 
-fn my_foo() -> impl std::fmt::Debug {
-    if false {
-        let x = my_foo();
-        //[next]~^ ERROR type annotations needed
-        x.my_debug();
-        //[current]~^ ERROR no method named `my_debug` found
-    }
-    ()
-}
-
 fn my_bar() -> impl std::fmt::Debug {
     if false {
         let x = &my_bar();
-        //[next]~^ ERROR type annotations needed
         x.my_debug();
     }
     ()
diff --git a/tests/ui/impl-trait/call_method_on_inherent_impl_ref.next.stderr b/tests/ui/impl-trait/call_method_on_inherent_impl_ref.next.stderr
deleted file mode 100644
index 7202cb6f90a..00000000000
--- a/tests/ui/impl-trait/call_method_on_inherent_impl_ref.next.stderr
+++ /dev/null
@@ -1,31 +0,0 @@
-error[E0282]: type annotations needed
-  --> $DIR/call_method_on_inherent_impl_ref.rs:17:13
-   |
-LL |         let x = my_foo();
-   |             ^
-LL |
-LL |         x.my_debug();
-   |         - type must be known at this point
-   |
-help: consider giving `x` an explicit type
-   |
-LL |         let x: /* Type */ = my_foo();
-   |              ++++++++++++
-
-error[E0282]: type annotations needed for `&_`
-  --> $DIR/call_method_on_inherent_impl_ref.rs:27:13
-   |
-LL |         let x = &my_bar();
-   |             ^
-LL |
-LL |         x.my_debug();
-   |           -------- type must be known at this point
-   |
-help: consider giving `x` an explicit type, where the placeholders `_` are specified
-   |
-LL |         let x: &_ = &my_bar();
-   |              ++++
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0282`.
diff --git a/tests/ui/impl-trait/hidden-type-is-opaque-2.default.stderr b/tests/ui/impl-trait/hidden-type-is-opaque-2.default.stderr
index dca0a7b0a1a..cb383b2db38 100644
--- a/tests/ui/impl-trait/hidden-type-is-opaque-2.default.stderr
+++ b/tests/ui/impl-trait/hidden-type-is-opaque-2.default.stderr
@@ -5,7 +5,7 @@ LL |     Thunk::new(|mut cont| {
    |                 ^^^^^^^^
 LL |
 LL |         cont.reify_as();
-   |         ---- type must be known at this point
+   |              -------- type must be known at this point
    |
 help: consider giving this closure parameter an explicit type
    |
@@ -19,7 +19,7 @@ LL |     Thunk::new(|mut cont| {
    |                 ^^^^^^^^
 LL |
 LL |         cont.reify_as();
-   |         ---- type must be known at this point
+   |              -------- type must be known at this point
    |
 help: consider giving this closure parameter an explicit type
    |
diff --git a/tests/ui/impl-trait/hidden-type-is-opaque-2.next.stderr b/tests/ui/impl-trait/hidden-type-is-opaque-2.next.stderr
index dca0a7b0a1a..cb383b2db38 100644
--- a/tests/ui/impl-trait/hidden-type-is-opaque-2.next.stderr
+++ b/tests/ui/impl-trait/hidden-type-is-opaque-2.next.stderr
@@ -5,7 +5,7 @@ LL |     Thunk::new(|mut cont| {
    |                 ^^^^^^^^
 LL |
 LL |         cont.reify_as();
-   |         ---- type must be known at this point
+   |              -------- type must be known at this point
    |
 help: consider giving this closure parameter an explicit type
    |
@@ -19,7 +19,7 @@ LL |     Thunk::new(|mut cont| {
    |                 ^^^^^^^^
 LL |
 LL |         cont.reify_as();
-   |         ---- type must be known at this point
+   |              -------- type must be known at this point
    |
 help: consider giving this closure parameter an explicit type
    |
diff --git a/tests/ui/impl-trait/method-resolution4.next.stderr b/tests/ui/impl-trait/method-resolution4.next.stderr
deleted file mode 100644
index 0524f49f98e..00000000000
--- a/tests/ui/impl-trait/method-resolution4.next.stderr
+++ /dev/null
@@ -1,9 +0,0 @@
-error[E0282]: type annotations needed
-  --> $DIR/method-resolution4.rs:13:9
-   |
-LL |         foo(false).next().unwrap();
-   |         ^^^^^^^^^^ cannot infer type
-
-error: aborting due to 1 previous error
-
-For more information about this error, try `rustc --explain E0282`.
diff --git a/tests/ui/impl-trait/method/broken-deref-chain.current.stderr b/tests/ui/impl-trait/method/broken-deref-chain.current.stderr
new file mode 100644
index 00000000000..726f076b183
--- /dev/null
+++ b/tests/ui/impl-trait/method/broken-deref-chain.current.stderr
@@ -0,0 +1,19 @@
+error[E0308]: mismatched types
+  --> $DIR/broken-deref-chain.rs:41:30
+   |
+LL | fn trait_method() -> impl Trait {
+   |                      ---------- the found opaque type
+...
+LL |         x.trait_method();
+   |         - here the type of `x` is inferred to be `Foo<u32, impl Trait>`
+LL |         let _: Foo<i32, _> = x; // Test that we did not apply the deref step
+   |                -----------   ^ expected `Foo<i32, _>`, found `Foo<u32, impl Trait>`
+   |                |
+   |                expected due to this
+   |
+   = note: expected struct `Foo<i32, _>`
+              found struct `Foo<u32, impl Trait>`
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/impl-trait/method/broken-deref-chain.rs b/tests/ui/impl-trait/method/broken-deref-chain.rs
new file mode 100644
index 00000000000..8b45e044f43
--- /dev/null
+++ b/tests/ui/impl-trait/method/broken-deref-chain.rs
@@ -0,0 +1,47 @@
+//@ revisions: current next
+//@[next] compile-flags: -Znext-solver
+//@[next] check-pass
+
+// An annoying edge case of method selection. While computing the deref-chain
+// constrains `T` to `u32`, the final method candidate does not and instead
+// constrains to `i32`. In this case, we no longer check that the opaque
+// remains unconstrained. Both method calls in this test constrain the opaque
+// to `i32`.
+use std::ops::Deref;
+
+struct Foo<T, U>(T, U);
+impl<U> Deref for Foo<u32, U> {
+    type Target = U;
+    fn deref(&self) -> &Self::Target {
+        &self.1
+    }
+}
+
+impl Foo<i32, i32> {
+    fn method(&self) {}
+}
+fn inherent_method() -> impl Sized {
+    if false {
+        let x = Foo(Default::default(), inherent_method());
+        x.method();
+        let _: Foo<i32, _> = x; // Test that we did not apply the deref step
+    }
+    1i32
+}
+
+trait Trait {
+    fn trait_method(&self) {}
+}
+impl Trait for Foo<i32, i32> {}
+impl Trait for i32 {}
+fn trait_method() -> impl Trait {
+    if false {
+        let x = Foo(Default::default(), trait_method());
+        x.trait_method();
+        let _: Foo<i32, _> = x; // Test that we did not apply the deref step
+        //[current]~^ ERROR mismatched types
+    }
+    1i32
+}
+
+fn main() {}
diff --git a/tests/ui/impl-trait/method-resolution.rs b/tests/ui/impl-trait/method/method-resolution.rs
index 60fbacd8646..60fbacd8646 100644
--- a/tests/ui/impl-trait/method-resolution.rs
+++ b/tests/ui/impl-trait/method/method-resolution.rs
diff --git a/tests/ui/impl-trait/method-resolution2.next.stderr b/tests/ui/impl-trait/method/method-resolution2.next.stderr
index 223430e1658..223430e1658 100644
--- a/tests/ui/impl-trait/method-resolution2.next.stderr
+++ b/tests/ui/impl-trait/method/method-resolution2.next.stderr
diff --git a/tests/ui/impl-trait/method-resolution2.rs b/tests/ui/impl-trait/method/method-resolution2.rs
index 88d4f3d9896..88d4f3d9896 100644
--- a/tests/ui/impl-trait/method-resolution2.rs
+++ b/tests/ui/impl-trait/method/method-resolution2.rs
diff --git a/tests/ui/impl-trait/method-resolution3.current.stderr b/tests/ui/impl-trait/method/method-resolution3.current.stderr
index 87dd862ef8f..87dd862ef8f 100644
--- a/tests/ui/impl-trait/method-resolution3.current.stderr
+++ b/tests/ui/impl-trait/method/method-resolution3.current.stderr
diff --git a/tests/ui/impl-trait/method-resolution3.next.stderr b/tests/ui/impl-trait/method/method-resolution3.next.stderr
index 87dd862ef8f..87dd862ef8f 100644
--- a/tests/ui/impl-trait/method-resolution3.next.stderr
+++ b/tests/ui/impl-trait/method/method-resolution3.next.stderr
diff --git a/tests/ui/impl-trait/method-resolution3.rs b/tests/ui/impl-trait/method/method-resolution3.rs
index 8c47ef4fc75..8c47ef4fc75 100644
--- a/tests/ui/impl-trait/method-resolution3.rs
+++ b/tests/ui/impl-trait/method/method-resolution3.rs
diff --git a/tests/ui/impl-trait/method-resolution4.rs b/tests/ui/impl-trait/method/method-resolution4.rs
index 90e7850cad5..f90a9309cda 100644
--- a/tests/ui/impl-trait/method-resolution4.rs
+++ b/tests/ui/impl-trait/method/method-resolution4.rs
@@ -6,12 +6,11 @@
 
 //@ revisions: current next
 //@[next] compile-flags: -Znext-solver
-//@[current] check-pass
+//@ check-pass
 
 fn foo(b: bool) -> impl Iterator<Item = ()> {
     if b {
         foo(false).next().unwrap();
-        //[next]~^ ERROR type annotations needed
     }
     std::iter::empty()
 }
diff --git a/tests/ui/impl-trait/method/method-resolution5-deref-no-constrain.current.stderr b/tests/ui/impl-trait/method/method-resolution5-deref-no-constrain.current.stderr
new file mode 100644
index 00000000000..08578de426a
--- /dev/null
+++ b/tests/ui/impl-trait/method/method-resolution5-deref-no-constrain.current.stderr
@@ -0,0 +1,19 @@
+error[E0308]: mismatched types
+  --> $DIR/method-resolution5-deref-no-constrain.rs:20:5
+   |
+LL | fn via_deref() -> impl Deref<Target = Foo> {
+   |                                       --- expected `&Foo` because of return type
+...
+LL |     Box::new(Foo)
+   |     ^^^^^^^^^^^^^ expected `&Foo`, found `Box<Foo>`
+   |
+   = note: expected reference `&Foo`
+                 found struct `Box<Foo>`
+help: consider borrowing here
+   |
+LL |     &Box::new(Foo)
+   |     +
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/impl-trait/method/method-resolution5-deref-no-constrain.rs b/tests/ui/impl-trait/method/method-resolution5-deref-no-constrain.rs
new file mode 100644
index 00000000000..2c41f62b9fd
--- /dev/null
+++ b/tests/ui/impl-trait/method/method-resolution5-deref-no-constrain.rs
@@ -0,0 +1,23 @@
+//! The recursive method call yields the opaque type. We want
+//! to use the impl candidate for `Foo` here without constraining
+//! the opaque to `&Foo`.
+
+//@ revisions: current next
+//@[next] compile-flags: -Znext-solver
+//@[next] check-pass
+
+use std::ops::Deref;
+struct Foo;
+impl Foo {
+    fn method(&self) {}
+}
+fn via_deref() -> impl Deref<Target = Foo> {
+    // Currently errors on stable, but should not
+    if false {
+        via_deref().method();
+    }
+
+    Box::new(Foo)
+    //[current]~^ ERROR mismatched types
+}
+fn main() {}
diff --git a/tests/ui/impl-trait/method/method-resolution5-deref.rs b/tests/ui/impl-trait/method/method-resolution5-deref.rs
new file mode 100644
index 00000000000..6133a8efe24
--- /dev/null
+++ b/tests/ui/impl-trait/method/method-resolution5-deref.rs
@@ -0,0 +1,30 @@
+//! The recursive method call yields the opaque type. We want
+//! to use the trait candidate for `impl Foo` here while not
+//! applying it for the `impl Deref`.
+
+//@ revisions: current next
+//@[next] compile-flags: -Znext-solver
+//@ check-pass
+
+use std::ops::Deref;
+trait Foo {
+    fn method(&self) {}
+}
+impl Foo for u32 {}
+fn via_deref() -> impl Deref<Target = impl Foo> {
+    if false {
+        via_deref().method();
+    }
+
+    Box::new(1u32)
+}
+
+fn via_deref_nested() -> Box<impl Deref<Target = impl Foo>> {
+    if false {
+        via_deref_nested().method();
+    }
+
+    Box::new(Box::new(1u32))
+}
+
+fn main() {}
diff --git a/tests/ui/impl-trait/method/would-constrain-opaque.current.stderr b/tests/ui/impl-trait/method/would-constrain-opaque.current.stderr
new file mode 100644
index 00000000000..60533a39c53
--- /dev/null
+++ b/tests/ui/impl-trait/method/would-constrain-opaque.current.stderr
@@ -0,0 +1,29 @@
+error[E0599]: no method named `method` found for reference `&impl Sized` in the current scope
+  --> $DIR/would-constrain-opaque.rs:28:11
+   |
+LL |         x.method();
+   |           ^^^^^^ method not found in `&impl Sized`
+   |
+   = help: items from traits can only be used if the trait is implemented and in scope
+note: `Trait` defines an item `method`, perhaps you need to implement it
+  --> $DIR/would-constrain-opaque.rs:15:1
+   |
+LL | trait Trait: Sized {
+   | ^^^^^^^^^^^^^^^^^^
+
+error[E0599]: no method named `method` found for reference `&impl Sized` in the current scope
+  --> $DIR/would-constrain-opaque.rs:30:11
+   |
+LL |         x.method();
+   |           ^^^^^^ method not found in `&impl Sized`
+   |
+   = help: items from traits can only be used if the trait is implemented and in scope
+note: `Trait` defines an item `method`, perhaps you need to implement it
+  --> $DIR/would-constrain-opaque.rs:15:1
+   |
+LL | trait Trait: Sized {
+   | ^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/tests/ui/impl-trait/method/would-constrain-opaque.next.stderr b/tests/ui/impl-trait/method/would-constrain-opaque.next.stderr
new file mode 100644
index 00000000000..23a4ceb826a
--- /dev/null
+++ b/tests/ui/impl-trait/method/would-constrain-opaque.next.stderr
@@ -0,0 +1,27 @@
+error[E0599]: no method named `method` found for reference `&_` in the current scope
+  --> $DIR/would-constrain-opaque.rs:28:11
+   |
+LL |         x.method();
+   |           ^^^^^^ method not found in `&_`
+   |
+   = help: items from traits can only be used if the trait is implemented and in scope
+help: trait `Trait` which provides `method` is implemented but not in scope; perhaps you want to import it
+   |
+LL + use Trait;
+   |
+
+error[E0599]: no method named `method` found for reference `&_` in the current scope
+  --> $DIR/would-constrain-opaque.rs:30:11
+   |
+LL |         x.method();
+   |           ^^^^^^ method not found in `&_`
+   |
+   = help: items from traits can only be used if the trait is implemented and in scope
+help: trait `Trait` which provides `method` is implemented but not in scope; perhaps you want to import it
+   |
+LL + use Trait;
+   |
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/tests/ui/impl-trait/method/would-constrain-opaque.rs b/tests/ui/impl-trait/method/would-constrain-opaque.rs
new file mode 100644
index 00000000000..8dd32282529
--- /dev/null
+++ b/tests/ui/impl-trait/method/would-constrain-opaque.rs
@@ -0,0 +1,39 @@
+//@ revisions: current next
+//@[next] compile-flags: -Znext-solver
+
+// If we don't treat `impl Sized` as rigid, the first call would
+// resolve to the trait method, constraining the opaque, while the
+// second call would resolve to the inherent method.
+//
+// We avoid cases like this by rejecting candidates which constrain
+// opaque types encountered in the autoderef chain.
+//
+// FIXME(-Znext-solver): ideally we would note that the inference variable
+// is an opaque type in the error message and change this to a type annotations
+// needed error.
+
+trait Trait: Sized {
+    fn method(self) {}
+}
+impl Trait for &Foo {}
+
+struct Foo;
+impl Foo {
+    fn method(&self) {}
+}
+
+fn define_opaque(b: bool) -> impl Sized {
+    if b {
+        let x = &define_opaque(false);
+        x.method();
+        //~^ ERROR no method named `method` found for reference
+        x.method();
+        //~^ ERROR no method named `method` found for reference
+    }
+
+    Foo
+}
+
+fn main() {
+    define_opaque(true);
+}
diff --git a/tests/ui/impl-trait/recursive-bound-eval.next.stderr b/tests/ui/impl-trait/recursive-bound-eval.next.stderr
deleted file mode 100644
index 4bab290d71c..00000000000
--- a/tests/ui/impl-trait/recursive-bound-eval.next.stderr
+++ /dev/null
@@ -1,9 +0,0 @@
-error[E0282]: type annotations needed
-  --> $DIR/recursive-bound-eval.rs:20:13
-   |
-LL |     move || recursive_fn().parse()
-   |             ^^^^^^^^^^^^^^ cannot infer type
-
-error: aborting due to 1 previous error
-
-For more information about this error, try `rustc --explain E0282`.
diff --git a/tests/ui/impl-trait/recursive-bound-eval.rs b/tests/ui/impl-trait/recursive-bound-eval.rs
index 7859c8983fc..058b12e5651 100644
--- a/tests/ui/impl-trait/recursive-bound-eval.rs
+++ b/tests/ui/impl-trait/recursive-bound-eval.rs
@@ -1,10 +1,9 @@
 //! Test that we can evaluate nested obligations when invoking methods on recursive calls on
 //! an RPIT.
 
-//@revisions: next current
+//@ revisions: next current
 //@[next] compile-flags: -Znext-solver
-
-//@[current] check-pass
+//@ check-pass
 
 pub trait Parser<E> {
     fn parse(&self) -> E;
@@ -18,7 +17,6 @@ impl<E, T: Fn() -> E> Parser<E> for T {
 
 pub fn recursive_fn<E>() -> impl Parser<E> {
     move || recursive_fn().parse()
-    //[next]~^ ERROR: type annotations needed
 }
 
 fn main() {}
diff --git a/tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr b/tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr
deleted file mode 100644
index 5ce6eb0fc39..00000000000
--- a/tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr
+++ /dev/null
@@ -1,17 +0,0 @@
-error[E0282]: type annotations needed
-  --> $DIR/recursive-coroutine-boxed.rs:11:23
-   |
-LL |         let mut gen = Box::pin(foo());
-   |                       ^^^^^^^^ cannot infer type of the type parameter `T` declared on the struct `Box`
-LL |
-LL |         let mut r = gen.as_mut().resume(());
-   |                         ------ type must be known at this point
-   |
-help: consider specifying the generic argument
-   |
-LL |         let mut gen = Box::<T>::pin(foo());
-   |                          +++++
-
-error: aborting due to 1 previous error
-
-For more information about this error, try `rustc --explain E0282`.
diff --git a/tests/ui/impl-trait/recursive-coroutine-boxed.rs b/tests/ui/impl-trait/recursive-coroutine-boxed.rs
index 306edc3591e..932023d103d 100644
--- a/tests/ui/impl-trait/recursive-coroutine-boxed.rs
+++ b/tests/ui/impl-trait/recursive-coroutine-boxed.rs
@@ -1,7 +1,7 @@
 //@ revisions: current next
 //@ ignore-compare-mode-next-solver (explicit revisions)
-//@[current] check-pass
 //@[next] compile-flags: -Znext-solver
+//@ check-pass
 #![feature(coroutines, coroutine_trait)]
 
 use std::ops::{Coroutine, CoroutineState};
@@ -9,7 +9,6 @@ use std::ops::{Coroutine, CoroutineState};
 fn foo() -> impl Coroutine<Yield = (), Return = ()> {
     #[coroutine] || {
         let mut gen = Box::pin(foo());
-        //[next]~^ ERROR type annotations needed
         let mut r = gen.as_mut().resume(());
         while let CoroutineState::Yielded(v) = r {
             yield v;
diff --git a/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-0.stderr b/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-0.stderr
index 10056bdf3d4..ba1c81c4518 100644
--- a/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-0.stderr
+++ b/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-0.stderr
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed
   --> $DIR/incompat-call-after-qualified-path-0.rs:21:6
    |
 LL |   f(|a, b| a.cmp(b));
-   |      ^     - type must be known at this point
+   |      ^       --- type must be known at this point
    |
 help: consider giving this closure parameter an explicit type
    |
diff --git a/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-1.stderr b/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-1.stderr
index 632a9b99f84..93bba3625b5 100644
--- a/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-1.stderr
+++ b/tests/ui/inference/need_type_info/incompat-call-after-qualified-path-1.stderr
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed
   --> $DIR/incompat-call-after-qualified-path-1.rs:25:6
    |
 LL |   f(|a, b| a.cmp(b));
-   |      ^     - type must be known at this point
+   |      ^       --- type must be known at this point
    |
 help: consider giving this closure parameter an explicit type
    |
diff --git a/tests/ui/issues/issue-2151.stderr b/tests/ui/issues/issue-2151.stderr
index b130f162414..59fef42eb5e 100644
--- a/tests/ui/issues/issue-2151.stderr
+++ b/tests/ui/issues/issue-2151.stderr
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed
 LL |     let x = panic!();
    |         ^
 LL |     x.clone();
-   |     - type must be known at this point
+   |       ----- type must be known at this point
    |
 help: consider giving `x` an explicit type
    |
diff --git a/tests/ui/lazy-type-alias-impl-trait/branches3.stderr b/tests/ui/lazy-type-alias-impl-trait/branches3.stderr
index 117d189867b..539673bc343 100644
--- a/tests/ui/lazy-type-alias-impl-trait/branches3.stderr
+++ b/tests/ui/lazy-type-alias-impl-trait/branches3.stderr
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed
   --> $DIR/branches3.rs:9:10
    |
 LL |         |s| s.len()
-   |          ^  - type must be known at this point
+   |          ^    --- type must be known at this point
    |
 help: consider giving this closure parameter an explicit type
    |
@@ -13,7 +13,7 @@ error[E0282]: type annotations needed
   --> $DIR/branches3.rs:18:10
    |
 LL |         |s| s.len()
-   |          ^  - type must be known at this point
+   |          ^    --- type must be known at this point
    |
 help: consider giving this closure parameter an explicit type
    |
@@ -24,7 +24,7 @@ error[E0282]: type annotations needed
   --> $DIR/branches3.rs:26:10
    |
 LL |         |s| s.len()
-   |          ^  - type must be known at this point
+   |          ^    --- type must be known at this point
    |
 help: consider giving this closure parameter an explicit type
    |
@@ -35,7 +35,7 @@ error[E0282]: type annotations needed
   --> $DIR/branches3.rs:33:10
    |
 LL |         |s| s.len()
-   |          ^  - type must be known at this point
+   |          ^    --- type must be known at this point
    |
 help: consider giving this closure parameter an explicit type
    |
diff --git a/tests/ui/proc-macro/quote/not-repeatable.rs b/tests/ui/proc-macro/quote/not-repeatable.rs
index 0291e4ddf88..373f0e74dbd 100644
--- a/tests/ui/proc-macro/quote/not-repeatable.rs
+++ b/tests/ui/proc-macro/quote/not-repeatable.rs
@@ -8,5 +8,7 @@ struct Ipv4Addr;
 
 fn main() {
     let ip = Ipv4Addr;
-    let _ = quote! { $($ip)* }; //~ ERROR the method `quote_into_iter` exists for struct `Ipv4Addr`, but its trait bounds were not satisfied
+    let _ = quote! { $($ip)* };
+    //~^ ERROR the method `quote_into_iter` exists for struct `Ipv4Addr`, but its trait bounds were not satisfied
+    //~| ERROR type annotations needed
 }
diff --git a/tests/ui/proc-macro/quote/not-repeatable.stderr b/tests/ui/proc-macro/quote/not-repeatable.stderr
index aeda08d7de6..ff31799abb0 100644
--- a/tests/ui/proc-macro/quote/not-repeatable.stderr
+++ b/tests/ui/proc-macro/quote/not-repeatable.stderr
@@ -20,6 +20,13 @@ note: the traits `Iterator` and `ToTokens` must be implemented
   --> $SRC_DIR/proc_macro/src/to_tokens.rs:LL:COL
   --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
 
-error: aborting due to 1 previous error
+error[E0282]: type annotations needed
+  --> $DIR/not-repeatable.rs:11:13
+   |
+LL |     let _ = quote! { $($ip)* };
+   |             ^^^^^^^^^^^^^^^^^^ cannot infer type
+
+error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0599`.
+Some errors have detailed explanations: E0282, E0599.
+For more information about an error, try `rustc --explain E0282`.
diff --git a/tests/ui/repeat-expr/copy-inference-side-effects-are-lazy.stderr b/tests/ui/repeat-expr/copy-inference-side-effects-are-lazy.stderr
index ba44beb76db..b8a8f927542 100644
--- a/tests/ui/repeat-expr/copy-inference-side-effects-are-lazy.stderr
+++ b/tests/ui/repeat-expr/copy-inference-side-effects-are-lazy.stderr
@@ -5,9 +5,9 @@ LL |     let x = [Foo(PhantomData); 2];
    |         ^
 LL |
 LL |     extract(x).max(2);
-   |     ---------- type must be known at this point
+   |                --- type must be known at this point
    |
-help: consider giving `x` an explicit type, where the type for type parameter `T` is specified
+help: consider giving `x` an explicit type, where the placeholders `_` are specified
    |
 LL |     let x: [Foo<T>; 2] = [Foo(PhantomData); 2];
    |          +++++++++++++
diff --git a/tests/ui/span/issue-42234-unknown-receiver-type.stderr b/tests/ui/span/issue-42234-unknown-receiver-type.stderr
index 10308ec07da..71ac4f53b3f 100644
--- a/tests/ui/span/issue-42234-unknown-receiver-type.stderr
+++ b/tests/ui/span/issue-42234-unknown-receiver-type.stderr
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed
 LL |     let x: Option<_> = None;
    |                        ^^^^ cannot infer type of the type parameter `T` declared on the enum `Option`
 LL |     x.unwrap().method_that_could_exist_on_some_type();
-   |     ---------- type must be known at this point
+   |                ------------------------------------ type must be known at this point
    |
 help: consider specifying the generic argument
    |
@@ -16,6 +16,8 @@ error[E0282]: type annotations needed
    |
 LL |         .sum::<_>()
    |          ^^^ cannot infer type of the type parameter `S` declared on the method `sum`
+LL |         .to_string()
+   |          --------- type must be known at this point
    |
 
 error: aborting due to 2 previous errors
diff --git a/tests/ui/type-alias-impl-trait/closures_in_branches.stderr b/tests/ui/type-alias-impl-trait/closures_in_branches.stderr
index 849ffd214f0..559bc57d906 100644
--- a/tests/ui/type-alias-impl-trait/closures_in_branches.stderr
+++ b/tests/ui/type-alias-impl-trait/closures_in_branches.stderr
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed
   --> $DIR/closures_in_branches.rs:8:10
    |
 LL |         |x| x.len()
-   |          ^  - type must be known at this point
+   |          ^    --- type must be known at this point
    |
 help: consider giving this closure parameter an explicit type
    |
@@ -13,7 +13,7 @@ error[E0282]: type annotations needed
   --> $DIR/closures_in_branches.rs:22:10
    |
 LL |         |x| x.len()
-   |          ^  - type must be known at this point
+   |          ^    --- type must be known at this point
    |
 help: consider giving this closure parameter an explicit type
    |
diff --git a/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.next.stderr b/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.next.stderr
index bbdd3923821..37bde4b18a4 100644
--- a/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.next.stderr
+++ b/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.next.stderr
@@ -1,8 +1,14 @@
 error[E0282]: type annotations needed
-  --> $DIR/method_resolution_trait_method_from_opaque.rs:28:9
+  --> $DIR/method_resolution_trait_method_from_opaque.rs:28:18
    |
 LL |         self.bar.next().unwrap();
-   |         ^^^^^^^^ cannot infer type
+   |                  ^^^^
+   |
+help: try using a fully qualified path to specify the expected types
+   |
+LL -         self.bar.next().unwrap();
+LL +         <_ as Iterator>::next(&mut self.bar).unwrap();
+   |
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/type-inference/regression-issue-81317.stderr b/tests/ui/type-inference/regression-issue-81317.stderr
index fcd3fca06e1..a070b50e311 100644
--- a/tests/ui/type-inference/regression-issue-81317.stderr
+++ b/tests/ui/type-inference/regression-issue-81317.stderr
@@ -5,7 +5,7 @@ LL |     let iv = S ^ index.into();
    |         ^^
 LL |
 LL |     &iv.to_bytes_be();
-   |      -- type must be known at this point
+   |         ----------- type must be known at this point
    |
 help: consider giving `iv` an explicit type
    |
diff --git a/tests/ui/typeck/issue-13853.rs b/tests/ui/typeck/issue-13853.rs
index ac9886d2e72..ed44d506261 100644
--- a/tests/ui/typeck/issue-13853.rs
+++ b/tests/ui/typeck/issue-13853.rs
@@ -25,7 +25,7 @@ impl Node for Stuff {
 
 fn iterate<N: Node, G: Graph<N>>(graph: &G) {
     for node in graph.iter() { //~ ERROR no method named `iter` found
-        node.zomg();
+        node.zomg(); //~ ERROR type annotations needed
     }
 }
 
diff --git a/tests/ui/typeck/issue-13853.stderr b/tests/ui/typeck/issue-13853.stderr
index 45363c87d29..9b8698d6ed2 100644
--- a/tests/ui/typeck/issue-13853.stderr
+++ b/tests/ui/typeck/issue-13853.stderr
@@ -17,6 +17,12 @@ error[E0599]: no method named `iter` found for reference `&G` in the current sco
 LL |     for node in graph.iter() {
    |                       ^^^^ method not found in `&G`
 
+error[E0282]: type annotations needed
+  --> $DIR/issue-13853.rs:28:14
+   |
+LL |         node.zomg();
+   |              ^^^^ cannot infer type
+
 error[E0308]: mismatched types
   --> $DIR/issue-13853.rs:37:13
    |
@@ -37,7 +43,7 @@ help: consider borrowing here
 LL |     iterate(&graph);
    |             +
 
-error: aborting due to 3 previous errors
+error: aborting due to 4 previous errors
 
-Some errors have detailed explanations: E0308, E0599.
-For more information about an error, try `rustc --explain E0308`.
+Some errors have detailed explanations: E0282, E0308, E0599.
+For more information about an error, try `rustc --explain E0282`.