@@ -8,7 +8,9 @@ use rustc_ast::{
8
8
FormatDebugHex , FormatOptions , FormatPlaceholder , FormatSign , FormatTrait ,
9
9
} ;
10
10
use rustc_data_structures:: fx:: FxHashSet ;
11
- use rustc_errors:: { Applicability , MultiSpan , PResult , SingleLabelManySpans } ;
11
+ use rustc_errors:: {
12
+ Applicability , DiagnosticBuilder , ErrorGuaranteed , MultiSpan , PResult , SingleLabelManySpans ,
13
+ } ;
12
14
use rustc_expand:: base:: { self , * } ;
13
15
use rustc_parse_format as parse;
14
16
use rustc_span:: symbol:: { Ident , Symbol } ;
@@ -616,9 +618,13 @@ fn report_missing_placeholders(
616
618
. collect :: < Vec < _ > > ( ) ;
617
619
618
620
if !placeholders. is_empty ( ) {
619
- report_redundant_format_arguments ( ecx, fmt_span, & args, used, placeholders) ;
620
- diag. cancel ( ) ;
621
- return ;
621
+ if let Some ( mut new_diag) =
622
+ report_redundant_format_arguments ( ecx, fmt_span, & args, used, placeholders)
623
+ {
624
+ diag. cancel ( ) ;
625
+ new_diag. emit ( ) ;
626
+ return ;
627
+ }
622
628
}
623
629
624
630
// Used to ensure we only report translations for *one* kind of foreign format.
@@ -710,13 +716,13 @@ fn report_missing_placeholders(
710
716
711
717
/// This function detects and reports unused format!() arguments that are
712
718
/// redundant due to implicit captures (e.g. `format!("{x}", x)`).
713
- fn report_redundant_format_arguments (
714
- ecx : & mut ExtCtxt < ' _ > ,
719
+ fn report_redundant_format_arguments < ' a > (
720
+ ecx : & mut ExtCtxt < ' a > ,
715
721
fmt_span : Span ,
716
722
args : & FormatArguments ,
717
723
used : & [ bool ] ,
718
724
placeholders : Vec < ( Span , & str ) > ,
719
- ) {
725
+ ) -> Option < DiagnosticBuilder < ' a , ErrorGuaranteed > > {
720
726
let mut fmt_arg_indices = vec ! [ ] ;
721
727
let mut args_spans = vec ! [ ] ;
722
728
let mut fmt_spans = vec ! [ ] ;
@@ -762,15 +768,15 @@ fn report_redundant_format_arguments(
762
768
suggestion_spans. push ( span) ;
763
769
}
764
770
765
- let mut diag = ecx. create_err ( errors:: FormatRedundantArgs {
771
+ return Some ( ecx. create_err ( errors:: FormatRedundantArgs {
766
772
fmt_span,
767
773
note : multispan,
768
774
n : args_spans. len ( ) ,
769
775
sugg : errors:: FormatRedundantArgsSugg { spans : suggestion_spans } ,
770
- } ) ;
771
-
772
- diag. emit ( ) ;
776
+ } ) ) ;
773
777
}
778
+
779
+ None
774
780
}
775
781
776
782
/// Handle invalid references to positional arguments. Output different
0 commit comments