Fix diagnostics being cancelled even with unused arguments
This commit is contained in:
parent
dc75c99226
commit
4a7a98cf30
@ -8,7 +8,9 @@
|
|||||||
FormatDebugHex, FormatOptions, FormatPlaceholder, FormatSign, FormatTrait,
|
FormatDebugHex, FormatOptions, FormatPlaceholder, FormatSign, FormatTrait,
|
||||||
};
|
};
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_errors::{Applicability, MultiSpan, PResult, SingleLabelManySpans};
|
use rustc_errors::{
|
||||||
|
Applicability, DiagnosticBuilder, ErrorGuaranteed, MultiSpan, PResult, SingleLabelManySpans,
|
||||||
|
};
|
||||||
use rustc_expand::base::{self, *};
|
use rustc_expand::base::{self, *};
|
||||||
use rustc_parse_format as parse;
|
use rustc_parse_format as parse;
|
||||||
use rustc_span::symbol::{Ident, Symbol};
|
use rustc_span::symbol::{Ident, Symbol};
|
||||||
@ -616,9 +618,13 @@ fn report_missing_placeholders(
|
|||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
if !placeholders.is_empty() {
|
if !placeholders.is_empty() {
|
||||||
report_redundant_format_arguments(ecx, fmt_span, &args, used, placeholders);
|
if let Some(mut new_diag) =
|
||||||
diag.cancel();
|
report_redundant_format_arguments(ecx, fmt_span, &args, used, placeholders)
|
||||||
return;
|
{
|
||||||
|
diag.cancel();
|
||||||
|
new_diag.emit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used to ensure we only report translations for *one* kind of foreign format.
|
// Used to ensure we only report translations for *one* kind of foreign format.
|
||||||
@ -710,13 +716,13 @@ macro_rules! check_foreign {
|
|||||||
|
|
||||||
/// This function detects and reports unused format!() arguments that are
|
/// This function detects and reports unused format!() arguments that are
|
||||||
/// redundant due to implicit captures (e.g. `format!("{x}", x)`).
|
/// redundant due to implicit captures (e.g. `format!("{x}", x)`).
|
||||||
fn report_redundant_format_arguments(
|
fn report_redundant_format_arguments<'a>(
|
||||||
ecx: &mut ExtCtxt<'_>,
|
ecx: &mut ExtCtxt<'a>,
|
||||||
fmt_span: Span,
|
fmt_span: Span,
|
||||||
args: &FormatArguments,
|
args: &FormatArguments,
|
||||||
used: &[bool],
|
used: &[bool],
|
||||||
placeholders: Vec<(Span, &str)>,
|
placeholders: Vec<(Span, &str)>,
|
||||||
) {
|
) -> Option<DiagnosticBuilder<'a, ErrorGuaranteed>> {
|
||||||
let mut fmt_arg_indices = vec![];
|
let mut fmt_arg_indices = vec![];
|
||||||
let mut args_spans = vec![];
|
let mut args_spans = vec![];
|
||||||
let mut fmt_spans = vec![];
|
let mut fmt_spans = vec![];
|
||||||
@ -762,15 +768,15 @@ fn report_redundant_format_arguments(
|
|||||||
suggestion_spans.push(span);
|
suggestion_spans.push(span);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut diag = ecx.create_err(errors::FormatRedundantArgs {
|
return Some(ecx.create_err(errors::FormatRedundantArgs {
|
||||||
fmt_span,
|
fmt_span,
|
||||||
note: multispan,
|
note: multispan,
|
||||||
n: args_spans.len(),
|
n: args_spans.len(),
|
||||||
sugg: errors::FormatRedundantArgsSugg { spans: suggestion_spans },
|
sugg: errors::FormatRedundantArgsSugg { spans: suggestion_spans },
|
||||||
});
|
}));
|
||||||
|
|
||||||
diag.emit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle invalid references to positional arguments. Output different
|
/// Handle invalid references to positional arguments. Output different
|
||||||
|
Loading…
Reference in New Issue
Block a user