@@ -426,14 +426,18 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
426426 return ;
427427 }
428428 let trait_ref = trait_predicate. to_poly_trait_ref ( ) ;
429-
430- let ( post_message, pre_message, type_def) = self
429+ let ( post_message, pre_message, type_def, file_note) = self
431430 . get_parent_trait_ref ( obligation. cause . code ( ) )
432431 . map ( |( t, s) | {
432+ let ( t, file) = self . tcx . short_ty_string ( t) ;
433433 (
434434 format ! ( " in `{t}`" ) ,
435435 format ! ( "within `{t}`, " ) ,
436436 s. map ( |s| ( format ! ( "within this `{t}`" ) , s) ) ,
437+ file. map ( |file| format ! (
438+ "the full trait has been written to '{}'" ,
439+ file. display( ) ,
440+ ) )
437441 )
438442 } )
439443 . unwrap_or_default ( ) ;
@@ -541,6 +545,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
541545 err. emit ( ) ;
542546 return ;
543547 }
548+
549+ file_note. map ( |note| err. note ( note) ) ;
544550 if let Some ( s) = label {
545551 // If it has a custom `#[rustc_on_unimplemented]`
546552 // error message, let's display it as the label!
@@ -1094,7 +1100,7 @@ pub(super) trait InferCtxtPrivExt<'tcx> {
10941100 fn get_parent_trait_ref (
10951101 & self ,
10961102 code : & ObligationCauseCode < ' tcx > ,
1097- ) -> Option < ( String , Option < Span > ) > ;
1103+ ) -> Option < ( Ty < ' tcx > , Option < Span > ) > ;
10981104
10991105 /// If the `Self` type of the unsatisfied trait `trait_ref` implements a trait
11001106 /// with the same path as `trait_ref`, a help message about
@@ -1943,7 +1949,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
19431949 fn get_parent_trait_ref (
19441950 & self ,
19451951 code : & ObligationCauseCode < ' tcx > ,
1946- ) -> Option < ( String , Option < Span > ) > {
1952+ ) -> Option < ( Ty < ' tcx > , Option < Span > ) > {
19471953 match code {
19481954 ObligationCauseCode :: BuiltinDerivedObligation ( data) => {
19491955 let parent_trait_ref = self . resolve_vars_if_possible ( data. parent_trait_pred ) ;
@@ -1953,7 +1959,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
19531959 let ty = parent_trait_ref. skip_binder ( ) . self_ty ( ) ;
19541960 let span = TyCategory :: from_ty ( self . tcx , ty)
19551961 . map ( |( _, def_id) | self . tcx . def_span ( def_id) ) ;
1956- Some ( ( ty. to_string ( ) , span) )
1962+ Some ( ( ty, span) )
19571963 }
19581964 }
19591965 }
0 commit comments