Skip to content

Commit

Permalink
chore(deps): Update syn to 2 (#214)
Browse files Browse the repository at this point in the history
* chore(deps): Update syn to 2

* Remove non-existant feature flag from tests
  • Loading branch information
jsdw authored Oct 23, 2024
1 parent a17edf7 commit e56c6ef
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 30 deletions.
2 changes: 1 addition & 1 deletion derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ proc-macro = true

[dependencies]
quote = "1.0"
syn = { version = "1.0", features = ["derive", "visit", "visit-mut", "extra-traits"] }
syn = { version = "2.0", features = ["derive", "visit", "visit-mut", "extra-traits"] }
proc-macro2 = "1.0"
proc-macro-crate = "3"

Expand Down
9 changes: 4 additions & 5 deletions derive/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ impl Attributes {
let mut replace_segments = Vec::new();

let attributes_parser = |input: &ParseBuffer| {
let attrs: Punctuated<ScaleInfoAttr, Token![,]> =
input.parse_terminated(ScaleInfoAttr::parse)?;
let attrs = input.parse_terminated(ScaleInfoAttr::parse, Token![,])?;
Ok(attrs)
};

for attr in &item.attrs {
if !attr.path.is_ident(SCALE_INFO) {
if !attr.path().is_ident(SCALE_INFO) {
continue;
}
let scale_info_attrs = attr.parse_args_with(attributes_parser)?;
Expand Down Expand Up @@ -177,7 +176,7 @@ impl Parse for BoundsAttr {
input.parse::<keywords::bounds>()?;
let content;
syn::parenthesized!(content in input);
let predicates = content.parse_terminated(syn::WherePredicate::parse)?;
let predicates = content.parse_terminated(syn::WherePredicate::parse, Token![,])?;
Ok(Self { predicates })
}
}
Expand Down Expand Up @@ -215,7 +214,7 @@ impl Parse for SkipTypeParamsAttr {
input.parse::<keywords::skip_type_params>()?;
let content;
syn::parenthesized!(content in input);
let type_params = content.parse_terminated(syn::TypeParam::parse)?;
let type_params = content.parse_terminated(syn::TypeParam::parse, Token![,])?;
Ok(Self { type_params })
}
}
Expand Down
32 changes: 17 additions & 15 deletions derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,22 +261,24 @@ impl TypeInfoImpl {
let docs = attrs
.iter()
.filter_map(|attr| {
if let Ok(syn::Meta::NameValue(meta)) = attr.parse_meta() {
if meta.path.get_ident().map_or(false, |ident| ident == "doc") {
if let syn::Lit::Str(lit) = &meta.lit {
let lit_value = lit.value();
let stripped = lit_value.strip_prefix(' ').unwrap_or(&lit_value);
let lit: syn::Lit = parse_quote!(#stripped);
Some(lit)
} else {
None
}
} else {
None
}
} else {
None
if !attr.path().is_ident("doc") {
return None;
}
let syn::Meta::NameValue(nv) = &attr.meta else {
return None;
};
let syn::Expr::Lit(syn::ExprLit {
lit: syn::Lit::Str(s),
..
}) = &nv.value
else {
return None;
};

let lit_value = s.value();
let stripped = lit_value.strip_prefix(' ').unwrap_or(&lit_value);
let lit: syn::Lit = parse_quote!(#stripped);
Some(lit)
})
.collect::<Vec<_>>();

Expand Down
18 changes: 12 additions & 6 deletions derive/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
use proc_macro2::TokenStream;
use quote::quote;
use syn::{parse::Parse, spanned::Spanned, AttrStyle, Attribute, Lit, Meta, NestedMeta, Variant};
use syn::{
parse::Parse, spanned::Spanned, AttrStyle, Attribute, Expr, ExprLit, Lit, Meta, Variant,
};

/// Look for a `#[codec(index = $int)]` attribute on a variant. If no attribute
/// is found, fall back to the discriminant or just the variant index.
Expand All @@ -43,9 +45,13 @@ pub fn maybe_index(variant: &Variant) -> Option<u8> {
.filter(|attr| attr.style == AttrStyle::Outer);

codec_meta_item(outer_attrs, |meta| {
if let NestedMeta::Meta(Meta::NameValue(ref nv)) = meta {
if let Meta::NameValue(ref nv) = meta {
if nv.path.is_ident("index") {
if let Lit::Int(ref v) = nv.lit {
if let Expr::Lit(ExprLit {
lit: Lit::Int(ref v),
..
}) = nv.value
{
let byte = v
.base10_parse::<u8>()
.expect("Internal error. `#[codec(index = …)]` attribute syntax must be checked in `parity-scale-codec`. This is a bug.");
Expand All @@ -65,7 +71,7 @@ pub fn is_compact(field: &syn::Field) -> bool {
.iter()
.filter(|attr| attr.style == AttrStyle::Outer);
codec_meta_item(outer_attrs, |meta| {
if let NestedMeta::Meta(Meta::Path(ref path)) = meta {
if let Meta::Path(ref path) = meta {
if path.is_ident("compact") {
return Some(());
}
Expand All @@ -79,7 +85,7 @@ pub fn is_compact(field: &syn::Field) -> bool {
/// Look for a `#[codec(skip)]` in the given attributes.
pub fn should_skip(attrs: &[Attribute]) -> bool {
codec_meta_item(attrs.iter(), |meta| {
if let NestedMeta::Meta(Meta::Path(ref path)) = meta {
if let Meta::Path(ref path) = meta {
if path.is_ident("skip") {
return Some(path.span());
}
Expand All @@ -106,7 +112,7 @@ where
M: Parse,
{
itr.find_map(|attr| {
attr.path
attr.path()
.is_ident(kind)
.then(|| pred(attr.parse_args().ok()?))
.flatten()
Expand Down
2 changes: 1 addition & 1 deletion test_suite/tests/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#![no_std]
#![allow(unused)]
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(dead_code)]

use info::{self as scale_info};
Expand Down
2 changes: 1 addition & 1 deletion test_suite/tests/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#![cfg_attr(not(feature = "std"), no_std)]
#![no_std]

use core::ops::{Range, RangeInclusive};

Expand Down
2 changes: 1 addition & 1 deletion test_suite/tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#![no_std]
#![allow(unused)]
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(dead_code)]

use info::{self as scale_info};
Expand Down

0 comments on commit e56c6ef

Please sign in to comment.