chore(deps): upgrade syn 2.0 (#1910)

This commit is contained in:
Matthias Seitz
2023-03-22 14:02:33 +01:00
committed by GitHub
parent 2bc4da5eaa
commit bcfeb1dea0
8 changed files with 244 additions and 329 deletions

481
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,7 @@ proc-macro = true
[dependencies]
proc-macro2 = "1.0"
syn = { version = "1.0", features = ["extra-traits"] }
syn = { version = "2.0", features = ["extra-traits"] }
quote = "1.0"
regex = "1.6.0"
once_cell = "1.17.0"

View File

@ -2,7 +2,7 @@ use once_cell::sync::Lazy;
use quote::{quote, ToTokens};
use regex::Regex;
use syn::{
punctuated::Punctuated, Attribute, Data, DeriveInput, Error, Lit, LitBool, LitStr,
punctuated::Punctuated, Attribute, Data, DeriveInput, Error, Expr, Lit, LitBool, LitStr,
MetaNameValue, Result, Token,
};
@ -168,7 +168,7 @@ pub(crate) struct MetricsAttr {
}
impl MetricsAttr {
const DEFAULT_SEPARATOR: &str = ".";
const DEFAULT_SEPARATOR: &'static str = ".";
fn separator(&self) -> String {
match &self.separator {
@ -189,18 +189,22 @@ fn parse_metrics_attr(node: &DeriveInput) -> Result<MetricsAttr> {
metrics_attr.parse_args_with(Punctuated::<MetaNameValue, Token![,]>::parse_terminated)?;
let (mut scope, mut separator, mut dynamic) = (None, None, None);
for kv in parsed {
let lit = match kv.value {
Expr::Lit(ref expr) => &expr.lit,
_ => continue,
};
if kv.path.is_ident("scope") {
if scope.is_some() {
return Err(Error::new_spanned(kv, "Duplicate `scope` value provided."))
}
let scope_lit = parse_str_lit(&kv.lit)?;
let scope_lit = parse_str_lit(lit)?;
validate_metric_name(&scope_lit)?;
scope = Some(scope_lit);
} else if kv.path.is_ident("separator") {
if separator.is_some() {
return Err(Error::new_spanned(kv, "Duplicate `separator` value provided."))
}
let separator_lit = parse_str_lit(&kv.lit)?;
let separator_lit = parse_str_lit(lit)?;
if !SUPPORTED_SEPARATORS.contains(&&*separator_lit.value()) {
return Err(Error::new_spanned(
kv,
@ -219,7 +223,7 @@ fn parse_metrics_attr(node: &DeriveInput) -> Result<MetricsAttr> {
if dynamic.is_some() {
return Err(Error::new_spanned(kv, "Duplicate `dynamic` flag provided."))
}
dynamic = Some(parse_bool_lit(&kv.lit)?.value);
dynamic = Some(parse_bool_lit(lit)?.value);
} else {
return Err(Error::new_spanned(kv, "Unsupported attribute entry."))
}
@ -254,16 +258,20 @@ fn parse_metric_fields(node: &DeriveInput) -> Result<Vec<Metric<'_>>> {
let parsed = metric_attr
.parse_args_with(Punctuated::<MetaNameValue, Token![,]>::parse_terminated)?;
for kv in parsed {
let lit = match kv.value {
Expr::Lit(ref expr) => &expr.lit,
_ => continue,
};
if kv.path.is_ident("describe") {
if describe.is_some() {
return Err(Error::new_spanned(kv, "Duplicate `describe` value provided."))
}
describe = Some(parse_str_lit(&kv.lit)?);
describe = Some(parse_str_lit(lit)?);
} else if kv.path.is_ident("rename") {
if rename.is_some() {
return Err(Error::new_spanned(kv, "Duplicate `rename` value provided."))
}
let rename_lit = parse_str_lit(&kv.lit)?;
let rename_lit = parse_str_lit(lit)?;
validate_metric_name(&rename_lit)?;
rename = Some(rename_lit)
} else {
@ -304,7 +312,7 @@ fn parse_single_attr<'a, T: WithAttrs + ToTokens>(
token: &'a T,
ident: &str,
) -> Result<Option<&'a Attribute>> {
let mut attr_iter = token.attrs().iter().filter(|a| a.path.is_ident(ident));
let mut attr_iter = token.attrs().iter().filter(|a| a.path().is_ident(ident));
if let Some(attr) = attr_iter.next() {
if let Some(next_attr) = attr_iter.next() {
Err(Error::new_spanned(
@ -333,15 +341,16 @@ fn parse_single_required_attr<'a, T: WithAttrs + ToTokens>(
fn parse_docs_to_string<T: WithAttrs>(token: &T) -> Result<Option<String>> {
let mut doc_str = None;
for attr in token.attrs().iter() {
let meta = attr.parse_meta()?;
if let syn::Meta::NameValue(meta) = meta {
if let syn::Lit::Str(doc) = meta.lit {
let doc_value = doc.value().trim().to_string();
doc_str = Some(
doc_str
.map(|prev_doc_value| format!("{prev_doc_value} {doc_value}"))
.unwrap_or(doc_value),
);
if let syn::Meta::NameValue(ref meta) = attr.meta {
if let Expr::Lit(ref lit) = meta.value {
if let Lit::Str(ref doc) = lit.lit {
let doc_value = doc.value().trim().to_string();
doc_str = Some(
doc_str
.map(|prev_doc_value| format!("{prev_doc_value} {doc_value}"))
.unwrap_or(doc_value),
);
}
}
}
}

View File

@ -17,11 +17,12 @@ error: Either `scope = ..` or `dynamic = true` must be set.
16 | | struct CustomMetrics3;
| |______________________^
error: expected literal
--> tests/compile-fail/metrics_attr.rs:19:19
error: Either `scope = ..` or `dynamic = true` must be set.
--> tests/compile-fail/metrics_attr.rs:19:1
|
19 | #[metrics(scope = value)]
| ^^^^^
19 | / #[metrics(scope = value)]
20 | | struct CustomMetrics4;
| |______________________^
error: Value **must** be a string literal.
--> tests/compile-fail/metrics_attr.rs:23:19
@ -41,11 +42,12 @@ error: Duplicate `scope` value provided.
31 | #[metrics(scope = "some_scope", scope = "another_scope")]
| ^^^^^^^^^^^^^^^^^^^^^^^
error: expected literal
--> tests/compile-fail/metrics_attr.rs:35:23
error: Either `scope = ..` or `dynamic = true` must be set.
--> tests/compile-fail/metrics_attr.rs:35:1
|
35 | #[metrics(separator = value)]
| ^^^^^
35 | / #[metrics(separator = value)]
36 | | struct CustomMetrics8;
| |______________________^
error: Value **must** be a string literal.
--> tests/compile-fail/metrics_attr.rs:39:23

View File

@ -10,6 +10,6 @@ repository = "https://github.com/paradigmxyz/reth"
proc-macro = true
[dependencies]
syn = "1"
syn = "2"
quote = "1"
proc-macro2 = "1"

View File

@ -1,6 +1,6 @@
use proc_macro2::TokenStream;
use quote::quote;
use syn::{Attribute, DataStruct, Error, Field, Meta, NestedMeta, Result, Type, TypePath};
use syn::{Attribute, DataStruct, Error, Field, Meta, Result, Type, TypePath};
pub(crate) const EMPTY_STRING_CODE: u8 = 0x80;
@ -19,18 +19,21 @@ pub(crate) fn parse_struct<'a>(
}
pub(crate) fn attributes_include(attrs: &[Attribute], attr_name: &str) -> bool {
attrs.iter().any(|attr| {
if attr.path.is_ident("rlp") {
if let Ok(Meta::List(meta)) = attr.parse_meta() {
if let Some(NestedMeta::Meta(meta)) = meta.nested.first() {
return meta.path().is_ident(attr_name)
for attr in attrs.iter() {
if attr.path().is_ident("rlp") {
if let Meta::List(meta) = &attr.meta {
let mut is_attr = false;
let _ = meta.parse_nested_meta(|meta| {
is_attr = meta.path.is_ident(attr_name);
Ok(())
});
if is_attr {
return true
}
return false
} else {
}
}
false
})
}
false
}
pub(crate) fn is_optional(field: &Field) -> bool {

View File

@ -20,7 +20,7 @@ proc-macro = true
[dependencies]
proc-macro2 = "1.0.47"
quote = "1.0"
syn = { version = "1.0", features = ["full"] }
syn = { version = "2.0", features = ["full"] }
convert_case = "0.6.0"
# codecs

View File

@ -119,7 +119,7 @@ fn load_field(field: &syn::Field, fields: &mut FieldList, is_enum: bool) {
} else {
let should_compact = is_flag_type(&ftype) ||
field.attrs.iter().any(|attr| {
attr.path.segments.iter().any(|path| path.ident == "maybe_zero")
attr.path().segments.iter().any(|path| path.ident == "maybe_zero")
});
fields.push(FieldTypes::StructField((