@@ -429,14 +429,18 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
429
429
return ;
430
430
}
431
431
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
434
433
. get_parent_trait_ref ( obligation. cause . code ( ) )
435
434
. map ( |( t, s) | {
435
+ let ( t, file) = self . tcx . short_ty_string ( t) ;
436
436
(
437
437
format ! ( " in `{t}`" ) ,
438
438
format ! ( "within `{t}`, " ) ,
439
439
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
+ ) ) )
440
444
)
441
445
} )
442
446
. unwrap_or_default ( ) ;
@@ -544,6 +548,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
544
548
err. emit ( ) ;
545
549
return ;
546
550
}
551
+
552
+ file_note. map ( |note| err. note ( note) ) ;
547
553
if let Some ( s) = label {
548
554
// If it has a custom `#[rustc_on_unimplemented]`
549
555
// error message, let's display it as the label!
@@ -1077,7 +1083,7 @@ pub(super) trait InferCtxtPrivExt<'tcx> {
1077
1083
fn get_parent_trait_ref (
1078
1084
& self ,
1079
1085
code : & ObligationCauseCode < ' tcx > ,
1080
- ) -> Option < ( String , Option < Span > ) > ;
1086
+ ) -> Option < ( Ty < ' tcx > , Option < Span > ) > ;
1081
1087
1082
1088
/// If the `Self` type of the unsatisfied trait `trait_ref` implements a trait
1083
1089
/// with the same path as `trait_ref`, a help message about
@@ -1927,7 +1933,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1927
1933
fn get_parent_trait_ref (
1928
1934
& self ,
1929
1935
code : & ObligationCauseCode < ' tcx > ,
1930
- ) -> Option < ( String , Option < Span > ) > {
1936
+ ) -> Option < ( Ty < ' tcx > , Option < Span > ) > {
1931
1937
match code {
1932
1938
ObligationCauseCode :: BuiltinDerivedObligation ( data) => {
1933
1939
let parent_trait_ref = self . resolve_vars_if_possible ( data. parent_trait_pred ) ;
@@ -1937,7 +1943,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1937
1943
let ty = parent_trait_ref. skip_binder ( ) . self_ty ( ) ;
1938
1944
let span = TyCategory :: from_ty ( self . tcx , ty)
1939
1945
. map ( |( _, def_id) | self . tcx . def_span ( def_id) ) ;
1940
- Some ( ( ty. to_string ( ) , span) )
1946
+ Some ( ( ty, span) )
1941
1947
}
1942
1948
}
1943
1949
}
0 commit comments