diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs index 28f335f91597..2b6f983d35d4 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs @@ -419,7 +419,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { error_code: TypeAnnotationNeeded, should_label_span: bool, param_env: ty::ParamEnv<'tcx>, - predicate: Option>, + originating_projection: Option>, ) -> Diag<'a> { let arg = self.resolve_vars_if_possible(arg); let arg_data = self.extract_inference_diagnostics_data(arg, None); @@ -468,7 +468,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { && let Some(ty) = typeck_results.node_type_opt(rcvr.hir_id) { paths = self.get_fully_qualified_path_suggestions_from_impls( - ty, def_id, true, param_env, predicate, + ty, + def_id, + true, + param_env, + originating_projection, ); } @@ -601,7 +605,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { def_id, false, param_env, - predicate, + originating_projection, ); if paths.len() > 20 || paths.is_empty() { // This will show the fallback impl, so the expression will have type @@ -680,7 +684,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { def_id: DefId, target_type: bool, param_env: ty::ParamEnv<'tcx>, - predicate: Option>, + originating_projection: Option>, ) -> Vec { let tcx = self.infcx.tcx; let mut paths = vec![]; @@ -703,8 +707,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let filter = if let Some(ty::ProjectionPredicate { projection_term: ty::AliasTerm { def_id, .. }, term, - }) = - predicate.and_then(|p| p.as_projection_clause()).map(|p| p.skip_binder()) + }) = originating_projection && let ty::TermKind::Ty(assoc_ty) = term.unpack() && tcx.item_name(def_id) == sym::Output && [ diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs index 975c6a3cd797..0f4ee00d7e7b 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs @@ -535,7 +535,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { TypeAnnotationNeeded::E0284, true, obligation.param_env, - Some(predicate), + Some(data), ) .with_note(format!("cannot satisfy `{predicate}`")) } else {