From 81b0de4356a579ac9ca46daac711ce163b8cdf5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 20 Aug 2024 18:59:00 +0000 Subject: [PATCH] Only show "same type from differnt version" note when relevant --- .../traits/fulfillment_errors.rs | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index cb074261cde..1109b11d2a7 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -1750,6 +1750,7 @@ pub(super) fn report_similar_impl_candidates( { span.push_span_label(sp, label); } + let mut points_at_type = false; if let Some(found_type) = found_type { span.push_span_label( self.tcx.def_span(found_type), @@ -1772,6 +1773,7 @@ pub(super) fn report_similar_impl_candidates( candidate_span, "this type implements the required trait", ); + points_at_type = true; } } } @@ -1783,14 +1785,20 @@ pub(super) fn report_similar_impl_candidates( StringPart::highlighted(format!("{crate_name}")), StringPart::normal("` in the dependency graph\n".to_string()), ]); - err.highlighted_note(vec![ - StringPart::normal( - "two types coming from two different versions of the same crate are \ + if points_at_type { + // We only clarify that the same type from different crate versions are not the + // same when we *find* the same type coming from different crate versions, otherwise + // it could be that it was a type provided by a different crate than the one that + // provides the trait, and mentioning this adds verbosity without clarification. + err.highlighted_note(vec![ + StringPart::normal( + "two types coming from two different versions of the same crate are \ different types " - .to_string(), - ), - StringPart::highlighted("even if they look the same".to_string()), - ]); + .to_string(), + ), + StringPart::highlighted("even if they look the same".to_string()), + ]); + } err.highlighted_help(vec![ StringPart::normal("you can use `".to_string()), StringPart::highlighted("cargo tree".to_string()),