1From 1d2c6fa2ea2f3ab560c30c631fdde0034f5789a4 Mon Sep 17 00:00:00 2001
2From: Matthew Maurer <[email protected]>
3Date: Mon, 3 Apr 2023 16:13:04 +0000
4Subject: [PATCH] Update to syn-2
5
6Bug: 276463929
7Test: m
8Change-Id: If2f4b9e451716cae4e7cc5d037764de4582aa761
9---
10 src/lib.rs        | 20 ++++++++------------
11 src/test.rs       | 31 -------------------------------
12 tests/issue-16.rs |  9 +++++++++
13 3 files changed, 17 insertions(+), 43 deletions(-)
14 delete mode 100644 src/test.rs
15 create mode 100644 tests/issue-16.rs
16
17diff --git a/src/lib.rs b/src/lib.rs
18index ef55e4b..0b821f9 100644
19--- a/src/lib.rs
20+++ b/src/lib.rs
21@@ -170,16 +170,14 @@ impl NumTraits {
22         // retrieve its value, and use it to create an `Ident` to be used
23         // to import the `num_traits` crate.
24         for attr in &ast.attrs {
25-            if let Ok(syn::Meta::NameValue(mnv)) = attr.parse_meta() {
26-                if mnv.path.is_ident("num_traits") {
27-                    if let syn::Lit::Str(lit_str) = mnv.lit {
28-                        return NumTraits {
29-                            import: syn::Ident::new(&lit_str.value(), lit_str.span()),
30-                            explicit: true,
31-                        };
32-                    } else {
33-                        panic!("#[num_traits] attribute value must be a str");
34-                    }
35+            if attr.path().is_ident("num_traits") {
36+                if let syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Str(ref lit_str), .. }) = attr.meta.require_name_value().unwrap().value {
37+                  return NumTraits {
38+                      import: syn::Ident::new(&lit_str.value(), lit_str.span()),
39+                      explicit: true,
40+                  }
41+                } else {
42+                    panic!("#[num_traits] attribute value must be a str");
43                 }
44             }
45         }
46@@ -954,5 +952,3 @@ pub fn float(input: TokenStream) -> TokenStream {
47
48     import.wrap("Float", &name, impl_).into()
49 }
50-
51-mod test;
52diff --git a/src/test.rs b/src/test.rs
53deleted file mode 100644
54index c4cd7fe..0000000
55--- a/src/test.rs
56+++ /dev/null
57@@ -1,31 +0,0 @@
58-//! This module uses doc-tests on modules for `compile_fail`
59-
60-// We need "syn/full" to parse macros.
61-// Use `--nocapture` to check the quality of the error message.
62-#[cfg(not(feature = "full-syntax"))]
63-/// ```compile_fail
64-/// macro_rules! get_an_isize {
65-///     () => (0_isize)
66-/// }
67-///
68-/// #[derive(num_derive::FromPrimitive)]
69-/// pub enum CLikeEnum {
70-///     VarA = get_an_isize!(), // error without "syn/full"
71-///     VarB = 2,
72-/// }
73-/// ```
74-mod issue16 {}
75-
76-#[cfg(feature = "full-syntax")]
77-/// ```
78-/// macro_rules! get_an_isize {
79-///     () => (0_isize)
80-/// }
81-///
82-/// #[derive(num_derive::FromPrimitive)]
83-/// pub enum CLikeEnum {
84-///     VarA = get_an_isize!(), // ok with "syn/full"
85-///     VarB = 2,
86-/// }
87-/// ```
88-mod issue16 {}
89diff --git a/tests/issue-16.rs b/tests/issue-16.rs
90new file mode 100644
91index 0000000..0db3b6f
92--- /dev/null
93+++ b/tests/issue-16.rs
94@@ -0,0 +1,9 @@
95+macro_rules! get_an_isize {
96+    () => (0_isize)
97+}
98+
99+#[derive(num_derive::FromPrimitive)]
100+pub enum CLikeEnum {
101+    VarA = get_an_isize!(),
102+    VarB = 2,
103+}
104diff --git b/Cargo.toml a/Cargo.toml
105index 90c5d27..d0ccb4b 100644
106--- b/Cargo.toml
107+++ a/Cargo.toml
108@@ -44,7 +44,7 @@ version = "1"
109 version = "1"
110
111 [dependencies.syn]
112-version = "1"
113+version = "2"
114 [dev-dependencies.num]
115 version = "0.3"
116
117--
1182.40.0.348.gf938b09366-goog
119
120