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" name = "deny_public_fields"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"syn 1.0.103", "syn 2.0.32",
"synstructure", "synstructure 0.13.0",
] ]
[[package]] [[package]]
@ -1294,7 +1294,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 1.0.103", "syn 1.0.103",
"synstructure", "synstructure 0.12.6",
] ]
[[package]] [[package]]
@ -1408,7 +1408,7 @@ name = "dom_struct"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"quote", "quote",
"syn 1.0.103", "syn 2.0.32",
] ]
[[package]] [[package]]
@ -1417,7 +1417,7 @@ version = "0.0.1"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 1.0.103", "syn 2.0.32",
] ]
[[package]] [[package]]
@ -2981,8 +2981,8 @@ name = "jstraceable_derive"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"syn 1.0.103", "syn 2.0.32",
"synstructure", "synstructure 0.13.0",
] ]
[[package]] [[package]]
@ -3449,7 +3449,7 @@ checksum = "632647502a8bfa82458c07134791fffa7a719f00427d1afd79c3cb6d4960a982"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"syn 1.0.103", "syn 1.0.103",
"synstructure", "synstructure 0.12.6",
] ]
[[package]] [[package]]
@ -4239,7 +4239,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 1.0.103", "syn 1.0.103",
"synstructure", "synstructure 0.12.6",
"unicode-xid", "unicode-xid",
] ]
@ -5376,7 +5376,7 @@ dependencies = [
"itertools", "itertools",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 1.0.103", "syn 2.0.32",
] ]
[[package]] [[package]]
@ -5840,7 +5840,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 1.0.103", "syn 1.0.103",
"synstructure", "synstructure 0.12.6",
] ]
[[package]] [[package]]
@ -5969,6 +5969,18 @@ dependencies = [
"unicode-xid", "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]] [[package]]
name = "take_mut" name = "take_mut"
version = "0.2.2" version = "0.2.2"
@ -6169,7 +6181,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 1.0.103", "syn 1.0.103",
"synstructure", "synstructure 0.12.6",
] ]
[[package]] [[package]]

View file

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

View file

@ -13,10 +13,7 @@ use proc_macro2::{Span, TokenStream};
use quote::*; use quote::*;
use syn::parse::Result; use syn::parse::Result;
use syn::spanned::Spanned; use syn::spanned::Spanned;
use syn::{ use syn::{parse_macro_input, Attribute, Ident, LitStr, Path};
parse_macro_input, Attribute, Ident, Lit, LitStr, Meta, MetaList, MetaNameValue, NestedMeta,
Path,
};
mod parse; mod parse;
use parse::*; use parse::*;
@ -199,23 +196,19 @@ impl Field {
} }
fn attr_to_pref_name(attr: &Attribute) -> Option<LitStr> { fn attr_to_pref_name(attr: &Attribute) -> Option<LitStr> {
attr.parse_meta().ok().and_then(|meta| { if attr.path().is_ident("serde") {
if let Meta::List(MetaList { path, nested, .. }) = meta { // If `parse_nested_meta()` fails, `result` will remain None.
if path.is_ident("serde") { let mut result = None;
if let Some(NestedMeta::Meta(Meta::NameValue(MetaNameValue { let _ = attr.parse_nested_meta(|meta| {
ref path, if meta.path.is_ident("rename") {
lit: Lit::Str(val), result = Some(meta.value()?.parse()?);
..
}))) = nested.iter().next()
{
if path.is_ident("rename") {
return Some(val.clone());
}
}
}
} }
Ok(())
});
result
} else {
None None
}) }
} }
fn err<S: Spanned>(s: S, msg: &str) -> syn::Error { fn err<S: Spanned>(s: S, msg: &str) -> syn::Error {

View file

@ -56,7 +56,8 @@ pub struct RootTypeDef {
impl Parse for MacroInput { impl Parse for MacroInput {
fn parse(input: ParseStream<'_>) -> Result<Self> { 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 gen_accessors = None;
let mut type_def = None; let mut type_def = None;
let mut accessor_type = None; let mut accessor_type = None;
@ -134,7 +135,7 @@ impl Parse for NewTypeDef {
#[allow(clippy::eval_order_dependence)] #[allow(clippy::eval_order_dependence)]
Ok(NewTypeDef { Ok(NewTypeDef {
_braces: braced!(content in input), _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 } darling = { workspace = true }
proc-macro2 = { workspace = true } proc-macro2 = { workspace = true }
quote = { workspace = true } quote = { workspace = true }
syn = { workspace = true } syn = { version = "1", default-features = false, features = ["clone-impls", "derive", "parsing"] }
synstructure = { workspace = true } synstructure = "0.12"

View file

@ -149,22 +149,16 @@ fn js_traceable_derive(s: synstructure::Structure) -> proc_macro2::TokenStream {
let mut asserts = quote!(); let mut asserts = quote!();
let match_body = s.each(|binding| { let match_body = s.each(|binding| {
for attr in binding.ast().attrs.iter() { for attr in binding.ast().attrs.iter() {
match attr.parse_meta().unwrap() { if attr.path().is_ident("no_trace") {
syn::Meta::Path(ref path) | syn::Meta::List(syn::MetaList { ref path, .. }) => { // If no reason argument is provided to `no_trace` (ie `#[no_trace="This types does not need..."]`),
if path.is_ident("no_trace") { // 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)); asserts.extend(assert_not_impl_traceable(&binding.ast().ty));
}
return None; return None;
} else if path.is_ident("custom_trace") { } else if attr.path().is_ident("custom_trace") {
return Some(quote!(<crate::dom::bindings::trace::CustomTraceable>::trace(#binding, tracer);)); 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;
}
},
}
} }
Some(quote!(#binding.trace(tracer);)) Some(quote!(#binding.trace(tracer);))
}); });

View file

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

View file

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