]> git.lizzy.rs Git - rust.git/commitdiff
Add span label for format str missing specifier
authorEsteban Küber <esteban@kuber.com.ar>
Wed, 25 Jul 2018 03:46:22 +0000 (20:46 -0700)
committerEsteban Küber <esteban@kuber.com.ar>
Wed, 25 Jul 2018 03:46:22 +0000 (20:46 -0700)
src/libsyntax_ext/format.rs
src/test/ui/ifmt-bad-arg.stderr
src/test/ui/macros/format-foreign.stderr
src/test/ui/macros/format-unused-lables.stderr

index ad05db91770a3031b0fa8394118ce1e41cf03d74..98de3d80b1e1f354ab2827b19b6a1f168637e2a5 100644 (file)
@@ -915,12 +915,13 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
             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 {
@@ -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.
         if args_used < args_unused {
             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.
             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;
@@ -987,7 +987,7 @@ macro_rules! check_foreign {
                     }
                     if suggestions.len() > 0 {
                         diag.multipart_suggestion(
-                            "format specifiers in Rust are written using `{}`",
+                            "format specifiers use curly braces",
                             suggestions,
                         );
                     }
@@ -999,6 +999,9 @@ macro_rules! check_foreign {
                 check_foreign!(shell);
             }
         }
+        if !found_foreign && errs_len == 1 {
+            diag.span_label(cx.fmtsp, "formatting specifier missing");
+        }
 
         diag.emit();
     }
index a126998355e0c83002809c09cc26b413c60bba8f..c8fd8bad19ba54402f1f3176ef4280ab4004288a 100644 (file)
@@ -16,7 +16,9 @@ error: argument never used
   --> $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
@@ -86,31 +88,41 @@ error: argument never used
   --> $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
@@ -148,7 +160,9 @@ error: named argument never used
   --> $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
@@ -180,7 +194,7 @@ 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`
 
index 93e68183b140ecc50b44a1cf07a4104c953ece76..5e76c0a322e51b941296762b1e793191c4112ba8 100644 (file)
@@ -7,7 +7,7 @@ LL |     println!("%.*3$s %s!/n", "Hello,", "World", 4); //~ ERROR multiple unus
    |              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
    |               ^^^^^^ ^^
@@ -18,7 +18,7 @@ error: argument 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`
 
@@ -34,7 +34,7 @@ LL | | "###, "Hello,", "World", 4);
    |      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
@@ -44,7 +44,9 @@ error: argument never used
   --> $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
index 0b024facc8e3822038b69a7442e6c2fcc2e3924b..81171a1ed01de5dfe035f8ab353e727ba8b2300a 100644 (file)
@@ -22,7 +22,9 @@ error: named argument never used
   --> $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