Skip to content

Commit

Permalink
Validate optional_fields compatibility with other attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavo-shigueo committed Nov 11, 2024
1 parent 033d096 commit f72238f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions macros/src/attr/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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(_)) {
Expand All @@ -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(())
Expand Down

0 comments on commit f72238f

Please sign in to comment.