Skip to content

Commit 297781f

Browse files
authored
chore(deps): update syn and darling (#400)
Update syn to 2.0.100 Update darling to 0.20
1 parent 2574e0b commit 297781f

File tree

8 files changed

+63
-57
lines changed

8 files changed

+63
-57
lines changed

crates/macros/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ edition = "2018"
1212
proc-macro = true
1313

1414
[dependencies]
15-
syn = { version = "1.0.68", features = ["full", "extra-traits", "printing"] }
16-
darling = "0.14"
15+
syn = { version = "2.0.100", features = ["full", "extra-traits", "printing"] }
16+
darling = "0.20"
1717
ident_case = "1.0.1"
1818
quote = "1.0.9"
1919
proc-macro2 = "1.0.26"

crates/macros/src/class.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
use darling::ast::NestedMeta;
12
use darling::{FromMeta, ToTokens};
23
use proc_macro2::{Ident, TokenStream};
34
use quote::quote;
45
use syn::parse::ParseStream;
5-
use syn::{Attribute, AttributeArgs, Expr, Fields, ItemStruct, LitStr, Token};
6+
use syn::{Attribute, Expr, Fields, ItemStruct, LitStr, Meta, Token};
67

78
use crate::helpers::get_docs;
89
use crate::prelude::*;
@@ -34,7 +35,9 @@ impl ClassAttrs {
3435
let mut unparsed = vec![];
3536
unparsed.append(attrs);
3637
for attr in unparsed {
37-
if attr.path.is_ident("extends") {
38+
let path = attr.path();
39+
40+
if path.is_ident("extends") {
3841
if self.extends.is_some() {
3942
bail!(attr => "Only one `#[extends]` attribute is valid per struct.");
4043
}
@@ -43,7 +46,7 @@ impl ClassAttrs {
4346
Err(_) => bail!(attr => "Invalid arguments passed to extends attribute."),
4447
};
4548
self.extends = Some(extends);
46-
} else if attr.path.is_ident("implements") {
49+
} else if path.is_ident("implements") {
4750
let implements: syn::Expr = match attr.parse_args() {
4851
Ok(extends) => extends,
4952
Err(_) => bail!(attr => "Invalid arguments passed to implements attribute."),
@@ -58,9 +61,10 @@ impl ClassAttrs {
5861
}
5962
}
6063

61-
pub fn parser(args: AttributeArgs, mut input: ItemStruct) -> Result<TokenStream> {
64+
pub fn parser(args: TokenStream, mut input: ItemStruct) -> Result<TokenStream> {
6265
let ident = &input.ident;
63-
let args = match StructArgs::from_list(&args) {
66+
let meta = NestedMeta::parse_meta_list(args)?;
67+
let args = match StructArgs::from_list(&meta) {
6468
Ok(args) => args,
6569
Err(e) => bail!("Failed to parse struct arguments: {:?}", e),
6670
};
@@ -189,7 +193,7 @@ pub enum ParsedAttribute {
189193
}
190194

191195
pub fn parse_attribute(attr: &Attribute) -> Result<Option<ParsedAttribute>> {
192-
let name = attr.path.to_token_stream().to_string();
196+
let name = attr.path().to_token_stream().to_string();
193197

194198
Ok(match name.as_ref() {
195199
"doc" => {
@@ -203,16 +207,19 @@ pub fn parse_attribute(attr: &Attribute) -> Result<Option<ParsedAttribute>> {
203207
}
204208
}
205209

206-
let comment: DocComment = syn::parse2(attr.tokens.clone())
210+
let comment: DocComment = syn::parse2(attr.to_token_stream())
207211
.map_err(|e| err!(attr => "Failed to parse doc comment {}", e))?;
208212
Some(ParsedAttribute::Comment(comment.0))
209213
}
210214
"prop" | "property" => {
211-
let attr = if attr.tokens.is_empty() {
212-
PropertyAttr::default()
213-
} else {
214-
attr.parse_args()
215-
.map_err(|e| err!(attr => "Unable to parse `#[{}]` attribute: {}", name, e))?
215+
let attr = match attr.meta {
216+
Meta::Path(_) => PropertyAttr::default(),
217+
Meta::List(_) => attr
218+
.parse_args()
219+
.map_err(|e| err!(attr => "Unable to parse `#[{}]` attribute: {}", name, e))?,
220+
_ => {
221+
bail!(attr => "Invalid attribute format for `#[{}]`", name);
222+
}
216223
};
217224

218225
Some(ParsedAttribute::Property(attr))

crates/macros/src/function.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use std::collections::HashMap;
22

3+
use darling::ast::NestedMeta;
34
use darling::{FromMeta, ToTokens};
45
use proc_macro2::{Ident, Span, TokenStream};
56
use quote::{format_ident, quote};
67
use syn::spanned::Spanned as _;
78
use syn::PatType;
8-
use syn::{AttributeArgs, FnArg, GenericArgument, ItemFn, Lit, PathArguments, Type, TypePath};
9+
use syn::{FnArg, GenericArgument, ItemFn, Lit, PathArguments, Type, TypePath};
910

1011
use crate::helpers::get_docs;
1112
use crate::prelude::*;
@@ -33,8 +34,9 @@ pub struct FnArgs {
3334
defaults: HashMap<Ident, Lit>,
3435
}
3536

36-
pub fn parser(opts: AttributeArgs, input: ItemFn) -> Result<TokenStream> {
37-
let opts = match FnArgs::from_list(&opts) {
37+
pub fn parser(opts: TokenStream, input: ItemFn) -> Result<TokenStream> {
38+
let meta = NestedMeta::parse_meta_list(opts)?;
39+
let opts = match FnArgs::from_list(&meta) {
3840
Ok(opts) => opts,
3941
Err(e) => bail!("Failed to parse attribute options: {:?}", e),
4042
};

crates/macros/src/impl_.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
use darling::ast::NestedMeta;
12
use darling::FromMeta;
23
use proc_macro2::TokenStream;
34
use quote::quote;
45
use std::collections::HashMap;
5-
use syn::{AttributeArgs, Ident, ItemImpl, Lit};
6+
use syn::{Ident, ItemImpl, Lit};
67

78
use crate::function::{Args, CallType, Function, MethodReceiver};
89
use crate::helpers::get_docs;
@@ -96,8 +97,9 @@ pub struct ImplArgs {
9697
rename_methods: RenameRule,
9798
}
9899

99-
pub fn parser(args: AttributeArgs, mut input: ItemImpl) -> Result<TokenStream> {
100-
let args = match ImplArgs::from_list(&args) {
100+
pub fn parser(args: TokenStream, mut input: ItemImpl) -> Result<TokenStream> {
101+
let meta = NestedMeta::parse_meta_list(args)?;
102+
let args = match ImplArgs::from_list(&meta) {
101103
Ok(args) => args,
102104
Err(e) => bail!(input => "Failed to parse impl attribute arguments: {:?}", e),
103105
};
@@ -153,49 +155,47 @@ impl MethodArgs {
153155
let mut unparsed = vec![];
154156
unparsed.append(attrs);
155157
for attr in unparsed {
156-
if attr.path.is_ident("optional") {
158+
let path = &attr.path();
159+
160+
if path.is_ident("optional") {
157161
// x
158162
if self.optional.is_some() {
159163
bail!(attr => "Only one `#[optional]` attribute is valid per method.");
160164
}
161165
let optional = attr.parse_args().map_err(
162-
|e| err!(attr => "Invalid arguments passed to `#[optional]` attribute. {}", e),
166+
|e| err!(e.span() => "Invalid arguments passed to `#[optional]` attribute. {}", e),
163167
)?;
164168
self.optional = Some(optional);
165-
} else if attr.path.is_ident("defaults") {
166-
// x
167-
let meta = attr
168-
.parse_meta()
169-
.map_err(|e| err!(attr => "Failed to parse metadata from attribute. {}", e))?;
170-
let defaults = HashMap::from_meta(&meta).map_err(
171-
|e| err!(attr => "Invalid arguments passed to `#[defaults]` attribute. {}", e),
169+
} else if path.is_ident("defaults") {
170+
let defaults = HashMap::from_meta(&attr.meta).map_err(
171+
|e| err!(e.span() => "Invalid arguments passed to `#[defaults]` attribute. {}", e),
172172
)?;
173173
self.defaults = defaults;
174-
} else if attr.path.is_ident("public") {
174+
} else if path.is_ident("public") {
175175
// x
176176
self.vis = MethodVis::Public;
177-
} else if attr.path.is_ident("protected") {
177+
} else if path.is_ident("protected") {
178178
// x
179179
self.vis = MethodVis::Protected;
180-
} else if attr.path.is_ident("private") {
180+
} else if path.is_ident("private") {
181181
// x
182182
self.vis = MethodVis::Private;
183-
} else if attr.path.is_ident("rename") {
183+
} else if path.is_ident("rename") {
184184
let lit: syn::Lit = attr.parse_args().map_err(|e| err!(attr => "Invalid arguments passed to the `#[rename]` attribute. {}", e))?;
185185
match lit {
186186
Lit::Str(name) => self.name = name.value(),
187187
_ => bail!(attr => "Only strings are valid method names."),
188188
};
189-
} else if attr.path.is_ident("getter") {
189+
} else if path.is_ident("getter") {
190190
// x
191191
self.ty = MethodTy::Getter;
192-
} else if attr.path.is_ident("setter") {
192+
} else if path.is_ident("setter") {
193193
// x
194194
self.ty = MethodTy::Setter;
195-
} else if attr.path.is_ident("constructor") {
195+
} else if path.is_ident("constructor") {
196196
// x
197197
self.ty = MethodTy::Constructor;
198-
} else if attr.path.is_ident("abstract_method") {
198+
} else if path.is_ident("abstract_method") {
199199
// x
200200
self.ty = MethodTy::Abstract;
201201
} else {
@@ -261,7 +261,7 @@ impl<'a> ParsedImpl<'a> {
261261
let mut unparsed = vec![];
262262
unparsed.append(&mut c.attrs);
263263
for attr in unparsed {
264-
if attr.path.is_ident("rename") {
264+
if attr.path().is_ident("rename") {
265265
let lit: syn::Lit = attr.parse_args().map_err(|e| err!(attr => "Invalid arguments passed to the `#[rename]` attribute. {}", e))?;
266266
match lit {
267267
Lit::Str(str) => name = Some(str.value()),
@@ -279,7 +279,7 @@ impl<'a> ParsedImpl<'a> {
279279
docs,
280280
});
281281
}
282-
syn::ImplItem::Method(method) => {
282+
syn::ImplItem::Fn(method) => {
283283
let name = self.rename.rename(method.sig.ident.to_string());
284284
let docs = get_docs(&method.attrs);
285285
let mut opts = MethodArgs::new(name);

crates/macros/src/lib.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ mod zval;
1212

1313
use proc_macro::TokenStream;
1414
use syn::{
15-
parse_macro_input, AttributeArgs, DeriveInput, ItemConst, ItemFn, ItemForeignMod, ItemImpl,
16-
ItemStruct,
15+
parse_macro_input, DeriveInput, ItemConst, ItemFn, ItemForeignMod, ItemImpl, ItemStruct,
1716
};
1817

1918
extern crate proc_macro;
@@ -195,10 +194,9 @@ extern crate proc_macro;
195194
/// ````
196195
#[proc_macro_attribute]
197196
pub fn php_class(args: TokenStream, input: TokenStream) -> TokenStream {
198-
let args = parse_macro_input!(args as AttributeArgs);
199197
let input = parse_macro_input!(input as ItemStruct);
200198

201-
class::parser(args, input)
199+
class::parser(args.into(), input)
202200
.unwrap_or_else(|e| e.to_compile_error())
203201
.into()
204202
}
@@ -357,10 +355,9 @@ pub fn php_class(args: TokenStream, input: TokenStream) -> TokenStream {
357355
/// [exceptions](../exceptions.md) for more details.
358356
#[proc_macro_attribute]
359357
pub fn php_function(args: TokenStream, input: TokenStream) -> TokenStream {
360-
let args = parse_macro_input!(args as AttributeArgs);
361358
let input = parse_macro_input!(input as ItemFn);
362359

363-
function::parser(args, input)
360+
function::parser(args.into(), input)
364361
.unwrap_or_else(|e| e.to_compile_error())
365362
.into()
366363
}
@@ -478,10 +475,9 @@ pub fn php_const(_args: TokenStream, input: TokenStream) -> TokenStream {
478475
/// ```
479476
#[proc_macro_attribute]
480477
pub fn php_module(args: TokenStream, input: TokenStream) -> TokenStream {
481-
let args = parse_macro_input!(args as AttributeArgs);
482478
let input = parse_macro_input!(input as ItemFn);
483479

484-
module::parser(args, input)
480+
module::parser(args.into(), input)
485481
.unwrap_or_else(|e| e.to_compile_error())
486482
.into()
487483
}
@@ -661,10 +657,9 @@ pub fn php_module(args: TokenStream, input: TokenStream) -> TokenStream {
661657
/// [`php_async_impl`]: ./async_impl.md
662658
#[proc_macro_attribute]
663659
pub fn php_impl(args: TokenStream, input: TokenStream) -> TokenStream {
664-
let args = parse_macro_input!(args as AttributeArgs);
665660
let input = parse_macro_input!(input as ItemImpl);
666661

667-
impl_::parser(args, input)
662+
impl_::parser(args.into(), input)
668663
.unwrap_or_else(|e| e.to_compile_error())
669664
.into()
670665
}

crates/macros/src/module.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use darling::FromMeta;
1+
use darling::{ast::NestedMeta, FromMeta};
22
use proc_macro2::{Ident, TokenStream};
33
use quote::quote;
4-
use syn::{AttributeArgs, ItemFn, Signature};
4+
use syn::{ItemFn, Signature};
55

66
use crate::prelude::*;
77

@@ -12,8 +12,9 @@ pub struct ModuleArgs {
1212
startup: Option<Ident>,
1313
}
1414

15-
pub fn parser(args: AttributeArgs, input: ItemFn) -> Result<TokenStream> {
16-
let opts = match ModuleArgs::from_list(&args) {
15+
pub fn parser(args: TokenStream, input: ItemFn) -> Result<TokenStream> {
16+
let meta = NestedMeta::parse_meta_list(args)?;
17+
let opts = match ModuleArgs::from_list(&meta) {
1718
Ok(opts) => opts,
1819
Err(e) => bail!(input => "Failed to parse attribute options: {:?}", e),
1920
};

crates/macros/src/syn_ext.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ impl DropLifetimes for syn::PathSegment {
101101
.filter_map(|mut i| {
102102
match &mut i {
103103
syn::GenericArgument::Type(t) => t.drop_lifetimes(),
104-
syn::GenericArgument::Binding(t) => t.drop_lifetimes(),
104+
syn::GenericArgument::AssocType(t) => t.drop_lifetimes(),
105105
syn::GenericArgument::Constraint(t) => t.drop_lifetimes(),
106106
syn::GenericArgument::Const(_) => {}
107+
syn::GenericArgument::AssocConst(_) => {}
107108
_ => return None,
108109
};
109110
Some(i)
@@ -113,7 +114,7 @@ impl DropLifetimes for syn::PathSegment {
113114
}
114115
}
115116

116-
impl DropLifetimes for syn::Binding {
117+
impl DropLifetimes for syn::AssocType {
117118
fn drop_lifetimes(&mut self) {
118119
self.ty.drop_lifetimes();
119120
}

crates/macros/src/zval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use proc_macro2::{Span, TokenStream};
33
use quote::quote;
44
use syn::{
55
token::Where, DataEnum, DataStruct, DeriveInput, GenericParam, Generics, Ident, ImplGenerics,
6-
Lifetime, LifetimeDef, TypeGenerics, Variant, WhereClause,
6+
Lifetime, LifetimeParam, TypeGenerics, Variant, WhereClause,
77
};
88

99
use crate::prelude::*;
@@ -31,7 +31,7 @@ pub fn parser(input: DeriveInput) -> Result<TokenStream> {
3131
let mut parsed: Generics = syn::parse2(tokens).expect("couldn't reparse generics");
3232
parsed
3333
.params
34-
.push(GenericParam::Lifetime(LifetimeDef::new(Lifetime::new(
34+
.push(GenericParam::Lifetime(LifetimeParam::new(Lifetime::new(
3535
"'_zval",
3636
Span::call_site(),
3737
))));

0 commit comments

Comments
 (0)