mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Update to syn 2 where possible (#30387)
* Update to syn 2 where possible * Cleanups * Better no_trace comment Co-authored-by: Martin Robinson <mrobinson@igalia.com> --------- Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
7caac9790d
commit
8b30d1a4b2
8 changed files with 57 additions and 54 deletions
|
@ -13,10 +13,7 @@ use proc_macro2::{Span, TokenStream};
|
|||
use quote::*;
|
||||
use syn::parse::Result;
|
||||
use syn::spanned::Spanned;
|
||||
use syn::{
|
||||
parse_macro_input, Attribute, Ident, Lit, LitStr, Meta, MetaList, MetaNameValue, NestedMeta,
|
||||
Path,
|
||||
};
|
||||
use syn::{parse_macro_input, Attribute, Ident, LitStr, Path};
|
||||
|
||||
mod parse;
|
||||
use parse::*;
|
||||
|
@ -199,23 +196,19 @@ impl Field {
|
|||
}
|
||||
|
||||
fn attr_to_pref_name(attr: &Attribute) -> Option<LitStr> {
|
||||
attr.parse_meta().ok().and_then(|meta| {
|
||||
if let Meta::List(MetaList { path, nested, .. }) = meta {
|
||||
if path.is_ident("serde") {
|
||||
if let Some(NestedMeta::Meta(Meta::NameValue(MetaNameValue {
|
||||
ref path,
|
||||
lit: Lit::Str(val),
|
||||
..
|
||||
}))) = nested.iter().next()
|
||||
{
|
||||
if path.is_ident("rename") {
|
||||
return Some(val.clone());
|
||||
}
|
||||
}
|
||||
if attr.path().is_ident("serde") {
|
||||
// If `parse_nested_meta()` fails, `result` will remain None.
|
||||
let mut result = None;
|
||||
let _ = attr.parse_nested_meta(|meta| {
|
||||
if meta.path.is_ident("rename") {
|
||||
result = Some(meta.value()?.parse()?);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
result
|
||||
} else {
|
||||
None
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn err<S: Spanned>(s: S, msg: &str) -> syn::Error {
|
||||
|
|
|
@ -56,7 +56,8 @@ pub struct RootTypeDef {
|
|||
|
||||
impl Parse for MacroInput {
|
||||
fn parse(input: ParseStream<'_>) -> Result<Self> {
|
||||
let fields: Punctuated<MacroArg, Token![, ]> = input.parse_terminated(MacroArg::parse)?;
|
||||
let fields: Punctuated<MacroArg, Token![, ]> =
|
||||
Punctuated::parse_terminated_with(input, MacroArg::parse)?;
|
||||
let mut gen_accessors = None;
|
||||
let mut type_def = None;
|
||||
let mut accessor_type = None;
|
||||
|
@ -134,7 +135,7 @@ impl Parse for NewTypeDef {
|
|||
#[allow(clippy::eval_order_dependence)]
|
||||
Ok(NewTypeDef {
|
||||
_braces: braced!(content in input),
|
||||
fields: content.parse_terminated(Field::parse)?,
|
||||
fields: Punctuated::parse_terminated_with(&content, Field::parse)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue