errs.push((cx.args[i].span, msg));
}
}
- if errs.len() > 0 {
- let args_used = cx.arg_types.len() - errs.len();
- let args_unused = errs.len();
+ let errs_len = errs.len();
+ if errs_len > 0 {
+ let args_used = cx.arg_types.len() - errs_len;
+ let args_unused = errs_len;
let mut diag = {
- if errs.len() == 1 {
+ if errs_len == 1 {
let (sp, msg) = errs.into_iter().next().unwrap();
cx.ecx.struct_span_err(sp, msg)
} else {
}
};
+ // 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.
if args_used < args_unused {
use super::format_foreign as foreign;
// with `%d should be written as {}` over and over again.
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 {
($kind:ident) => {{
let mut show_doc_note = false;
}
if suggestions.len() > 0 {
diag.multipart_suggestion(
- "format specifiers in Rust are written using `{}`",
+ "format specifiers use curly braces",
suggestions,
);
}
check_foreign!(shell);
}
}
+ if !found_foreign && errs_len == 1 {
+ diag.span_label(cx.fmtsp, "formatting specifier missing");
+ }
diag.emit();
}
--> $DIR/ifmt-bad-arg.rs:19:20
|
LL | format!("{1}", 1);
- | ^
+ | ----- ^
+ | |
+ | formatting specifier missing
error: 2 positional arguments in format string, but no arguments were given
--> $DIR/ifmt-bad-arg.rs:23:14
--> $DIR/ifmt-bad-arg.rs:43:22
|
LL | format!("{}", 1, 2); //~ ERROR: argument never used
- | ^
+ | ---- ^
+ | |
+ | formatting specifier missing
error: argument never used
--> $DIR/ifmt-bad-arg.rs:44:20
|
LL | format!("{1}", 1, 2); //~ ERROR: argument never used
- | ^
+ | ----- ^
+ | |
+ | formatting specifier missing
error: named argument never used
--> $DIR/ifmt-bad-arg.rs:45:26
|
LL | format!("{}", 1, foo=2); //~ ERROR: named argument never used
- | ^
+ | ---- ^
+ | |
+ | formatting specifier missing
error: argument never used
--> $DIR/ifmt-bad-arg.rs:46:22
|
LL | format!("{foo}", 1, foo=2); //~ ERROR: argument never used
- | ^
+ | ------- ^
+ | |
+ | formatting specifier missing
error: named argument never used
--> $DIR/ifmt-bad-arg.rs:47:21
|
LL | format!("", foo=2); //~ ERROR: named argument never used
- | ^
+ | -- ^
+ | |
+ | formatting specifier missing
error: multiple unused formatting arguments
--> $DIR/ifmt-bad-arg.rs:48:32
--> $DIR/ifmt-bad-arg.rs:55:51
|
LL | format!("{valuea} {valueb}", valuea=5, valuec=7);
- | ^
+ | ------------------- ^
+ | |
+ | formatting specifier missing
error: invalid format string: expected `'}'` but string was terminated
--> $DIR/ifmt-bad-arg.rs:61:15
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`
| multiple missing formatting specifiers
|
= 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!("%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`
| multiple missing formatting specifiers
|
= 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 | {}!/n
--> $DIR/format-foreign.rs:22:30
|
LL | println!("{} %f", "one", 2.0); //~ ERROR never used
- | ^^^
+ | ------- ^^^
+ | |
+ | formatting specifier missing
error: named argument never used
--> $DIR/format-foreign.rs:24:39
--> $DIR/format-unused-lables.rs:21:35
|
LL | println!("Some stuff", UNUSED="args"); //~ ERROR named argument never used
- | ^^^^^^
+ | ------------ ^^^^^^
+ | |
+ | formatting specifier missing
error: multiple unused formatting arguments
--> $DIR/format-unused-lables.rs:24:9