about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFabian Wolff <fabian.wolff@alumni.ethz.ch>2021-09-29 00:11:55 +0200
committerFabian Wolff <fabian.wolff@alumni.ethz.ch>2021-09-29 02:02:45 +0200
commit6490ed30e1025fbb85b3a2dd4849a249c072fb30 (patch)
tree170c9b42041dce30842771537c73e268c75c86d5 /src
parent1d71ba862309d59df710078a845c8772ffb22aba (diff)
Improve error message for `printf`-style format strings
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/fmt/issue-89173.rs14
-rw-r--r--src/test/ui/fmt/issue-89173.stderr18
2 files changed, 32 insertions, 0 deletions
diff --git a/src/test/ui/fmt/issue-89173.rs b/src/test/ui/fmt/issue-89173.rs
new file mode 100644
index 00000000000..96277d4d0d9
--- /dev/null
+++ b/src/test/ui/fmt/issue-89173.rs
@@ -0,0 +1,14 @@
+// Regression test for #89173: Make sure a helpful note is issued for
+// printf-style format strings using `*` to specify the width.
+
+fn main() {
+    let num = 0x0abcde;
+    let width = 6;
+    print!("%0*x", width, num);
+    //~^ ERROR: multiple unused formatting arguments
+    //~| NOTE: multiple missing formatting specifiers
+    //~| NOTE: argument never used
+    //~| NOTE: argument never used
+    //~| NOTE: format specifiers use curly braces, and you have to use a positional or named parameter for the width
+    //~| NOTE: printf formatting not supported
+}
diff --git a/src/test/ui/fmt/issue-89173.stderr b/src/test/ui/fmt/issue-89173.stderr
new file mode 100644
index 00000000000..7b21e0a4fc8
--- /dev/null
+++ b/src/test/ui/fmt/issue-89173.stderr
@@ -0,0 +1,18 @@
+error: multiple unused formatting arguments
+  --> $DIR/issue-89173.rs:7:20
+   |
+LL |     print!("%0*x", width, num);
+   |            ------  ^^^^^  ^^^ argument never used
+   |            |       |
+   |            |       argument never used
+   |            multiple missing formatting specifiers
+   |
+note: format specifiers use curly braces, and you have to use a positional or named parameter for the width
+  --> $DIR/issue-89173.rs:7:13
+   |
+LL |     print!("%0*x", width, num);
+   |             ^^^^
+   = note: printf formatting not supported; see the documentation for `std::fmt`
+
+error: aborting due to previous error
+