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:
Samson 2023-09-19 17:57:37 +02:00 committed by GitHub
parent 7caac9790d
commit 8b30d1a4b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 57 additions and 54 deletions

36
Cargo.lock generated
View file

@ -1275,8 +1275,8 @@ dependencies = [
name = "deny_public_fields"
version = "0.0.1"
dependencies = [
"syn 1.0.103",
"synstructure",
"syn 2.0.32",
"synstructure 0.13.0",
]
[[package]]
@ -1294,7 +1294,7 @@ dependencies = [
"proc-macro2",
"quote",
"syn 1.0.103",
"synstructure",
"synstructure 0.12.6",
]
[[package]]
@ -1408,7 +1408,7 @@ name = "dom_struct"
version = "0.0.1"
dependencies = [
"quote",
"syn 1.0.103",
"syn 2.0.32",
]
[[package]]
@ -1417,7 +1417,7 @@ version = "0.0.1"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.103",
"syn 2.0.32",
]
[[package]]
@ -2981,8 +2981,8 @@ name = "jstraceable_derive"
version = "0.0.1"
dependencies = [
"proc-macro2",
"syn 1.0.103",
"synstructure",
"syn 2.0.32",
"synstructure 0.13.0",
]
[[package]]
@ -3449,7 +3449,7 @@ checksum = "632647502a8bfa82458c07134791fffa7a719f00427d1afd79c3cb6d4960a982"
dependencies = [
"proc-macro2",
"syn 1.0.103",
"synstructure",
"synstructure 0.12.6",
]
[[package]]
@ -4239,7 +4239,7 @@ dependencies = [
"proc-macro2",
"quote",
"syn 1.0.103",
"synstructure",
"synstructure 0.12.6",
"unicode-xid",
]
@ -5376,7 +5376,7 @@ dependencies = [
"itertools",
"proc-macro2",
"quote",
"syn 1.0.103",
"syn 2.0.32",
]
[[package]]
@ -5840,7 +5840,7 @@ dependencies = [
"proc-macro2",
"quote",
"syn 1.0.103",
"synstructure",
"synstructure 0.12.6",
]
[[package]]
@ -5969,6 +5969,18 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "synstructure"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "285ba80e733fac80aa4270fbcdf83772a79b80aa35c97075320abfee4a915b06"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.32",
"unicode-xid",
]
[[package]]
name = "take_mut"
version = "0.2.2"
@ -6169,7 +6181,7 @@ dependencies = [
"proc-macro2",
"quote",
"syn 1.0.103",
"synstructure",
"synstructure 0.12.6",
]
[[package]]

View file

@ -75,8 +75,8 @@ string_cache = "0.8"
string_cache_codegen = "0.5"
# NOTE: the sm-angle feature only enables ANGLE on Windows, not other platforms!
surfman = { version = "0.8", features = ["chains", "sm-angle", "sm-angle-default"] }
syn = { version = "1", default-features = false, features = ["clone-impls", "derive", "parsing"] }
synstructure = "0.12"
syn = { version = "2", default-features = false, features = ["clone-impls", "derive", "parsing"] }
synstructure = "0.13"
time = "0.1.41"
tokio = "1"
tokio-rustls = "0.24"

View file

@ -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 {

View file

@ -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)?,
})
}
}

View file

@ -13,5 +13,5 @@ path = "lib.rs"
darling = { workspace = true }
proc-macro2 = { workspace = true }
quote = { workspace = true }
syn = { workspace = true }
synstructure = { workspace = true }
syn = { version = "1", default-features = false, features = ["clone-impls", "derive", "parsing"] }
synstructure = "0.12"

View file

@ -149,21 +149,15 @@ fn js_traceable_derive(s: synstructure::Structure) -> proc_macro2::TokenStream {
let mut asserts = quote!();
let match_body = s.each(|binding| {
for attr in binding.ast().attrs.iter() {
match attr.parse_meta().unwrap() {
syn::Meta::Path(ref path) | syn::Meta::List(syn::MetaList { ref path, .. }) => {
if path.is_ident("no_trace") {
asserts.extend(assert_not_impl_traceable(&binding.ast().ty));
return None;
} else if path.is_ident("custom_trace") {
return Some(quote!(<crate::dom::bindings::trace::CustomTraceable>::trace(#binding, tracer);));
}
},
syn::Meta::NameValue(syn::MetaNameValue { ref path, .. }) => {
// if reason provided we can skip JSTraceable check
if path.is_ident("no_trace") {
return None;
}
},
if attr.path().is_ident("no_trace") {
// If no reason argument is provided to `no_trace` (ie `#[no_trace="This types does not need..."]`),
// assert that the type in this bound field does not implement traceable.
if !matches!(attr.meta, syn::Meta::NameValue(_)) {
asserts.extend(assert_not_impl_traceable(&binding.ast().ty));
}
return None;
} else if attr.path().is_ident("custom_trace") {
return Some(quote!(<crate::dom::bindings::trace::CustomTraceable>::trace(#binding, tracer);));
}
}
Some(quote!(#binding.trace(tracer);))

View file

@ -15,5 +15,5 @@ darling = { workspace = true }
derive_common = { path = "../derive_common" }
proc-macro2 = { workspace = true }
quote = { workspace = true }
syn = { workspace = true }
synstructure = { workspace = true }
syn = { version = "1", default-features = false, features = ["clone-impls", "derive", "parsing"] }
synstructure = "0.12"

View file

@ -67,7 +67,10 @@ packages = [
"foreign-types-shared",
"metal",
"paste",
# Duplicated by Gecko crates that haven't been updated yet (style, shmem, derive_common, ...).
"syn",
"synstructure",
# style/webxr (0.62) vs. mozjs_sys (0.66)
"bindgen",