aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Maurer <mmaurer@google.com>2023-05-27 00:57:43 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-05-27 00:57:43 +0000
commitd11887ffec7705f36bffc9b1a3e93bc82ca3c29a (patch)
tree013695c6c3323ccdb9c6dccb7357753d563bcf9e
parenta5e9676fa6c5f27c82fe23f13c3534af7e977817 (diff)
parent8ebd4e87c098338018fc02c3d79ac2374e58a2f0 (diff)
downloadnum-derive-d11887ffec7705f36bffc9b1a3e93bc82ca3c29a.tar.gz
Update to syn-2 am: 559b5f3107 am: fd2dcef001 am: fe0607416e am: 8ebd4e87c0
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/num-derive/+/2520538 Change-Id: Ieb6e517f0df1d577a96cdc4939a988e228af7f84 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--Cargo.toml2
-rw-r--r--patches/syn-2.patch106
-rw-r--r--src/lib.rs20
-rw-r--r--src/test.rs31
-rw-r--r--tests/issue-16.rs9
5 files changed, 124 insertions, 44 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 90c5d27..d0ccb4b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -44,7 +44,7 @@ version = "1"
version = "1"
[dependencies.syn]
-version = "1"
+version = "2"
[dev-dependencies.num]
version = "0.3"
diff --git a/patches/syn-2.patch b/patches/syn-2.patch
new file mode 100644
index 0000000..987faa3
--- /dev/null
+++ b/patches/syn-2.patch
@@ -0,0 +1,106 @@
+From 1d2c6fa2ea2f3ab560c30c631fdde0034f5789a4 Mon Sep 17 00:00:00 2001
+From: Matthew Maurer <mmaurer@google.com>
+Date: Mon, 3 Apr 2023 16:13:04 +0000
+Subject: [PATCH] Update to syn-2
+
+Bug: 276463929
+Test: m
+Change-Id: If2f4b9e451716cae4e7cc5d037764de4582aa761
+---
+ src/lib.rs | 20 ++++++++------------
+ src/test.rs | 31 -------------------------------
+ tests/issue-16.rs | 9 +++++++++
+ 3 files changed, 17 insertions(+), 43 deletions(-)
+ delete mode 100644 src/test.rs
+ create mode 100644 tests/issue-16.rs
+
+diff --git a/src/lib.rs b/src/lib.rs
+index ef55e4b..0b821f9 100644
+--- a/src/lib.rs
++++ b/src/lib.rs
+@@ -170,16 +170,14 @@ impl NumTraits {
+ // retrieve its value, and use it to create an `Ident` to be used
+ // to import the `num_traits` crate.
+ for attr in &ast.attrs {
+- if let Ok(syn::Meta::NameValue(mnv)) = attr.parse_meta() {
+- if mnv.path.is_ident("num_traits") {
+- if let syn::Lit::Str(lit_str) = mnv.lit {
+- return NumTraits {
+- import: syn::Ident::new(&lit_str.value(), lit_str.span()),
+- explicit: true,
+- };
+- } else {
+- panic!("#[num_traits] attribute value must be a str");
+- }
++ if attr.path().is_ident("num_traits") {
++ if let syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Str(ref lit_str), .. }) = attr.meta.require_name_value().unwrap().value {
++ return NumTraits {
++ import: syn::Ident::new(&lit_str.value(), lit_str.span()),
++ explicit: true,
++ }
++ } else {
++ panic!("#[num_traits] attribute value must be a str");
+ }
+ }
+ }
+@@ -954,5 +952,3 @@ pub fn float(input: TokenStream) -> TokenStream {
+
+ import.wrap("Float", &name, impl_).into()
+ }
+-
+-mod test;
+diff --git a/src/test.rs b/src/test.rs
+deleted file mode 100644
+index c4cd7fe..0000000
+--- a/src/test.rs
++++ /dev/null
+@@ -1,31 +0,0 @@
+-//! This module uses doc-tests on modules for `compile_fail`
+-
+-// We need "syn/full" to parse macros.
+-// Use `--nocapture` to check the quality of the error message.
+-#[cfg(not(feature = "full-syntax"))]
+-/// ```compile_fail
+-/// macro_rules! get_an_isize {
+-/// () => (0_isize)
+-/// }
+-///
+-/// #[derive(num_derive::FromPrimitive)]
+-/// pub enum CLikeEnum {
+-/// VarA = get_an_isize!(), // error without "syn/full"
+-/// VarB = 2,
+-/// }
+-/// ```
+-mod issue16 {}
+-
+-#[cfg(feature = "full-syntax")]
+-/// ```
+-/// macro_rules! get_an_isize {
+-/// () => (0_isize)
+-/// }
+-///
+-/// #[derive(num_derive::FromPrimitive)]
+-/// pub enum CLikeEnum {
+-/// VarA = get_an_isize!(), // ok with "syn/full"
+-/// VarB = 2,
+-/// }
+-/// ```
+-mod issue16 {}
+diff --git a/tests/issue-16.rs b/tests/issue-16.rs
+new file mode 100644
+index 0000000..0db3b6f
+--- /dev/null
++++ b/tests/issue-16.rs
+@@ -0,0 +1,9 @@
++macro_rules! get_an_isize {
++ () => (0_isize)
++}
++
++#[derive(num_derive::FromPrimitive)]
++pub enum CLikeEnum {
++ VarA = get_an_isize!(),
++ VarB = 2,
++}
+--
+2.40.0.348.gf938b09366-goog
+
diff --git a/src/lib.rs b/src/lib.rs
index ef55e4b..0b821f9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -170,16 +170,14 @@ impl NumTraits {
// retrieve its value, and use it to create an `Ident` to be used
// to import the `num_traits` crate.
for attr in &ast.attrs {
- if let Ok(syn::Meta::NameValue(mnv)) = attr.parse_meta() {
- if mnv.path.is_ident("num_traits") {
- if let syn::Lit::Str(lit_str) = mnv.lit {
- return NumTraits {
- import: syn::Ident::new(&lit_str.value(), lit_str.span()),
- explicit: true,
- };
- } else {
- panic!("#[num_traits] attribute value must be a str");
- }
+ if attr.path().is_ident("num_traits") {
+ if let syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Str(ref lit_str), .. }) = attr.meta.require_name_value().unwrap().value {
+ return NumTraits {
+ import: syn::Ident::new(&lit_str.value(), lit_str.span()),
+ explicit: true,
+ }
+ } else {
+ panic!("#[num_traits] attribute value must be a str");
}
}
}
@@ -954,5 +952,3 @@ pub fn float(input: TokenStream) -> TokenStream {
import.wrap("Float", &name, impl_).into()
}
-
-mod test;
diff --git a/src/test.rs b/src/test.rs
deleted file mode 100644
index c4cd7fe..0000000
--- a/src/test.rs
+++ /dev/null
@@ -1,31 +0,0 @@
-//! This module uses doc-tests on modules for `compile_fail`
-
-// We need "syn/full" to parse macros.
-// Use `--nocapture` to check the quality of the error message.
-#[cfg(not(feature = "full-syntax"))]
-/// ```compile_fail
-/// macro_rules! get_an_isize {
-/// () => (0_isize)
-/// }
-///
-/// #[derive(num_derive::FromPrimitive)]
-/// pub enum CLikeEnum {
-/// VarA = get_an_isize!(), // error without "syn/full"
-/// VarB = 2,
-/// }
-/// ```
-mod issue16 {}
-
-#[cfg(feature = "full-syntax")]
-/// ```
-/// macro_rules! get_an_isize {
-/// () => (0_isize)
-/// }
-///
-/// #[derive(num_derive::FromPrimitive)]
-/// pub enum CLikeEnum {
-/// VarA = get_an_isize!(), // ok with "syn/full"
-/// VarB = 2,
-/// }
-/// ```
-mod issue16 {}
diff --git a/tests/issue-16.rs b/tests/issue-16.rs
new file mode 100644
index 0000000..0db3b6f
--- /dev/null
+++ b/tests/issue-16.rs
@@ -0,0 +1,9 @@
+macro_rules! get_an_isize {
+ () => (0_isize)
+}
+
+#[derive(num_derive::FromPrimitive)]
+pub enum CLikeEnum {
+ VarA = get_an_isize!(),
+ VarB = 2,
+}