From a0a2ec332621d35b92633dc4db0451e0c3cb4ab2 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Wed, 3 Aug 2022 11:28:00 +0900 Subject: [PATCH] add tests for `Debug` formatters and precision formatters --- .../struct-field-as-captured-argument.fixed | 3 ++ .../fmt/struct-field-as-captured-argument.rs | 3 ++ .../struct-field-as-captured-argument.stderr | 35 ++++++++++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/test/ui/fmt/struct-field-as-captured-argument.fixed b/src/test/ui/fmt/struct-field-as-captured-argument.fixed index a8d7b44fb3d..f7244f6744f 100644 --- a/src/test/ui/fmt/struct-field-as-captured-argument.fixed +++ b/src/test/ui/fmt/struct-field-as-captured-argument.fixed @@ -12,4 +12,7 @@ fn main() { format!("{1} {} {bar}", "aa", foo.field); //~ ERROR invalid format string: field access isn't supported format!("{2} {} {1} {bar}", "aa", "bb", foo.field); //~ ERROR invalid format string: field access isn't supported format!("{1} {} {baz}", "aa", foo.field, baz = 3); //~ ERROR invalid format string: field access isn't supported + format!("{1:?} {} {baz}", "aa", foo.field, baz = 3); //~ ERROR invalid format string: field access isn't supported + format!("{1:#?} {} {baz}", "aa", foo.field, baz = 3); //~ ERROR invalid format string: field access isn't supported + format!("{1:.3} {} {baz}", "aa", foo.field, baz = 3); //~ ERROR invalid format string: field access isn't supported } diff --git a/src/test/ui/fmt/struct-field-as-captured-argument.rs b/src/test/ui/fmt/struct-field-as-captured-argument.rs index e23c14190b0..ab5f2552bd3 100644 --- a/src/test/ui/fmt/struct-field-as-captured-argument.rs +++ b/src/test/ui/fmt/struct-field-as-captured-argument.rs @@ -12,4 +12,7 @@ fn main() { format!("{foo.field} {} {bar}", "aa"); //~ ERROR invalid format string: field access isn't supported format!("{foo.field} {} {1} {bar}", "aa", "bb"); //~ ERROR invalid format string: field access isn't supported format!("{foo.field} {} {baz}", "aa", baz = 3); //~ ERROR invalid format string: field access isn't supported + format!("{foo.field:?} {} {baz}", "aa", baz = 3); //~ ERROR invalid format string: field access isn't supported + format!("{foo.field:#?} {} {baz}", "aa", baz = 3); //~ ERROR invalid format string: field access isn't supported + format!("{foo.field:.3} {} {baz}", "aa", baz = 3); //~ ERROR invalid format string: field access isn't supported } diff --git a/src/test/ui/fmt/struct-field-as-captured-argument.stderr b/src/test/ui/fmt/struct-field-as-captured-argument.stderr index 28d3c8f838b..7ea8b4068f2 100644 --- a/src/test/ui/fmt/struct-field-as-captured-argument.stderr +++ b/src/test/ui/fmt/struct-field-as-captured-argument.stderr @@ -42,5 +42,38 @@ help: consider using a positional formatting argument instead LL | format!("{1} {} {baz}", "aa", foo.field, baz = 3); | ~ +++++++++++ -error: aborting due to 4 previous errors +error: invalid format string: field access isn't supported + --> $DIR/struct-field-as-captured-argument.rs:15:15 + | +LL | format!("{foo.field:?} {} {baz}", "aa", baz = 3); + | ^^^^^^^^^ not supported in format string + | +help: consider using a positional formatting argument instead + | +LL | format!("{1:?} {} {baz}", "aa", foo.field, baz = 3); + | ~ +++++++++++ + +error: invalid format string: field access isn't supported + --> $DIR/struct-field-as-captured-argument.rs:16:15 + | +LL | format!("{foo.field:#?} {} {baz}", "aa", baz = 3); + | ^^^^^^^^^ not supported in format string + | +help: consider using a positional formatting argument instead + | +LL | format!("{1:#?} {} {baz}", "aa", foo.field, baz = 3); + | ~ +++++++++++ + +error: invalid format string: field access isn't supported + --> $DIR/struct-field-as-captured-argument.rs:17:15 + | +LL | format!("{foo.field:.3} {} {baz}", "aa", baz = 3); + | ^^^^^^^^^ not supported in format string + | +help: consider using a positional formatting argument instead + | +LL | format!("{1:.3} {} {baz}", "aa", foo.field, baz = 3); + | ~ +++++++++++ + +error: aborting due to 7 previous errors