Skip to content

Commit 991bf75

Browse files
committed
make E0277 use short paths
add note change wording short_ty_string on t
1 parent 193e8a1 commit 991bf75

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

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

+11-5
Original file line numberDiff line numberDiff line change
@@ -429,14 +429,18 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
429429
return;
430430
}
431431
let trait_ref = trait_predicate.to_poly_trait_ref();
432-
433-
let (post_message, pre_message, type_def) = self
432+
let (post_message, pre_message, type_def, file_note) = self
434433
.get_parent_trait_ref(obligation.cause.code())
435434
.map(|(t, s)| {
435+
let (t, file) = self.tcx.short_ty_string(t);
436436
(
437437
format!(" in `{t}`"),
438438
format!("within `{t}`, "),
439439
s.map(|s| (format!("within this `{t}`"), s)),
440+
file.and_then(|file| Some(format!(
441+
"the full trait has been written to '{}'",
442+
file.display(),
443+
)))
440444
)
441445
})
442446
.unwrap_or_default();
@@ -544,6 +548,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
544548
err.emit();
545549
return;
546550
}
551+
552+
file_note.map(|note| err.note(note));
547553
if let Some(s) = label {
548554
// If it has a custom `#[rustc_on_unimplemented]`
549555
// error message, let's display it as the label!
@@ -1077,7 +1083,7 @@ pub(super) trait InferCtxtPrivExt<'tcx> {
10771083
fn get_parent_trait_ref(
10781084
&self,
10791085
code: &ObligationCauseCode<'tcx>,
1080-
) -> Option<(String, Option<Span>)>;
1086+
) -> Option<(Ty<'tcx>, Option<Span>)>;
10811087

10821088
/// If the `Self` type of the unsatisfied trait `trait_ref` implements a trait
10831089
/// with the same path as `trait_ref`, a help message about
@@ -1927,7 +1933,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
19271933
fn get_parent_trait_ref(
19281934
&self,
19291935
code: &ObligationCauseCode<'tcx>,
1930-
) -> Option<(String, Option<Span>)> {
1936+
) -> Option<(Ty<'tcx>, Option<Span>)> {
19311937
match code {
19321938
ObligationCauseCode::BuiltinDerivedObligation(data) => {
19331939
let parent_trait_ref = self.resolve_vars_if_possible(data.parent_trait_pred);
@@ -1937,7 +1943,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
19371943
let ty = parent_trait_ref.skip_binder().self_ty();
19381944
let span = TyCategory::from_ty(self.tcx, ty)
19391945
.map(|(_, def_id)| self.tcx.def_span(def_id));
1940-
Some((ty.to_string(), span))
1946+
Some((ty, span))
19411947
}
19421948
}
19431949
}

0 commit comments

Comments
 (0)