Highlight redundant arguments instead of the whole format string
This commit is contained in:
parent
fcdd5c0b2d
commit
905bace904
@ -650,7 +650,7 @@ pub(crate) struct FormatPositionalMismatch {
|
||||
#[diag(builtin_macros_format_redundant_args)]
|
||||
pub(crate) struct FormatRedundantArgs {
|
||||
#[primary_span]
|
||||
pub(crate) fmt_span: Span,
|
||||
pub(crate) span: MultiSpan,
|
||||
pub(crate) n: usize,
|
||||
|
||||
#[note]
|
||||
|
@ -619,7 +619,7 @@ fn report_missing_placeholders(
|
||||
|
||||
if !placeholders.is_empty() {
|
||||
if let Some(mut new_diag) =
|
||||
report_redundant_format_arguments(ecx, fmt_span, &args, used, placeholders)
|
||||
report_redundant_format_arguments(ecx, &args, used, placeholders)
|
||||
{
|
||||
diag.cancel();
|
||||
new_diag.emit();
|
||||
@ -718,7 +718,6 @@ macro_rules! check_foreign {
|
||||
/// redundant due to implicit captures (e.g. `format!("{x}", x)`).
|
||||
fn report_redundant_format_arguments<'a>(
|
||||
ecx: &mut ExtCtxt<'a>,
|
||||
fmt_span: Span,
|
||||
args: &FormatArguments,
|
||||
used: &[bool],
|
||||
placeholders: Vec<(Span, &str)>,
|
||||
@ -769,9 +768,9 @@ fn report_redundant_format_arguments<'a>(
|
||||
}
|
||||
|
||||
return Some(ecx.create_err(errors::FormatRedundantArgs {
|
||||
fmt_span,
|
||||
note: multispan,
|
||||
n: args_spans.len(),
|
||||
span: MultiSpan::from(args_spans),
|
||||
note: multispan,
|
||||
sugg: errors::FormatRedundantArgsSugg { spans: suggestion_spans },
|
||||
}));
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
fn main() {
|
||||
let x = 0;
|
||||
let y = 0;
|
||||
|
||||
println!("{x}", x);
|
||||
//~^ ERROR: redundant argument
|
||||
|
||||
@ -9,11 +11,9 @@ fn main() {
|
||||
println!("{} {x}", x, x);
|
||||
//~^ ERROR: redundant argument
|
||||
|
||||
let y = 0;
|
||||
println!("{x} {y}", x, y);
|
||||
//~^ ERROR: redundant argument
|
||||
//~^ ERROR: redundant arguments
|
||||
|
||||
let y = 0;
|
||||
println!("{} {} {x} {y} {}", x, x, x, y, y);
|
||||
//~^ ERROR: redundant argument
|
||||
//~^ ERROR: redundant arguments
|
||||
}
|
||||
|
@ -1,47 +1,47 @@
|
||||
error: redundant argument
|
||||
--> $DIR/issue-105225.rs:3:14
|
||||
--> $DIR/issue-105225.rs:5:21
|
||||
|
|
||||
LL | println!("{x}", x);
|
||||
| ^^^^^ - help: this can be removed
|
||||
| ^ help: this can be removed
|
||||
|
|
||||
note: the formatting specifier is referencing the binding already
|
||||
--> $DIR/issue-105225.rs:3:16
|
||||
--> $DIR/issue-105225.rs:5:16
|
||||
|
|
||||
LL | println!("{x}", x);
|
||||
| ^
|
||||
|
||||
error: redundant argument
|
||||
--> $DIR/issue-105225.rs:6:14
|
||||
--> $DIR/issue-105225.rs:8:27
|
||||
|
|
||||
LL | println!("{x} {}", x, x);
|
||||
| ^^^^^^^^ - help: this can be removed
|
||||
| ^ help: this can be removed
|
||||
|
|
||||
note: the formatting specifier is referencing the binding already
|
||||
--> $DIR/issue-105225.rs:6:16
|
||||
--> $DIR/issue-105225.rs:8:16
|
||||
|
|
||||
LL | println!("{x} {}", x, x);
|
||||
| ^
|
||||
|
||||
error: redundant argument
|
||||
--> $DIR/issue-105225.rs:9:14
|
||||
--> $DIR/issue-105225.rs:11:27
|
||||
|
|
||||
LL | println!("{} {x}", x, x);
|
||||
| ^^^^^^^^ - help: this can be removed
|
||||
| ^ help: this can be removed
|
||||
|
|
||||
note: the formatting specifier is referencing the binding already
|
||||
--> $DIR/issue-105225.rs:9:19
|
||||
--> $DIR/issue-105225.rs:11:19
|
||||
|
|
||||
LL | println!("{} {x}", x, x);
|
||||
| ^
|
||||
|
||||
error: redundant arguments
|
||||
--> $DIR/issue-105225.rs:13:14
|
||||
--> $DIR/issue-105225.rs:14:25
|
||||
|
|
||||
LL | println!("{x} {y}", x, y);
|
||||
| ^^^^^^^^^
|
||||
| ^ ^
|
||||
|
|
||||
note: the formatting specifiers are referencing the bindings already
|
||||
--> $DIR/issue-105225.rs:13:16
|
||||
--> $DIR/issue-105225.rs:14:16
|
||||
|
|
||||
LL | println!("{x} {y}", x, y);
|
||||
| ^ ^
|
||||
@ -52,10 +52,10 @@ LL + println!("{x} {y}", );
|
||||
|
|
||||
|
||||
error: redundant arguments
|
||||
--> $DIR/issue-105225.rs:17:14
|
||||
--> $DIR/issue-105225.rs:17:43
|
||||
|
|
||||
LL | println!("{} {} {x} {y} {}", x, x, x, y, y);
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
| ^ ^
|
||||
|
|
||||
note: the formatting specifiers are referencing the bindings already
|
||||
--> $DIR/issue-105225.rs:17:26
|
||||
|
Loading…
Reference in New Issue
Block a user