Add span label for format str missing specifier
This commit is contained in:
parent
7bd94e0738
commit
9a893cc2b8
@ -915,12 +915,13 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
|
|||||||
errs.push((cx.args[i].span, msg));
|
errs.push((cx.args[i].span, msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if errs.len() > 0 {
|
let errs_len = errs.len();
|
||||||
let args_used = cx.arg_types.len() - errs.len();
|
if errs_len > 0 {
|
||||||
let args_unused = errs.len();
|
let args_used = cx.arg_types.len() - errs_len;
|
||||||
|
let args_unused = errs_len;
|
||||||
|
|
||||||
let mut diag = {
|
let mut diag = {
|
||||||
if errs.len() == 1 {
|
if errs_len == 1 {
|
||||||
let (sp, msg) = errs.into_iter().next().unwrap();
|
let (sp, msg) = errs.into_iter().next().unwrap();
|
||||||
cx.ecx.struct_span_err(sp, msg)
|
cx.ecx.struct_span_err(sp, msg)
|
||||||
} else {
|
} else {
|
||||||
@ -933,6 +934,8 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Used to ensure we only report translations for *one* kind of foreign format.
|
||||||
|
let mut found_foreign = false;
|
||||||
// Decide if we want to look for foreign formatting directives.
|
// Decide if we want to look for foreign formatting directives.
|
||||||
if args_used < args_unused {
|
if args_used < args_unused {
|
||||||
use super::format_foreign as foreign;
|
use super::format_foreign as foreign;
|
||||||
@ -941,9 +944,6 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
|
|||||||
// with `%d should be written as {}` over and over again.
|
// with `%d should be written as {}` over and over again.
|
||||||
let mut explained = HashSet::new();
|
let mut explained = HashSet::new();
|
||||||
|
|
||||||
// Used to ensure we only report translations for *one* kind of foreign format.
|
|
||||||
let mut found_foreign = false;
|
|
||||||
|
|
||||||
macro_rules! check_foreign {
|
macro_rules! check_foreign {
|
||||||
($kind:ident) => {{
|
($kind:ident) => {{
|
||||||
let mut show_doc_note = false;
|
let mut show_doc_note = false;
|
||||||
@ -987,7 +987,7 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
|
|||||||
}
|
}
|
||||||
if suggestions.len() > 0 {
|
if suggestions.len() > 0 {
|
||||||
diag.multipart_suggestion(
|
diag.multipart_suggestion(
|
||||||
"format specifiers in Rust are written using `{}`",
|
"format specifiers use curly braces",
|
||||||
suggestions,
|
suggestions,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -999,6 +999,9 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
|
|||||||
check_foreign!(shell);
|
check_foreign!(shell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !found_foreign && errs_len == 1 {
|
||||||
|
diag.span_label(cx.fmtsp, "formatting specifier missing");
|
||||||
|
}
|
||||||
|
|
||||||
diag.emit();
|
diag.emit();
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,9 @@ error: argument never used
|
|||||||
--> $DIR/ifmt-bad-arg.rs:19:20
|
--> $DIR/ifmt-bad-arg.rs:19:20
|
||||||
|
|
|
|
||||||
LL | format!("{1}", 1);
|
LL | format!("{1}", 1);
|
||||||
| ^
|
| ----- ^
|
||||||
|
| |
|
||||||
|
| formatting specifier missing
|
||||||
|
|
||||||
error: 2 positional arguments in format string, but no arguments were given
|
error: 2 positional arguments in format string, but no arguments were given
|
||||||
--> $DIR/ifmt-bad-arg.rs:23:14
|
--> $DIR/ifmt-bad-arg.rs:23:14
|
||||||
@ -86,31 +88,41 @@ error: argument never used
|
|||||||
--> $DIR/ifmt-bad-arg.rs:43:22
|
--> $DIR/ifmt-bad-arg.rs:43:22
|
||||||
|
|
|
|
||||||
LL | format!("{}", 1, 2); //~ ERROR: argument never used
|
LL | format!("{}", 1, 2); //~ ERROR: argument never used
|
||||||
| ^
|
| ---- ^
|
||||||
|
| |
|
||||||
|
| formatting specifier missing
|
||||||
|
|
||||||
error: argument never used
|
error: argument never used
|
||||||
--> $DIR/ifmt-bad-arg.rs:44:20
|
--> $DIR/ifmt-bad-arg.rs:44:20
|
||||||
|
|
|
|
||||||
LL | format!("{1}", 1, 2); //~ ERROR: argument never used
|
LL | format!("{1}", 1, 2); //~ ERROR: argument never used
|
||||||
| ^
|
| ----- ^
|
||||||
|
| |
|
||||||
|
| formatting specifier missing
|
||||||
|
|
||||||
error: named argument never used
|
error: named argument never used
|
||||||
--> $DIR/ifmt-bad-arg.rs:45:26
|
--> $DIR/ifmt-bad-arg.rs:45:26
|
||||||
|
|
|
|
||||||
LL | format!("{}", 1, foo=2); //~ ERROR: named argument never used
|
LL | format!("{}", 1, foo=2); //~ ERROR: named argument never used
|
||||||
| ^
|
| ---- ^
|
||||||
|
| |
|
||||||
|
| formatting specifier missing
|
||||||
|
|
||||||
error: argument never used
|
error: argument never used
|
||||||
--> $DIR/ifmt-bad-arg.rs:46:22
|
--> $DIR/ifmt-bad-arg.rs:46:22
|
||||||
|
|
|
|
||||||
LL | format!("{foo}", 1, foo=2); //~ ERROR: argument never used
|
LL | format!("{foo}", 1, foo=2); //~ ERROR: argument never used
|
||||||
| ^
|
| ------- ^
|
||||||
|
| |
|
||||||
|
| formatting specifier missing
|
||||||
|
|
||||||
error: named argument never used
|
error: named argument never used
|
||||||
--> $DIR/ifmt-bad-arg.rs:47:21
|
--> $DIR/ifmt-bad-arg.rs:47:21
|
||||||
|
|
|
|
||||||
LL | format!("", foo=2); //~ ERROR: named argument never used
|
LL | format!("", foo=2); //~ ERROR: named argument never used
|
||||||
| ^
|
| -- ^
|
||||||
|
| |
|
||||||
|
| formatting specifier missing
|
||||||
|
|
||||||
error: multiple unused formatting arguments
|
error: multiple unused formatting arguments
|
||||||
--> $DIR/ifmt-bad-arg.rs:48:32
|
--> $DIR/ifmt-bad-arg.rs:48:32
|
||||||
@ -148,7 +160,9 @@ error: named argument never used
|
|||||||
--> $DIR/ifmt-bad-arg.rs:55:51
|
--> $DIR/ifmt-bad-arg.rs:55:51
|
||||||
|
|
|
|
||||||
LL | format!("{valuea} {valueb}", valuea=5, valuec=7);
|
LL | format!("{valuea} {valueb}", valuea=5, valuec=7);
|
||||||
| ^
|
| ------------------- ^
|
||||||
|
| |
|
||||||
|
| formatting specifier missing
|
||||||
|
|
||||||
error: invalid format string: expected `'}'` but string was terminated
|
error: invalid format string: expected `'}'` but string was terminated
|
||||||
--> $DIR/ifmt-bad-arg.rs:61:15
|
--> $DIR/ifmt-bad-arg.rs:61:15
|
||||||
@ -180,7 +194,7 @@ error: argument never used
|
|||||||
LL | format!("foo %s baz", "bar"); //~ ERROR: argument never used
|
LL | format!("foo %s baz", "bar"); //~ ERROR: argument never used
|
||||||
| -- ^^^^^
|
| -- ^^^^^
|
||||||
| |
|
| |
|
||||||
| help: format specifiers in Rust are written using `{}`: `{}`
|
| help: format specifiers use curly braces: `{}`
|
||||||
|
|
|
|
||||||
= note: printf formatting not supported; see the documentation for `std::fmt`
|
= note: printf formatting not supported; see the documentation for `std::fmt`
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ LL | println!("%.*3$s %s!/n", "Hello,", "World", 4); //~ ERROR multiple unus
|
|||||||
| multiple missing formatting specifiers
|
| multiple missing formatting specifiers
|
||||||
|
|
|
|
||||||
= note: printf formatting not supported; see the documentation for `std::fmt`
|
= note: printf formatting not supported; see the documentation for `std::fmt`
|
||||||
help: format specifiers in Rust are written using `{}`
|
help: format specifiers use curly braces
|
||||||
|
|
|
|
||||||
LL | println!("{:.2$} {}!/n", "Hello,", "World", 4); //~ ERROR multiple unused formatting arguments
|
LL | println!("{:.2$} {}!/n", "Hello,", "World", 4); //~ ERROR multiple unused formatting arguments
|
||||||
| ^^^^^^ ^^
|
| ^^^^^^ ^^
|
||||||
@ -18,7 +18,7 @@ error: argument never used
|
|||||||
LL | println!("%1$*2$.*3$f", 123.456); //~ ERROR never used
|
LL | println!("%1$*2$.*3$f", 123.456); //~ ERROR never used
|
||||||
| ----------- ^^^^^^^
|
| ----------- ^^^^^^^
|
||||||
| |
|
| |
|
||||||
| help: format specifiers in Rust are written using `{}`: `{0:1$.2$}`
|
| help: format specifiers use curly braces: `{0:1$.2$}`
|
||||||
|
|
|
|
||||||
= note: printf formatting not supported; see the documentation for `std::fmt`
|
= note: printf formatting not supported; see the documentation for `std::fmt`
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ LL | | "###, "Hello,", "World", 4);
|
|||||||
| multiple missing formatting specifiers
|
| multiple missing formatting specifiers
|
||||||
|
|
|
|
||||||
= note: printf formatting not supported; see the documentation for `std::fmt`
|
= note: printf formatting not supported; see the documentation for `std::fmt`
|
||||||
help: format specifiers in Rust are written using `{}`
|
help: format specifiers use curly braces
|
||||||
|
|
|
|
||||||
LL | println!(r###"{:.2$}
|
LL | println!(r###"{:.2$}
|
||||||
LL | {}!/n
|
LL | {}!/n
|
||||||
@ -44,7 +44,9 @@ error: argument never used
|
|||||||
--> $DIR/format-foreign.rs:22:30
|
--> $DIR/format-foreign.rs:22:30
|
||||||
|
|
|
|
||||||
LL | println!("{} %f", "one", 2.0); //~ ERROR never used
|
LL | println!("{} %f", "one", 2.0); //~ ERROR never used
|
||||||
| ^^^
|
| ------- ^^^
|
||||||
|
| |
|
||||||
|
| formatting specifier missing
|
||||||
|
|
||||||
error: named argument never used
|
error: named argument never used
|
||||||
--> $DIR/format-foreign.rs:24:39
|
--> $DIR/format-foreign.rs:24:39
|
||||||
|
@ -22,7 +22,9 @@ error: named argument never used
|
|||||||
--> $DIR/format-unused-lables.rs:21:35
|
--> $DIR/format-unused-lables.rs:21:35
|
||||||
|
|
|
|
||||||
LL | println!("Some stuff", UNUSED="args"); //~ ERROR named argument never used
|
LL | println!("Some stuff", UNUSED="args"); //~ ERROR named argument never used
|
||||||
| ^^^^^^
|
| ------------ ^^^^^^
|
||||||
|
| |
|
||||||
|
| formatting specifier missing
|
||||||
|
|
||||||
error: multiple unused formatting arguments
|
error: multiple unused formatting arguments
|
||||||
--> $DIR/format-unused-lables.rs:24:9
|
--> $DIR/format-unused-lables.rs:24:9
|
||||||
|
Loading…
Reference in New Issue
Block a user