From f72238fc65686bf1564515fcde4717bfc68da12f Mon Sep 17 00:00:00 2001 From: Gustavo Shigueo Date: Sun, 10 Nov 2024 23:04:25 -0300 Subject: [PATCH] Validate `optional_fields` compatibility with other attributes --- macros/src/attr/struct.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/macros/src/attr/struct.rs b/macros/src/attr/struct.rs index 2244f808..80d1e12f 100644 --- a/macros/src/attr/struct.rs +++ b/macros/src/attr/struct.rs @@ -108,6 +108,10 @@ impl Attr for StructAttr { if self.tag.is_some() { syn_err!("`tag` is not compatible with `type`"); } + + if let Optional::Optional { .. } = self.optional_fields { + syn_err!("`optional_fields` is not compatible with `type`"); + } } if self.type_as.is_some() { @@ -118,6 +122,10 @@ impl Attr for StructAttr { if self.rename_all.is_some() { syn_err!("`rename_all` is not compatible with `as`"); } + + if let Optional::Optional { .. } = self.optional_fields { + syn_err!("`optional_fields` is not compatible with `as`"); + } } if !matches!(item, Fields::Named(_)) { @@ -128,6 +136,10 @@ impl Attr for StructAttr { if self.rename_all.is_some() { syn_err!("`rename_all` cannot be used with unit or tuple structs"); } + + if let Optional::Optional { .. } = self.optional_fields { + syn_err!("`optional_fields` cannot be used with unit or tuple structs"); + } } Ok(())