From 07c8e123fc46320d9a598b0c00136402710b80b4 Mon Sep 17 00:00:00 2001 From: tyranron Date: Wed, 20 Sep 2023 14:02:15 +0300 Subject: [PATCH] Update `compile_fail` tests --- impl/src/fmt/mod.rs | 14 ++++++++++---- .../debug/both_fmt_and_skip_on_field.stderr | 8 ++++---- .../debug/duplicate_fmt_on_struct.stderr | 6 +++--- tests/compile_fail/debug/unknown_attribute.stderr | 2 +- .../compile_fail/display/unknown_attribute.stderr | 2 +- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/impl/src/fmt/mod.rs b/impl/src/fmt/mod.rs index 35026538..baeaadbb 100644 --- a/impl/src/fmt/mod.rs +++ b/impl/src/fmt/mod.rs @@ -45,7 +45,10 @@ impl Parse for BoundsAttribute { { Ok(p) } else { - Err(syn::Error::new(p.span(), "only `bound(...)` allowed here")) + Err(syn::Error::new( + p.span(), + "unknown attribute argument, expected `bound(...)`", + )) } })?; @@ -360,12 +363,15 @@ struct ContainerAttributes { impl Parse for ContainerAttributes { fn parse(input: ParseStream<'_>) -> syn::Result { - >::parse(input).map(|v| match v { - Either::Left(bounds) => Self { bounds, fmt: None }, - Either::Right(fmt) => Self { + // We do check `FmtAttribute::check_legacy_fmt` eagerly here, because `Either` will swallow + // any error of the `Either::Left` if the `Either::Right` succeeds. + FmtAttribute::check_legacy_fmt(input)?; + >::parse(input).map(|v| match v { + Either::Left(fmt) => Self { bounds: BoundsAttribute::default(), fmt: Some(fmt), }, + Either::Right(bounds) => Self { bounds, fmt: None }, }) } } diff --git a/tests/compile_fail/debug/both_fmt_and_skip_on_field.stderr b/tests/compile_fail/debug/both_fmt_and_skip_on_field.stderr index 31167d3f..a777e3c0 100644 --- a/tests/compile_fail/debug/both_fmt_and_skip_on_field.stderr +++ b/tests/compile_fail/debug/both_fmt_and_skip_on_field.stderr @@ -1,5 +1,5 @@ -error: only single `#[debug(...)]` attribute is allowed here - --> tests/compile_fail/debug/both_fmt_and_skip_on_field.rs:3:7 +error: only single kind of `#[debug(...)]` attribute is allowed here + --> tests/compile_fail/debug/both_fmt_and_skip_on_field.rs:4:5 | -3 | #[debug("Stuff({}): {}", bar)] - | ^^^^^ +4 | #[debug(skip)] + | ^ diff --git a/tests/compile_fail/debug/duplicate_fmt_on_struct.stderr b/tests/compile_fail/debug/duplicate_fmt_on_struct.stderr index ad98a725..ffc7a0ad 100644 --- a/tests/compile_fail/debug/duplicate_fmt_on_struct.stderr +++ b/tests/compile_fail/debug/duplicate_fmt_on_struct.stderr @@ -1,5 +1,5 @@ error: multiple `#[debug("...", ...)]` attributes aren't allowed - --> tests/compile_fail/debug/duplicate_fmt_on_struct.rs:2:9 + --> tests/compile_fail/debug/duplicate_fmt_on_struct.rs:3:1 | -2 | #[debug("Test")] - | ^^^^^^ +3 | #[debug("Second")] + | ^ diff --git a/tests/compile_fail/debug/unknown_attribute.stderr b/tests/compile_fail/debug/unknown_attribute.stderr index 63b18964..1820df7b 100644 --- a/tests/compile_fail/debug/unknown_attribute.stderr +++ b/tests/compile_fail/debug/unknown_attribute.stderr @@ -1,4 +1,4 @@ -error: unknown attribute, expected `bound(...)` +error: unknown attribute argument, expected `bound(...)` --> tests/compile_fail/debug/unknown_attribute.rs:2:9 | 2 | #[debug(unknown = "unknown")] diff --git a/tests/compile_fail/display/unknown_attribute.stderr b/tests/compile_fail/display/unknown_attribute.stderr index 5750586c..be551fc0 100644 --- a/tests/compile_fail/display/unknown_attribute.stderr +++ b/tests/compile_fail/display/unknown_attribute.stderr @@ -1,4 +1,4 @@ -error: unknown attribute, expected `bound(...)` +error: unknown attribute argument, expected `bound(...)` --> tests/compile_fail/display/unknown_attribute.rs:3:11 | 3 | #[display(unknown = "unknown")]