@@ -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 } ;
@@ -607,9 +609,13 @@ fn report_missing_placeholders(
607
609
. collect :: < Vec < _ > > ( ) ;
608
610
609
611
if !placeholders. is_empty ( ) {
610
- report_redundant_format_arguments ( ecx, fmt_span, & args, used, placeholders) ;
611
- diag. cancel ( ) ;
612
- return ;
612
+ if let Some ( mut new_diag) =
613
+ report_redundant_format_arguments ( ecx, fmt_span, & args, used, placeholders)
614
+ {
615
+ diag. cancel ( ) ;
616
+ new_diag. emit ( ) ;
617
+ return ;
618
+ }
613
619
}
614
620
615
621
// Used to ensure we only report translations for *one* kind of foreign format.
@@ -701,13 +707,13 @@ fn report_missing_placeholders(
701
707
702
708
/// This function detects and reports unused format!() arguments that are
703
709
/// redundant due to implicit captures (e.g. `format!("{x}", x)`).
704
- fn report_redundant_format_arguments (
705
- ecx : & mut ExtCtxt < ' _ > ,
710
+ fn report_redundant_format_arguments < ' a > (
711
+ ecx : & mut ExtCtxt < ' a > ,
706
712
fmt_span : Span ,
707
713
args : & FormatArguments ,
708
714
used : & [ bool ] ,
709
715
placeholders : Vec < ( Span , & str ) > ,
710
- ) {
716
+ ) -> Option < DiagnosticBuilder < ' a , ErrorGuaranteed > > {
711
717
let mut fmt_arg_indices = vec ! [ ] ;
712
718
let mut args_spans = vec ! [ ] ;
713
719
let mut fmt_spans = vec ! [ ] ;
@@ -753,15 +759,15 @@ fn report_redundant_format_arguments(
753
759
suggestion_spans. push ( span) ;
754
760
}
755
761
756
- let mut diag = ecx. create_err ( errors:: FormatRedundantArgs {
762
+ return Some ( ecx. create_err ( errors:: FormatRedundantArgs {
757
763
fmt_span,
758
764
note : multispan,
759
765
n : args_spans. len ( ) ,
760
766
sugg : errors:: FormatRedundantArgsSugg { spans : suggestion_spans } ,
761
- } ) ;
762
-
763
- diag. emit ( ) ;
767
+ } ) ) ;
764
768
}
769
+
770
+ None
765
771
}
766
772
767
773
/// Handle invalid references to positional arguments. Output different
0 commit comments