diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
commit | dc0db358abe19481e475e10c32149b53370f1a1c (patch) | |
tree | ab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/serde_derive/src/internals | |
parent | Releasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff) | |
download | rustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip |
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/serde_derive/src/internals')
-rw-r--r-- | vendor/serde_derive/src/internals/ast.rs | 17 | ||||
-rw-r--r-- | vendor/serde_derive/src/internals/attr.rs | 9 | ||||
-rw-r--r-- | vendor/serde_derive/src/internals/ctxt.rs | 17 |
3 files changed, 36 insertions, 7 deletions
diff --git a/vendor/serde_derive/src/internals/ast.rs b/vendor/serde_derive/src/internals/ast.rs index 2a6950b2a..8bcb0ecd1 100644 --- a/vendor/serde_derive/src/internals/ast.rs +++ b/vendor/serde_derive/src/internals/ast.rs @@ -140,7 +140,7 @@ fn enum_from_ast<'a>( variants: &'a Punctuated<syn::Variant, Token![,]>, container_default: &attr::Default, ) -> Vec<Variant<'a>> { - variants + let variants: Vec<Variant> = variants .iter() .map(|variant| { let attrs = attr::Variant::from_ast(cx, variant); @@ -154,7 +154,20 @@ fn enum_from_ast<'a>( original: variant, } }) - .collect() + .collect(); + + let index_of_last_tagged_variant = variants + .iter() + .rposition(|variant| !variant.attrs.untagged()); + if let Some(index_of_last_tagged_variant) = index_of_last_tagged_variant { + for variant in &variants[..index_of_last_tagged_variant] { + if variant.attrs.untagged() { + cx.error_spanned_by(&variant.ident, "all variants with the #[serde(untagged)] attribute must be placed at the end of the enum"); + } + } + } + + variants } fn struct_from_ast<'a>( diff --git a/vendor/serde_derive/src/internals/attr.rs b/vendor/serde_derive/src/internals/attr.rs index b0a7d08a2..bff82191b 100644 --- a/vendor/serde_derive/src/internals/attr.rs +++ b/vendor/serde_derive/src/internals/attr.rs @@ -740,6 +740,7 @@ pub struct Variant { serialize_with: Option<syn::ExprPath>, deserialize_with: Option<syn::ExprPath>, borrow: Option<BorrowAttribute>, + untagged: bool, } struct BorrowAttribute { @@ -762,6 +763,7 @@ impl Variant { let mut serialize_with = Attr::none(cx, SERIALIZE_WITH); let mut deserialize_with = Attr::none(cx, DESERIALIZE_WITH); let mut borrow = Attr::none(cx, BORROW); + let mut untagged = BoolAttr::none(cx, UNTAGGED); for attr in &variant.attrs { if attr.path() != SERDE { @@ -879,6 +881,8 @@ impl Variant { cx.error_spanned_by(variant, msg); } } + } else if meta.path == UNTAGGED { + untagged.set_true(&meta.path); } else { let path = meta.path.to_token_stream().to_string().replace(' ', ""); return Err( @@ -905,6 +909,7 @@ impl Variant { serialize_with: serialize_with.get(), deserialize_with: deserialize_with.get(), borrow: borrow.get(), + untagged: untagged.get(), } } @@ -956,6 +961,10 @@ impl Variant { pub fn deserialize_with(&self) -> Option<&syn::ExprPath> { self.deserialize_with.as_ref() } + + pub fn untagged(&self) -> bool { + self.untagged + } } /// Represents field attribute information diff --git a/vendor/serde_derive/src/internals/ctxt.rs b/vendor/serde_derive/src/internals/ctxt.rs index d692c2a44..707bed90e 100644 --- a/vendor/serde_derive/src/internals/ctxt.rs +++ b/vendor/serde_derive/src/internals/ctxt.rs @@ -44,12 +44,19 @@ impl Ctxt { } /// Consume this object, producing a formatted error string if there are errors. - pub fn check(self) -> Result<(), Vec<syn::Error>> { - let errors = self.errors.borrow_mut().take().unwrap(); - match errors.len() { - 0 => Ok(()), - _ => Err(errors), + pub fn check(self) -> syn::Result<()> { + let mut errors = self.errors.borrow_mut().take().unwrap().into_iter(); + + let mut combined = match errors.next() { + Some(first) => first, + None => return Ok(()), + }; + + for rest in errors { + combined.combine(rest); } + + Err(combined) } } |