@@ -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) ;
@@ -3973,7 +3983,15 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
39733983 ) = expr. kind
39743984 {
39753985 if Some ( * span) != err. span . primary_span ( ) {
3976- err. span_label ( * span, "required by a bound introduced by this call" ) ;
3986+ let msg = if span. is_desugaring ( DesugaringKind :: FormatLiteral { source : true } )
3987+ {
3988+ "required by this formatting parameter"
3989+ } else if span. is_desugaring ( DesugaringKind :: FormatLiteral { source : false } ) {
3990+ "required by a formatting parameter in this expression"
3991+ } else {
3992+ "required by a bound introduced by this call"
3993+ } ;
3994+ err. span_label ( * span, msg) ;
39773995 }
39783996 }
39793997
0 commit comments