Skip to content

Commit eb3da09

Browse files
committed
Add secondary span pointing at the statement (error span)
1 parent a4660df commit eb3da09

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

src/libsyntax_ext/format.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,12 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
814814
let (sp, msg) = errs.into_iter().next().unwrap();
815815
cx.ecx.struct_span_err(sp, msg)
816816
} else {
817-
cx.ecx.struct_span_err(errs.iter().map(|&(sp, _)| sp).collect::<Vec<Span>>(),
818-
"multiple unused formatting arguments")
817+
let mut diag = cx.ecx.struct_span_err(
818+
errs.iter().map(|&(sp, _)| sp).collect::<Vec<Span>>(),
819+
"multiple unused formatting arguments"
820+
);
821+
diag.span_label(cx.fmtsp, "multiple unused arguments in this statement");
822+
diag
819823
}
820824
};
821825

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ error: multiple unused formatting arguments
22
--> $DIR/format-foreign.rs:12:30
33
|
44
12 | println!("%.*3$s %s!/n", "Hello,", "World", 4); //~ ERROR multiple unused formatting arguments
5-
| ^^^^^^^^ ^^^^^^^ ^
5+
| -------------------------^^^^^^^^--^^^^^^^--^-- multiple unused arguments in this statement
66
|
77
= help: `%.*3$s` should be written as `{:.2$}`
88
= help: `%s` should be written as `{}`
99
= note: printf formatting not supported; see the documentation for `std::fmt`
10+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
1011

1112
error: argument never used
1213
--> $DIR/format-foreign.rs:13:29

src/test/ui/macros/format-unused-lables.stderr

+23-14
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,24 @@ error: multiple unused formatting arguments
22
--> $DIR/format-unused-lables.rs:12:22
33
|
44
12 | println!("Test", 123, 456, 789);
5-
| ^^^ ^^^ ^^^
5+
| -----------------^^^--^^^--^^^-- multiple unused arguments in this statement
6+
|
7+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
68

79
error: multiple unused formatting arguments
810
--> $DIR/format-unused-lables.rs:16:9
911
|
10-
16 | 123, //~ ERROR multiple unused formatting arguments
11-
| ^^^
12-
17 | 456,
13-
| ^^^
14-
18 | 789
15-
| ^^^
12+
15 | / println!("Test2",
13+
16 | | 123, //~ ERROR multiple unused formatting arguments
14+
| | ^^^
15+
17 | | 456,
16+
| | ^^^
17+
18 | | 789
18+
| | ^^^
19+
19 | | );
20+
| |______- multiple unused arguments in this statement
21+
|
22+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
1623

1724
error: named argument never used
1825
--> $DIR/format-unused-lables.rs:21:35
@@ -23,16 +30,18 @@ error: named argument never used
2330
error: multiple unused formatting arguments
2431
--> $DIR/format-unused-lables.rs:24:9
2532
|
26-
24 | "woo!", //~ ERROR multiple unused formatting arguments
27-
| ^^^^^^
28-
25 | STUFF=
29-
26 | "things"
30-
| ^^^^^^^^
31-
27 | , UNUSED="args");
32-
| ^^^^^^
33+
23 | / println!("Some more $STUFF",
34+
24 | | "woo!", //~ ERROR multiple unused formatting arguments
35+
| | ^^^^^^
36+
25 | | STUFF=
37+
26 | | "things"
38+
| | ^^^^^^^^
39+
27 | | , UNUSED="args");
40+
| |_______________________^^^^^^_- multiple unused arguments in this statement
3341
|
3442
= help: `$STUFF` should be written as `{STUFF}`
3543
= note: shell formatting not supported; see the documentation for `std::fmt`
44+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
3645

3746
error: aborting due to 4 previous errors
3847

0 commit comments

Comments
 (0)