Rollup merge of #47481 - estebank:unused-args, r=arielb1

Point at unused arguments for format string

Avoid overlapping spans by only pointing at the arguments that are not
being used in the argument string. Enable libsyntax to have diagnostics
with multiple primary spans by accepting `Into<MultiSpan>` instead of
`Span`.

Partially addresses #41850.
This commit is contained in:
kennytm 2018-01-18 01:57:25 +08:00 committed by GitHub
commit 35bf7f844c
7 changed files with 69 additions and 77 deletions

View file

@ -9,7 +9,7 @@
// except according to those terms.
fn main() {
println!("%.*3$s %s!\n", "Hello,", "World", 4);
println!("%.*3$s %s!\n", "Hello,", "World", 4); //~ ERROR multiple unused formatting arguments
println!("%1$*2$.*3$f", 123.456); //~ ERROR never used
// This should *not* produce hints, on the basis that there's equally as

View file

@ -1,12 +1,8 @@
error: multiple unused formatting arguments
--> $DIR/format-foreign.rs:12:5
--> $DIR/format-foreign.rs:12:30
|
12 | println!("%.*3$s %s!/n", "Hello,", "World", 4);
| ^^^^^^^^^^^^^^^^^^^^^^^^^--------^^-------^^-^^
| | | |
| | | unused
| | unused
| unused
12 | println!("%.*3$s %s!/n", "Hello,", "World", 4); //~ ERROR multiple unused formatting arguments
| -------------------------^^^^^^^^--^^^^^^^--^-- multiple unused arguments in this statement
|
= help: `%.*3$s` should be written as `{:.2$}`
= help: `%s` should be written as `{}`

View file

@ -10,9 +10,10 @@
fn main() {
println!("Test", 123, 456, 789);
//~^ ERROR multiple unused formatting arguments
println!("Test2",
123,
123, //~ ERROR multiple unused formatting arguments
456,
789
);
@ -20,7 +21,7 @@ fn main() {
println!("Some stuff", UNUSED="args"); //~ ERROR named argument never used
println!("Some more $STUFF",
"woo!",
"woo!", //~ ERROR multiple unused formatting arguments
STUFF=
"things"
, UNUSED="args");

View file

@ -1,49 +1,43 @@
error: multiple unused formatting arguments
--> $DIR/format-unused-lables.rs:12:5
--> $DIR/format-unused-lables.rs:12:22
|
12 | println!("Test", 123, 456, 789);
| ^^^^^^^^^^^^^^^^^---^^---^^---^^
| | | |
| | | unused
| | unused
| unused
| -----------------^^^--^^^--^^^-- multiple unused arguments in this statement
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: multiple unused formatting arguments
--> $DIR/format-unused-lables.rs:14:5
--> $DIR/format-unused-lables.rs:16:9
|
14 | / println!("Test2",
15 | | 123,
| | --- unused
16 | | 456,
| | --- unused
17 | | 789
| | --- unused
18 | | );
| |______^
15 | / println!("Test2",
16 | | 123, //~ ERROR multiple unused formatting arguments
| | ^^^
17 | | 456,
| | ^^^
18 | | 789
| | ^^^
19 | | );
| |______- multiple unused arguments in this statement
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: named argument never used
--> $DIR/format-unused-lables.rs:20:35
--> $DIR/format-unused-lables.rs:21:35
|
20 | println!("Some stuff", UNUSED="args"); //~ ERROR named argument never used
21 | println!("Some stuff", UNUSED="args"); //~ ERROR named argument never used
| ^^^^^^
error: multiple unused formatting arguments
--> $DIR/format-unused-lables.rs:22:5
--> $DIR/format-unused-lables.rs:24:9
|
22 | / println!("Some more $STUFF",
23 | | "woo!",
| | ------ unused
24 | | STUFF=
25 | | "things"
| | -------- unused
26 | | , UNUSED="args");
| |_______________________------_^
| |
| unused
23 | / println!("Some more $STUFF",
24 | | "woo!", //~ ERROR multiple unused formatting arguments
| | ^^^^^^
25 | | STUFF=
26 | | "things"
| | ^^^^^^^^
27 | | , UNUSED="args");
| |_______________________^^^^^^_- multiple unused arguments in this statement
|
= help: `$STUFF` should be written as `{STUFF}`
= note: shell formatting not supported; see the documentation for `std::fmt`