Skip to content

Commit e56c6ef

Browse files
authored
chore(deps): Update syn to 2 (#214)
* chore(deps): Update syn to 2 * Remove non-existant feature flag from tests
1 parent a17edf7 commit e56c6ef

File tree

7 files changed

+37
-30
lines changed

7 files changed

+37
-30
lines changed

derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ proc-macro = true
1818

1919
[dependencies]
2020
quote = "1.0"
21-
syn = { version = "1.0", features = ["derive", "visit", "visit-mut", "extra-traits"] }
21+
syn = { version = "2.0", features = ["derive", "visit", "visit-mut", "extra-traits"] }
2222
proc-macro2 = "1.0"
2323
proc-macro-crate = "3"
2424

derive/src/attr.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,12 @@ impl Attributes {
4848
let mut replace_segments = Vec::new();
4949

5050
let attributes_parser = |input: &ParseBuffer| {
51-
let attrs: Punctuated<ScaleInfoAttr, Token![,]> =
52-
input.parse_terminated(ScaleInfoAttr::parse)?;
51+
let attrs = input.parse_terminated(ScaleInfoAttr::parse, Token![,])?;
5352
Ok(attrs)
5453
};
5554

5655
for attr in &item.attrs {
57-
if !attr.path.is_ident(SCALE_INFO) {
56+
if !attr.path().is_ident(SCALE_INFO) {
5857
continue;
5958
}
6059
let scale_info_attrs = attr.parse_args_with(attributes_parser)?;
@@ -177,7 +176,7 @@ impl Parse for BoundsAttr {
177176
input.parse::<keywords::bounds>()?;
178177
let content;
179178
syn::parenthesized!(content in input);
180-
let predicates = content.parse_terminated(syn::WherePredicate::parse)?;
179+
let predicates = content.parse_terminated(syn::WherePredicate::parse, Token![,])?;
181180
Ok(Self { predicates })
182181
}
183182
}
@@ -215,7 +214,7 @@ impl Parse for SkipTypeParamsAttr {
215214
input.parse::<keywords::skip_type_params>()?;
216215
let content;
217216
syn::parenthesized!(content in input);
218-
let type_params = content.parse_terminated(syn::TypeParam::parse)?;
217+
let type_params = content.parse_terminated(syn::TypeParam::parse, Token![,])?;
219218
Ok(Self { type_params })
220219
}
221220
}

derive/src/lib.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -261,22 +261,24 @@ impl TypeInfoImpl {
261261
let docs = attrs
262262
.iter()
263263
.filter_map(|attr| {
264-
if let Ok(syn::Meta::NameValue(meta)) = attr.parse_meta() {
265-
if meta.path.get_ident().map_or(false, |ident| ident == "doc") {
266-
if let syn::Lit::Str(lit) = &meta.lit {
267-
let lit_value = lit.value();
268-
let stripped = lit_value.strip_prefix(' ').unwrap_or(&lit_value);
269-
let lit: syn::Lit = parse_quote!(#stripped);
270-
Some(lit)
271-
} else {
272-
None
273-
}
274-
} else {
275-
None
276-
}
277-
} else {
278-
None
264+
if !attr.path().is_ident("doc") {
265+
return None;
279266
}
267+
let syn::Meta::NameValue(nv) = &attr.meta else {
268+
return None;
269+
};
270+
let syn::Expr::Lit(syn::ExprLit {
271+
lit: syn::Lit::Str(s),
272+
..
273+
}) = &nv.value
274+
else {
275+
return None;
276+
};
277+
278+
let lit_value = s.value();
279+
let stripped = lit_value.strip_prefix(' ').unwrap_or(&lit_value);
280+
let lit: syn::Lit = parse_quote!(#stripped);
281+
Some(lit)
280282
})
281283
.collect::<Vec<_>>();
282284

derive/src/utils.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
1919
use proc_macro2::TokenStream;
2020
use quote::quote;
21-
use syn::{parse::Parse, spanned::Spanned, AttrStyle, Attribute, Lit, Meta, NestedMeta, Variant};
21+
use syn::{
22+
parse::Parse, spanned::Spanned, AttrStyle, Attribute, Expr, ExprLit, Lit, Meta, Variant,
23+
};
2224

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

4547
codec_meta_item(outer_attrs, |meta| {
46-
if let NestedMeta::Meta(Meta::NameValue(ref nv)) = meta {
48+
if let Meta::NameValue(ref nv) = meta {
4749
if nv.path.is_ident("index") {
48-
if let Lit::Int(ref v) = nv.lit {
50+
if let Expr::Lit(ExprLit {
51+
lit: Lit::Int(ref v),
52+
..
53+
}) = nv.value
54+
{
4955
let byte = v
5056
.base10_parse::<u8>()
5157
.expect("Internal error. `#[codec(index = …)]` attribute syntax must be checked in `parity-scale-codec`. This is a bug.");
@@ -65,7 +71,7 @@ pub fn is_compact(field: &syn::Field) -> bool {
6571
.iter()
6672
.filter(|attr| attr.style == AttrStyle::Outer);
6773
codec_meta_item(outer_attrs, |meta| {
68-
if let NestedMeta::Meta(Meta::Path(ref path)) = meta {
74+
if let Meta::Path(ref path) = meta {
6975
if path.is_ident("compact") {
7076
return Some(());
7177
}
@@ -79,7 +85,7 @@ pub fn is_compact(field: &syn::Field) -> bool {
7985
/// Look for a `#[codec(skip)]` in the given attributes.
8086
pub fn should_skip(attrs: &[Attribute]) -> bool {
8187
codec_meta_item(attrs.iter(), |meta| {
82-
if let NestedMeta::Meta(Meta::Path(ref path)) = meta {
88+
if let Meta::Path(ref path) = meta {
8389
if path.is_ident("skip") {
8490
return Some(path.span());
8591
}
@@ -106,7 +112,7 @@ where
106112
M: Parse,
107113
{
108114
itr.find_map(|attr| {
109-
attr.path
115+
attr.path()
110116
.is_ident(kind)
111117
.then(|| pred(attr.parse_args().ok()?))
112118
.flatten()

test_suite/tests/codec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#![no_std]
1516
#![allow(unused)]
16-
#![cfg_attr(not(feature = "std"), no_std)]
1717
#![allow(dead_code)]
1818

1919
use info::{self as scale_info};

test_suite/tests/derive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#![cfg_attr(not(feature = "std"), no_std)]
15+
#![no_std]
1616

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

test_suite/tests/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#![no_std]
1516
#![allow(unused)]
16-
#![cfg_attr(not(feature = "std"), no_std)]
1717
#![allow(dead_code)]
1818

1919
use info::{self as scale_info};

0 commit comments

Comments
 (0)