about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/fmt/format-args-non-identifier-diagnostics.fixed10
-rw-r--r--tests/ui/fmt/format-args-non-identifier-diagnostics.rs10
-rw-r--r--tests/ui/fmt/format-args-non-identifier-diagnostics.stderr13
3 files changed, 33 insertions, 0 deletions
diff --git a/tests/ui/fmt/format-args-non-identifier-diagnostics.fixed b/tests/ui/fmt/format-args-non-identifier-diagnostics.fixed
new file mode 100644
index 00000000000..bd4db948067
--- /dev/null
+++ b/tests/ui/fmt/format-args-non-identifier-diagnostics.fixed
@@ -0,0 +1,10 @@
+// Checks that there is a suggestion for simple tuple index access expression (used where an
+// identifier is expected in a format arg) to use positional arg instead.
+// Issue: <https://github.com/rust-lang/rust/issues/122535>.
+//@ run-rustfix
+
+fn main() {
+    let x = (1,);
+    println!("{0}", x.0);
+    //~^ ERROR invalid format string
+}
diff --git a/tests/ui/fmt/format-args-non-identifier-diagnostics.rs b/tests/ui/fmt/format-args-non-identifier-diagnostics.rs
new file mode 100644
index 00000000000..aab705341f7
--- /dev/null
+++ b/tests/ui/fmt/format-args-non-identifier-diagnostics.rs
@@ -0,0 +1,10 @@
+// Checks that there is a suggestion for simple tuple index access expression (used where an
+// identifier is expected in a format arg) to use positional arg instead.
+// Issue: <https://github.com/rust-lang/rust/issues/122535>.
+//@ run-rustfix
+
+fn main() {
+    let x = (1,);
+    println!("{x.0}");
+    //~^ ERROR invalid format string
+}
diff --git a/tests/ui/fmt/format-args-non-identifier-diagnostics.stderr b/tests/ui/fmt/format-args-non-identifier-diagnostics.stderr
new file mode 100644
index 00000000000..08abba2854e
--- /dev/null
+++ b/tests/ui/fmt/format-args-non-identifier-diagnostics.stderr
@@ -0,0 +1,13 @@
+error: invalid format string: tuple index access isn't supported
+  --> $DIR/format-args-non-identifier-diagnostics.rs:8:16
+   |
+LL |     println!("{x.0}");
+   |                ^^^ not supported in format string
+   |
+help: consider using a positional formatting argument instead
+   |
+LL |     println!("{0}", x.0);
+   |                ~  +++++
+
+error: aborting due to 1 previous error
+