summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Maurer <mmaurer@google.com>2023-05-26 20:22:58 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-05-26 20:22:58 +0000
commitbe25b90aad1eaa539689ad652788477bd1777745 (patch)
treea63a78509e14b80610fa5ed48ae0ea66cd4f7d02
parent4b6ebb93d4d9794a3c7dff2a10b14e674fcb1376 (diff)
parentf5bc07ca72de897d88e379765b2f7197de25041a (diff)
downloadzerocopy-derive-be25b90aad1eaa539689ad652788477bd1777745.tar.gz
Update to syn-2 am: f5bc07ca72
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/zerocopy-derive/+/2520656 Change-Id: I09acbc32196b8f68c35248320f0a52201a6a5579 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--Cargo.toml2
-rw-r--r--Cargo.toml.orig42
-rw-r--r--src/repr.rs55
3 files changed, 57 insertions, 42 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 1f7ec41..b00e3c3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -29,7 +29,7 @@ version = "1.0.1"
version = "1.0.10"
[dependencies.syn]
-version = "1.0.5"
+version = "2"
features = ["visit"]
[dev-dependencies.rustversion]
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 1ba3b12..1f7ec41 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,29 +1,39 @@
-# Copyright 2019 The Fuchsia Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-# This file is used when publishing to crates.io
+# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
+#
+# When uploading crates to the registry Cargo will automatically
+# "normalize" Cargo.toml files for maximal compatibility
+# with all versions of Cargo and also rewrite `path` dependencies
+# to registry (e.g., crates.io) dependencies.
+#
+# If you are reading this file be aware that the original Cargo.toml
+# will likely look very different (and much more reasonable).
+# See Cargo.toml.orig for the original contents.
[package]
edition = "2018"
name = "zerocopy-derive"
version = "0.3.2"
authors = ["Joshua Liebow-Feeser <joshlf@google.com>"]
+exclude = [".*"]
description = "Custom derive for traits from the zerocopy crate"
-license-file = "../LICENSE"
+license-file = "LICENSE"
repository = "https://github.com/google/zerocopy"
-exclude = [".*"]
-
[lib]
proc-macro = true
-[dependencies]
-proc-macro2 = "1.0.1"
-quote = "1.0.10"
-syn = { version = "1.0.5", features = ["visit"] }
+[dependencies.proc-macro2]
+version = "1.0.1"
+
+[dependencies.quote]
+version = "1.0.10"
+
+[dependencies.syn]
+version = "1.0.5"
+features = ["visit"]
+
+[dev-dependencies.rustversion]
+version = "1.0"
-[dev-dependencies]
-rustversion = "1.0"
-trybuild = "1.0"
-zerocopy = { path = "../" }
+[dev-dependencies.trybuild]
+version = "1.0"
diff --git a/src/repr.rs b/src/repr.rs
index 6ded70b..5bd4a8a 100644
--- a/src/repr.rs
+++ b/src/repr.rs
@@ -6,8 +6,10 @@ use core::fmt::{self, Display, Formatter};
use {
proc_macro2::Span,
+ syn::punctuated::Punctuated,
syn::spanned::Spanned,
- syn::{Attribute, DeriveInput, Error, Lit, Meta, NestedMeta},
+ syn::token::Comma,
+ syn::{Attribute, DeriveInput, Error, LitInt, Meta},
};
pub struct Config<Repr: KindRepr> {
@@ -44,11 +46,11 @@ impl<R: KindRepr> Config<R> {
/// stripped out of the returned value since no callers care about them.
pub fn validate_reprs(&self, input: &DeriveInput) -> Result<Vec<R>, Vec<Error>> {
let mut metas_reprs = reprs(&input.attrs)?;
- metas_reprs.sort_by(|a: &(NestedMeta, R), b| a.1.partial_cmp(&b.1).unwrap());
+ metas_reprs.sort_by(|a: &(_, R), b| a.1.partial_cmp(&b.1).unwrap());
if self.derive_unaligned {
if let Some((meta, _)) =
- metas_reprs.iter().find(|&repr: &&(NestedMeta, R)| repr.1.is_align_gt_one())
+ metas_reprs.iter().find(|&repr: &&(_, R)| repr.1.is_align_gt_one())
{
return Err(vec![Error::new_spanned(
meta,
@@ -95,7 +97,7 @@ impl<R: KindRepr> Config<R> {
pub trait KindRepr: 'static + Sized + Ord {
fn is_align(&self) -> bool;
fn is_align_gt_one(&self) -> bool;
- fn parse(meta: &NestedMeta) -> syn::Result<Self>;
+ fn parse(meta: &Meta) -> syn::Result<Self>;
}
// Defines an enum for reprs which are valid for a given kind (structs, enums,
@@ -124,8 +126,8 @@ macro_rules! define_kind_specific_repr {
}
}
- fn parse(meta: &NestedMeta) -> syn::Result<$repr_name> {
- match Repr::from_nested_meta(meta)? {
+ fn parse(meta: &Meta) -> syn::Result<$repr_name> {
+ match Repr::from_meta(meta)? {
$(Repr::$repr_variant => Ok($repr_name::$repr_variant),)*
Repr::Align(u) => Ok($repr_name::Align(u)),
_ => Err(Error::new_spanned(meta, concat!("unsupported representation for deriving FromBytes, AsBytes, or Unaligned on ", $type_name)))
@@ -183,9 +185,9 @@ pub enum Repr {
}
impl Repr {
- fn from_nested_meta(meta: &NestedMeta) -> Result<Repr, Error> {
+ fn from_meta(meta: &Meta) -> Result<Repr, Error> {
match meta {
- NestedMeta::Meta(Meta::Path(path)) => {
+ Meta::Path(path) => {
let ident = path
.get_ident()
.ok_or_else(|| Error::new_spanned(meta, "unrecognized representation hint"))?;
@@ -206,12 +208,8 @@ impl Repr {
_ => {}
}
}
- NestedMeta::Meta(Meta::List(list)) => {
- if let [&NestedMeta::Lit(Lit::Int(ref n))] =
- list.nested.iter().collect::<Vec<_>>().as_slice()
- {
- return Ok(Repr::Align(n.base10_parse::<u64>()?));
- }
+ Meta::List(list) => {
+ return Ok(Repr::Align(list.parse_args::<LitInt>()?.base10_parse::<u64>()?))
}
_ => {}
}
@@ -248,27 +246,34 @@ impl Display for Repr {
}
}
-fn reprs<R: KindRepr>(attrs: &[Attribute]) -> Result<Vec<(NestedMeta, R)>, Vec<Error>> {
+fn reprs<R: KindRepr>(attrs: &[Attribute]) -> Result<Vec<(Meta, R)>, Vec<Error>> {
let mut reprs = Vec::new();
let mut errors = Vec::new();
for attr in attrs {
// Ignore documentation attributes.
- if attr.path.is_ident("doc") {
+ if attr.path().is_ident("doc") {
continue;
}
- match attr.parse_meta() {
- Ok(Meta::List(meta_list)) => {
- if meta_list.path.is_ident("repr") {
- for nested_meta in &meta_list.nested {
- match R::parse(nested_meta) {
- Ok(repr) => reprs.push((nested_meta.clone(), repr)),
- Err(err) => errors.push(err),
+ if let Meta::List(ref meta_list) = attr.meta {
+ if meta_list.path.is_ident("repr") {
+ let parsed: Punctuated<Meta, Comma> =
+ match meta_list.parse_args_with(Punctuated::parse_terminated) {
+ Ok(parsed) => parsed,
+ Err(_) => {
+ errors.push(Error::new_spanned(
+ &meta_list.tokens,
+ "unrecognized representation hint",
+ ));
+ continue;
}
+ };
+ for meta in parsed {
+ match R::parse(&meta) {
+ Ok(repr) => reprs.push((meta, repr)),
+ Err(err) => errors.push(err),
}
}
}
- Err(e) => errors.push(e),
- _ => {}
}
}