Skip to content

Less unused argument spew #37729

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

Closed
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
7 changes: 5 additions & 2 deletions src/libsyntax_ext/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,11 @@ 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);
for (sp, _) in errs {
// Ignore the specific message, and use something terser; otherwise, the error
// message starts to sound a little repetitive. A little repetitive. A little
// repetitive.
diag.span_label(sp, &"unused");
}
diag
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/macros/format-foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ fn main() {
println!("{} %f", "one", 2.0);

println!("Hi there, $NAME.", NAME="Tim");

println!("%*2$.*1$s",
"Some text",
20,
8);
}
39 changes: 22 additions & 17 deletions src/test/ui/macros/format-foreign.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,12 @@ 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
|
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`
Expand Down Expand Up @@ -48,5 +37,21 @@ error: named argument never used
= 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: multiple unused formatting arguments
--> $DIR/format-foreign.rs:21:5
|
21 | println!("%*2$.*1$s",
| ^
22 | "Some text",
| ----------- unused
23 | 20,
| -- unused
24 | 8);
| - unused
|
= help: `%*2$.*1$s` should be written as `{:>1$.0$}`
= note: printf formatting not supported; see the documentation for `std::fmt`
= note: this error originates in a macro outside of the current crate

error: aborting due to 5 previous errors