From 5b36e375c2f6b0a8189134f34b7c8f5ca3ec28d1 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 9 Nov 2024 22:05:33 -0800 Subject: [PATCH 1/2] Add ui test of invalid expression syntax in display attribute --- tests/ui/expression-fallback.rs | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/ui/expression-fallback.rs diff --git a/tests/ui/expression-fallback.rs b/tests/ui/expression-fallback.rs new file mode 100644 index 0000000..7269129 --- /dev/null +++ b/tests/ui/expression-fallback.rs @@ -0,0 +1,7 @@ +use thiserror::Error; + +#[derive(Error, Debug)] +#[error("".yellow)] +pub struct ArgError; + +fn main() {} From 591a44d9a37b0326e808df7ef38a6a101badab17 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 9 Nov 2024 22:18:07 -0800 Subject: [PATCH 2/2] Fix fallback fmt expression parser hang --- impl/src/fmt.rs | 2 ++ tests/ui/expression-fallback.stderr | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/ui/expression-fallback.stderr diff --git a/impl/src/fmt.rs b/impl/src/fmt.rs index 3d1394c..d2ab353 100644 --- a/impl/src/fmt.rs +++ b/impl/src/fmt.rs @@ -193,6 +193,8 @@ fn fallback_explicit_named_args(input: ParseStream) -> Result { let ident = input.call(Ident::parse_any)?; input.parse::()?; args.named.insert(ident); + } else { + input.parse::()?; } } diff --git a/tests/ui/expression-fallback.stderr b/tests/ui/expression-fallback.stderr new file mode 100644 index 0000000..5c9f215 --- /dev/null +++ b/tests/ui/expression-fallback.stderr @@ -0,0 +1,19 @@ +error: expected `,`, found `.` + --> tests/ui/expression-fallback.rs:4:11 + | +4 | #[error("".yellow)] + | ^ expected `,` + +error: argument never used + --> tests/ui/expression-fallback.rs:4:12 + | +4 | #[error("".yellow)] + | -- ^^^^^^ argument never used + | | + | formatting specifier missing + +error[E0425]: cannot find value `yellow` in this scope + --> tests/ui/expression-fallback.rs:4:12 + | +4 | #[error("".yellow)] + | ^^^^^^ not found in this scope