Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple unused formatting argument are now labels, less unused argument spam #41256

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/libsyntax_ext/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,10 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
} else {
let mut diag = cx.ecx.struct_span_err(cx.fmtsp,
"multiple unused formatting arguments");
for (sp, msg) in errs {
diag.span_note(sp, msg);

// Push all the unused errors to the DiagnosticBuilder's `MultiSpan`.
for (sp, _) in errs {
diag.span_label(sp, &"unused");
}
diag
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/macros/format-foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@

fn main() {
println!("%.*3$s %s!\n", "Hello,", "World", 4);
println!(
"%.*3$s %s!\n",
"Hello,",
"World",
4
);

println!("%1$*2$.*3$f", 123.456);

// This should *not* produce hints, on the basis that there's equally as
Expand Down
53 changes: 31 additions & 22 deletions src/test/ui/macros/format-foreign.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,60 @@ error: multiple unused formatting arguments
--> $DIR/format-foreign.rs:12:5
|
12 | println!("%.*3$s %s!/n", "Hello,", "World", 4);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^^--------^^-------^^-^^
| | | |
| | | unused
| | unused
| unused
|
note: argument never used
--> $DIR/format-foreign.rs:12:30
|
12 | println!("%.*3$s %s!/n", "Hello,", "World", 4);
| ^^^^^^^^
note: argument never used
--> $DIR/format-foreign.rs:12:40
|
12 | println!("%.*3$s %s!/n", "Hello,", "World", 4);
| ^^^^^^^
note: argument never used
--> $DIR/format-foreign.rs:12:49
= help: `%.*3$s` should be written as `{:.2$}`
= help: `%s` should be written as `{}`
= note: printf formatting not supported; see the documentation for `std::fmt`
= note: this error originates in a macro outside of the current crate

error: multiple unused formatting arguments
--> $DIR/format-foreign.rs:13:5
|
13 | println!(
| _____^ starting here...
14 | | "%.*3$s %s!/n",
15 | | "Hello,",
| | -------- unused
16 | | "World",
| | ------- unused
17 | | 4
| | - unused
18 | | );
| |______^ ...ending here
|
12 | println!("%.*3$s %s!/n", "Hello,", "World", 4);
| ^
= help: `%.*3$s` should be written as `{:.2$}`
= help: `%s` should be written as `{}`
= note: printf formatting not supported; see the documentation for `std::fmt`
= note: this error originates in a macro outside of the current crate

error: argument never used
--> $DIR/format-foreign.rs:13:29
--> $DIR/format-foreign.rs:20:29
|
13 | println!("%1$*2$.*3$f", 123.456);
20 | println!("%1$*2$.*3$f", 123.456);
| ^^^^^^^
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put a label here also?

|
= help: `%1$*2$.*3$f` should be written as `{0:1$.2$}`
= note: printf formatting not supported; see the documentation for `std::fmt`

error: argument never used
--> $DIR/format-foreign.rs:17:30
--> $DIR/format-foreign.rs:24:30
|
17 | println!("{} %f", "one", 2.0);
24 | println!("{} %f", "one", 2.0);
| ^^^
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same


error: named argument never used
--> $DIR/format-foreign.rs:19:39
--> $DIR/format-foreign.rs:26:39
|
19 | println!("Hi there, $NAME.", NAME="Tim");
26 | println!("Hi there, $NAME.", NAME="Tim");
| ^^^^^
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

|
= help: `$NAME` should be written as `{NAME}`
= note: shell formatting not supported; see the documentation for `std::fmt`

error: aborting due to 4 previous errors
error: aborting due to 5 previous errors