@@ -2872,13 +2872,23 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
2872
2872
_ => ( ) ,
2873
2873
}
2874
2874
}
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 { .. } ) )
2880
2880
} 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
+ }
2882
2892
}
2883
2893
if let Some ( note) = note {
2884
2894
err. note ( note) ;
@@ -3977,7 +3987,15 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
3977
3987
) = expr. kind
3978
3988
{
3979
3989
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) ;
3981
3999
}
3982
4000
}
3983
4001
0 commit comments