@@ -2872,13 +2872,23 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
28722872 _ => ( ) ,
28732873 }
28742874 }
2875- let descr = format ! ( "required by {a} bound in `{item_name}`" ) ;
2876- if span . is_visible ( sm ) {
2877- let msg = format ! ( "required by { this} in `{short_item_name}`" ) ;
2878- multispan . push_span_label ( span , msg ) ;
2879- err . span_note ( multispan , descr ) ;
2875+
2876+ // If this is from a format string literal desugaring,
2877+ // we've already said "required by this formatting parameter"
2878+ let is_in_fmt_lit = if let Some ( s ) = err . span . primary_span ( ) {
2879+ matches ! ( s . desugaring_kind ( ) , Some ( DesugaringKind :: FormatLiteral { .. } ) )
28802880 } else {
2881- err. span_note ( tcx. def_span ( item_def_id) , descr) ;
2881+ false
2882+ } ;
2883+ if !is_in_fmt_lit {
2884+ let descr = format ! ( "required by {a} bound in `{item_name}`" ) ;
2885+ if span. is_visible ( sm) {
2886+ let msg = format ! ( "required by {this} in `{short_item_name}`" ) ;
2887+ multispan. push_span_label ( span, msg) ;
2888+ err. span_note ( multispan, descr) ;
2889+ } else {
2890+ err. span_note ( tcx. def_span ( item_def_id) , descr) ;
2891+ }
28822892 }
28832893 if let Some ( note) = note {
28842894 err. note ( note) ;
@@ -3977,7 +3987,15 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
39773987 ) = expr. kind
39783988 {
39793989 if Some ( * span) != err. span . primary_span ( ) {
3980- err. span_label ( * span, "required by a bound introduced by this call" ) ;
3990+ let msg = if span. is_desugaring ( DesugaringKind :: FormatLiteral { source : true } )
3991+ {
3992+ "required by this formatting parameter"
3993+ } else if span. is_desugaring ( DesugaringKind :: FormatLiteral { source : false } ) {
3994+ "required by a formatting parameter in this expression"
3995+ } else {
3996+ "required by a bound introduced by this call"
3997+ } ;
3998+ err. span_label ( * span, msg) ;
39813999 }
39824000 }
39834001
0 commit comments