Only give autofix suggestion when no named args are present
This commit is contained in:
parent
38b0182832
commit
c8ee7db6ea
@ -657,7 +657,7 @@ pub(crate) struct FormatRedundantArgs {
|
|||||||
pub(crate) note: MultiSpan,
|
pub(crate) note: MultiSpan,
|
||||||
|
|
||||||
#[subdiagnostic]
|
#[subdiagnostic]
|
||||||
pub(crate) sugg: FormatRedundantArgsSugg,
|
pub(crate) sugg: Option<FormatRedundantArgsSugg>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
|
@ -767,11 +767,17 @@ fn report_redundant_format_arguments<'a>(
|
|||||||
suggestion_spans.push(span);
|
suggestion_spans.push(span);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let sugg = if args.named_args().len() == 0 {
|
||||||
|
Some(errors::FormatRedundantArgsSugg { spans: suggestion_spans })
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
return Some(ecx.create_err(errors::FormatRedundantArgs {
|
return Some(ecx.create_err(errors::FormatRedundantArgs {
|
||||||
n: args_spans.len(),
|
n: args_spans.len(),
|
||||||
span: MultiSpan::from(args_spans),
|
span: MultiSpan::from(args_spans),
|
||||||
note: multispan,
|
note: multispan,
|
||||||
sugg: errors::FormatRedundantArgsSugg { spans: suggestion_spans },
|
sugg,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
tests/ui/did_you_mean/issue-105225-named-args.rs
Normal file
10
tests/ui/did_you_mean/issue-105225-named-args.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
fn main() {
|
||||||
|
let x = "x";
|
||||||
|
let y = "y";
|
||||||
|
|
||||||
|
println!("{x}", x, x = y);
|
||||||
|
//~^ ERROR: redundant argument
|
||||||
|
|
||||||
|
println!("{x}", x = y, x = y);
|
||||||
|
//~^ ERROR: duplicate argument named `x`
|
||||||
|
}
|
22
tests/ui/did_you_mean/issue-105225-named-args.stderr
Normal file
22
tests/ui/did_you_mean/issue-105225-named-args.stderr
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
error: redundant argument
|
||||||
|
--> $DIR/issue-105225-named-args.rs:5:21
|
||||||
|
|
|
||||||
|
LL | println!("{x}", x, x = y);
|
||||||
|
| ^
|
||||||
|
|
|
||||||
|
note: the formatting specifier is referencing the binding already
|
||||||
|
--> $DIR/issue-105225-named-args.rs:5:16
|
||||||
|
|
|
||||||
|
LL | println!("{x}", x, x = y);
|
||||||
|
| ^
|
||||||
|
|
||||||
|
error: duplicate argument named `x`
|
||||||
|
--> $DIR/issue-105225-named-args.rs:8:28
|
||||||
|
|
|
||||||
|
LL | println!("{x}", x = y, x = y);
|
||||||
|
| - ^ duplicate argument
|
||||||
|
| |
|
||||||
|
| previously here
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
@ -1,8 +1,8 @@
|
|||||||
// run-rustfix
|
// run-rustfix
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = 0;
|
let x = "x";
|
||||||
let y = 0;
|
let y = "y";
|
||||||
|
|
||||||
println!("{x}", );
|
println!("{x}", );
|
||||||
//~^ ERROR: redundant argument
|
//~^ ERROR: redundant argument
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
// run-rustfix
|
// run-rustfix
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let x = 0;
|
let x = "x";
|
||||||
let y = 0;
|
let y = "y";
|
||||||
|
|
||||||
println!("{x}", x);
|
println!("{x}", x);
|
||||||
//~^ ERROR: redundant argument
|
//~^ ERROR: redundant argument
|
||||||
|
Loading…
Reference in New Issue
Block a user