Skip to content

Commit 4ff9d72

Browse files
committed
Only show "same type from differnt version" note when relevant
1 parent 6abfa79 commit 4ff9d72

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

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

+15-7
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
17031703
{
17041704
span.push_span_label(sp, label);
17051705
}
1706+
let mut points_at_type = false;
17061707
if let Some(found_type) = found_type {
17071708
span.push_span_label(
17081709
self.tcx.def_span(found_type),
@@ -1725,6 +1726,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
17251726
candidate_span,
17261727
"this type implements the required trait",
17271728
);
1729+
points_at_type = true;
17281730
}
17291731
}
17301732
}
@@ -1739,14 +1741,20 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
17391741
StringPart::normal("` in the dependency graph\n".to_string()),
17401742
],
17411743
);
1742-
err.highlighted_note(vec![
1743-
StringPart::normal(
1744-
"two types coming from two different versions of the same crate are \
1744+
if points_at_type {
1745+
// We only clarify that the same type from different crate versions are not the
1746+
// same when we *find* the same type coming from different crate versions, otherwise
1747+
// it could be that it was a type provided by a different crate than the one that
1748+
// provides the trait, and mentioning this adds verbosity without clarification.
1749+
err.highlighted_note(vec![
1750+
StringPart::normal(
1751+
"two types coming from two different versions of the same crate are \
17451752
different types "
1746-
.to_string(),
1747-
),
1748-
StringPart::highlighted("even if they look the same".to_string()),
1749-
]);
1753+
.to_string(),
1754+
),
1755+
StringPart::highlighted("even if they look the same".to_string()),
1756+
]);
1757+
}
17501758
err.highlighted_help(vec![
17511759
StringPart::normal("you can use `".to_string()),
17521760
StringPart::highlighted("cargo tree".to_string()),

0 commit comments

Comments
 (0)