@@ -426,14 +426,18 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
426
426
return ;
427
427
}
428
428
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
431
430
. get_parent_trait_ref ( obligation. cause . code ( ) )
432
431
. map ( |( t, s) | {
432
+ let ( t, file) = self . tcx . short_ty_string ( t) ;
433
433
(
434
434
format ! ( " in `{t}`" ) ,
435
435
format ! ( "within `{t}`, " ) ,
436
436
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
+ ) )
437
441
)
438
442
} )
439
443
. unwrap_or_default ( ) ;
@@ -541,6 +545,8 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
541
545
err. emit ( ) ;
542
546
return ;
543
547
}
548
+
549
+ file_note. map ( |note| err. note ( note) ) ;
544
550
if let Some ( s) = label {
545
551
// If it has a custom `#[rustc_on_unimplemented]`
546
552
// error message, let's display it as the label!
@@ -1094,7 +1100,7 @@ pub(super) trait InferCtxtPrivExt<'tcx> {
1094
1100
fn get_parent_trait_ref (
1095
1101
& self ,
1096
1102
code : & ObligationCauseCode < ' tcx > ,
1097
- ) -> Option < ( String , Option < Span > ) > ;
1103
+ ) -> Option < ( Ty < ' tcx > , Option < Span > ) > ;
1098
1104
1099
1105
/// If the `Self` type of the unsatisfied trait `trait_ref` implements a trait
1100
1106
/// with the same path as `trait_ref`, a help message about
@@ -1943,7 +1949,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1943
1949
fn get_parent_trait_ref (
1944
1950
& self ,
1945
1951
code : & ObligationCauseCode < ' tcx > ,
1946
- ) -> Option < ( String , Option < Span > ) > {
1952
+ ) -> Option < ( Ty < ' tcx > , Option < Span > ) > {
1947
1953
match code {
1948
1954
ObligationCauseCode :: BuiltinDerivedObligation ( data) => {
1949
1955
let parent_trait_ref = self . resolve_vars_if_possible ( data. parent_trait_pred ) ;
@@ -1953,7 +1959,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1953
1959
let ty = parent_trait_ref. skip_binder ( ) . self_ty ( ) ;
1954
1960
let span = TyCategory :: from_ty ( self . tcx , ty)
1955
1961
. map ( |( _, def_id) | self . tcx . def_span ( def_id) ) ;
1956
- Some ( ( ty. to_string ( ) , span) )
1962
+ Some ( ( ty, span) )
1957
1963
}
1958
1964
}
1959
1965
}
0 commit comments