Skip to content

Commit 6f0ba7e

Browse files
committed
Compact "unused format argument" errors.
Unused arguments are attached to the main error as labels. This drops the traditional named/positional message split (except in the case of a *single* unused argument) for "unused" in interest of terseness. Closes #37718.
1 parent 455723c commit 6f0ba7e

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

src/libsyntax_ext/format.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,11 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
794794
} else {
795795
let mut diag = cx.ecx.struct_span_err(cx.fmtsp,
796796
"multiple unused formatting arguments");
797-
for (sp, msg) in errs {
798-
diag.span_note(sp, msg);
797+
for (sp, _) in errs {
798+
// Ignore the specific message, and use something terser; otherwise, the error
799+
// message starts to sound a little repetitive. A little repetitive. A little
800+
// repetitive.
801+
diag.span_label(sp, &"unused");
799802
}
800803
diag
801804
}

src/test/ui/macros/format-foreign.rs

+5
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ fn main() {
1717
println!("{} %f", "one", 2.0);
1818

1919
println!("Hi there, $NAME.", NAME="Tim");
20+
21+
println!("%*2$.*1$s",
22+
"Some text",
23+
20,
24+
8);
2025
}

src/test/ui/macros/format-foreign.stderr

+22-17
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,12 @@ error: multiple unused formatting arguments
22
--> $DIR/format-foreign.rs:12:5
33
|
44
12 | println!("%.*3$s %s!/n", "Hello,", "World", 4);
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^--------^^-------^^-^^
6+
| | | |
7+
| | | unused
8+
| | unused
9+
| unused
610
|
7-
note: argument never used
8-
--> $DIR/format-foreign.rs:12:30
9-
|
10-
12 | println!("%.*3$s %s!/n", "Hello,", "World", 4);
11-
| ^^^^^^^^
12-
note: argument never used
13-
--> $DIR/format-foreign.rs:12:40
14-
|
15-
12 | println!("%.*3$s %s!/n", "Hello,", "World", 4);
16-
| ^^^^^^^
17-
note: argument never used
18-
--> $DIR/format-foreign.rs:12:49
19-
|
20-
12 | println!("%.*3$s %s!/n", "Hello,", "World", 4);
21-
| ^
2211
= help: `%.*3$s` should be written as `{:.2$}`
2312
= help: `%s` should be written as `{}`
2413
= note: printf formatting not supported; see the documentation for `std::fmt`
@@ -48,5 +37,21 @@ error: named argument never used
4837
= help: `$NAME` should be written as `{NAME}`
4938
= note: shell formatting not supported; see the documentation for `std::fmt`
5039

51-
error: aborting due to 4 previous errors
40+
error: multiple unused formatting arguments
41+
--> $DIR/format-foreign.rs:21:5
42+
|
43+
21 | println!("%*2$.*1$s",
44+
| ^
45+
22 | "Some text",
46+
| ----------- unused
47+
23 | 20,
48+
| -- unused
49+
24 | 8);
50+
| - unused
51+
|
52+
= help: `%*2$.*1$s` should be written as `{:>1$.0$}`
53+
= note: printf formatting not supported; see the documentation for `std::fmt`
54+
= note: this error originates in a macro outside of the current crate
55+
56+
error: aborting due to 5 previous errors
5257

0 commit comments

Comments
 (0)