From 56c5fbbe61ab296cb55d2b826b471ac88807b08c Mon Sep 17 00:00:00 2001 From: Nikita Strygin Date: Mon, 11 Mar 2024 15:30:17 +0300 Subject: [PATCH] [refactor] #3682: unrename the syn2, as we no longer have two syn versions in our codebase Signed-off-by: Nikita Strygin --- Cargo.toml | 2 +- data_model/derive/Cargo.toml | 2 +- data_model/derive/src/enum_ref.rs | 26 ++--- data_model/derive/src/filter.rs | 8 +- data_model/derive/src/has_origin.rs | 24 ++--- data_model/derive/src/id.rs | 26 ++--- data_model/derive/src/lib.rs | 16 +-- data_model/derive/src/model.rs | 40 +++---- data_model/derive/src/partially_tagged/mod.rs | 18 ++-- .../src/partially_tagged/resolve_self.rs | 14 +-- ffi/derive/Cargo.toml | 2 +- ffi/derive/src/attr_parse/derive.rs | 6 +- ffi/derive/src/attr_parse/doc.rs | 2 +- ffi/derive/src/attr_parse/getset.rs | 30 +++--- ffi/derive/src/attr_parse/repr.rs | 10 +- ffi/derive/src/convert.rs | 92 ++++++++-------- ffi/derive/src/ffi_fn.rs | 12 +-- ffi/derive/src/getset_gen.rs | 6 +- ffi/derive/src/impl_visitor.rs | 74 ++++++------- ffi/derive/src/lib.rs | 34 +++--- ffi/derive/src/wrapper.rs | 46 ++++---- futures/derive/Cargo.toml | 2 +- futures/derive/src/lib.rs | 4 +- macro/derive/Cargo.toml | 2 +- macro/derive/src/lib.rs | 76 ++++++------- macro/utils/Cargo.toml | 2 +- macro/utils/src/lib.rs | 26 ++--- primitives/derive/Cargo.toml | 2 +- primitives/derive/src/socket_addr.rs | 30 +++--- schema/derive/Cargo.toml | 2 +- schema/derive/src/lib.rs | 72 ++++++------- smart_contract/derive/Cargo.toml | 2 +- smart_contract/derive/src/entrypoint.rs | 11 +- smart_contract/derive/src/lib.rs | 2 +- smart_contract/executor/derive/Cargo.toml | 2 +- .../executor/derive/src/conversion.rs | 30 +++--- smart_contract/executor/derive/src/default.rs | 36 +++---- .../executor/derive/src/entrypoint.rs | 25 +++-- smart_contract/executor/derive/src/lib.rs | 22 ++-- smart_contract/executor/derive/src/token.rs | 6 +- .../executor/derive/src/validate.rs | 10 +- smart_contract/trigger/derive/Cargo.toml | 2 +- .../trigger/derive/src/entrypoint.rs | 10 +- smart_contract/trigger/derive/src/lib.rs | 2 +- telemetry/derive/Cargo.toml | 2 +- telemetry/derive/src/lib.rs | 34 +++--- torii/derive/Cargo.toml | 2 +- torii/derive/src/lib.rs | 10 +- version/derive/Cargo.toml | 2 +- version/derive/src/lib.rs | 20 ++-- wasm_codec/derive/Cargo.toml | 2 +- wasm_codec/derive/src/lib.rs | 102 +++++++++--------- 52 files changed, 517 insertions(+), 525 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b44da28f4f0..9d82e9a11eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,7 +60,7 @@ test_network = { version = "=2.0.0-pre-rc.20", path = "core/test_network" } proc-macro-error = "1.0.4" proc-macro2 = "1.0.69" -syn2 = { package = "syn", version = "2.0.38", default-features = false } +syn = { version = "2.0.38", default-features = false } quote = "1.0.33" manyhow = { version = "0.8.1", features = ["darling"] } darling = "0.20.3" diff --git a/data_model/derive/Cargo.toml b/data_model/derive/Cargo.toml index 5cb877d609f..be1b79f628e 100644 --- a/data_model/derive/Cargo.toml +++ b/data_model/derive/Cargo.toml @@ -14,7 +14,7 @@ workspace = true proc-macro = true [dependencies] -syn2 = { workspace = true, features = ["default", "full", "extra-traits", "visit-mut"] } +syn = { workspace = true, features = ["default", "full", "extra-traits", "visit-mut"] } quote = { workspace = true } darling = { workspace = true } proc-macro2 = { workspace = true } diff --git a/data_model/derive/src/enum_ref.rs b/data_model/derive/src/enum_ref.rs index ca399cf9938..8215be75795 100644 --- a/data_model/derive/src/enum_ref.rs +++ b/data_model/derive/src/enum_ref.rs @@ -2,7 +2,7 @@ use darling::{FromAttributes, FromDeriveInput, FromMeta, FromVariant}; use proc_macro2::TokenStream; use quote::{quote, ToTokens}; -pub fn impl_enum_ref(input: &syn2::DeriveInput) -> manyhow::Result { +pub fn impl_enum_ref(input: &syn::DeriveInput) -> manyhow::Result { let input = EnumRef::from_derive_input(input)?; Ok(quote! { #input }) } @@ -32,20 +32,20 @@ struct EnumRefVariantAttrs { #[derive(Clone)] struct EnumRefField { - ty: syn2::Type, + ty: syn::Type, } #[derive(Clone)] struct EnumRefVariant { - ident: syn2::Ident, + ident: syn::Ident, field: EnumRefField, } #[derive(Clone)] struct EnumRef { attrs: EnumRefAttrs, - ident: syn2::Ident, - generics: syn2::Generics, + ident: syn::Ident, + generics: syn::Generics, data: darling::ast::Data, } @@ -66,7 +66,7 @@ impl FromMeta for EnumRefDeriveAttrs { } impl FromVariant for EnumRefVariant { - fn from_variant(variant: &syn2::Variant) -> darling::Result { + fn from_variant(variant: &syn::Variant) -> darling::Result { let transparent = EnumRefVariantAttrs::from_attributes(&variant.attrs)?; let mut fields: Vec<_> = variant @@ -96,7 +96,7 @@ impl FromVariant for EnumRefVariant { } impl FromDeriveInput for EnumRef { - fn from_derive_input(input: &syn2::DeriveInput) -> darling::Result { + fn from_derive_input(input: &syn::DeriveInput) -> darling::Result { Ok(Self { attrs: EnumRefAttrs::from_attributes(&input.attrs)?, ident: gen_enum_ref_ident(&input.ident), @@ -159,19 +159,19 @@ impl ToTokens for EnumRef { } } -fn gen_enum_ref_ident(ident: &syn2::Ident) -> syn2::Ident { - syn2::Ident::new(&format!("{ident}Ref"), proc_macro2::Span::call_site()) +fn gen_enum_ref_ident(ident: &syn::Ident) -> syn::Ident { + syn::Ident::new(&format!("{ident}Ref"), proc_macro2::Span::call_site()) } -fn gen_field_ty(transparent: Transparent, field_ty: &syn2::Type) -> syn2::Type { +fn gen_field_ty(transparent: Transparent, field_ty: &syn::Type) -> syn::Type { if matches!(transparent, Transparent::Transparent) { - if let syn2::Type::Path(ty) = field_ty { + if let syn::Type::Path(ty) = field_ty { if let Some(ident) = ty.path.get_ident() { let ident = gen_enum_ref_ident(ident); - return syn2::parse_quote! { #ident<'a> }; + return syn::parse_quote! { #ident<'a> }; } } } - syn2::parse_quote!(&'a #field_ty) + syn::parse_quote!(&'a #field_ty) } diff --git a/data_model/derive/src/filter.rs b/data_model/derive/src/filter.rs index 8479c88bfdb..a023f4496cf 100644 --- a/data_model/derive/src/filter.rs +++ b/data_model/derive/src/filter.rs @@ -3,7 +3,7 @@ use iroha_macro_utils::Emitter; use manyhow::emit; use proc_macro2::TokenStream; use quote::{format_ident, quote}; -use syn2::{Generics, Ident, Variant, Visibility}; +use syn::{Generics, Ident, Variant, Visibility}; #[derive(FromDeriveInput)] #[darling(supports(enum_tuple))] @@ -29,7 +29,7 @@ enum EventVariant { impl FromVariant for EventVariant { fn from_variant(variant: &Variant) -> darling::Result { - let syn2::Fields::Unnamed(fields) = &variant.fields else { + let syn::Fields::Unnamed(fields) = &variant.fields else { return Err( darling::Error::custom("Expected an enum with unnamed fields") .with_span(&variant.fields), @@ -40,7 +40,7 @@ impl FromVariant for EventVariant { let Some(first_field_ty) = fields.unnamed.first().map(|v| &v.ty) else { return Err(darling::Error::custom("Expected at least one field").with_span(&fields)); }; - let syn2::Type::Path(path) = first_field_ty else { + let syn::Type::Path(path) = first_field_ty else { return Err( darling::Error::custom("Only identifiers supported as event types") .with_span(first_field_ty), @@ -209,7 +209,7 @@ fn impl_event_filter(event: &EventEnum) -> proc_macro2::TokenStream { /// Generates the filter for the event. E.g. for `AccountEvent`, `AccountFilter` /// and its `impl Filter` are generated. -pub fn impl_filter(emitter: &mut Emitter, input: &syn2::DeriveInput) -> TokenStream { +pub fn impl_filter(emitter: &mut Emitter, input: &syn::DeriveInput) -> TokenStream { let Some(event) = emitter.handle(EventEnum::from_derive_input(input)) else { return quote!(); }; diff --git a/data_model/derive/src/has_origin.rs b/data_model/derive/src/has_origin.rs index ac2e88833f1..b6f7fe365e2 100644 --- a/data_model/derive/src/has_origin.rs +++ b/data_model/derive/src/has_origin.rs @@ -1,13 +1,11 @@ use darling::{FromDeriveInput, FromVariant}; -use iroha_macro_utils::{ - attr_struct2, parse_single_list_attr, parse_single_list_attr_opt, Emitter, -}; +use iroha_macro_utils::{attr_struct, parse_single_list_attr, parse_single_list_attr_opt, Emitter}; use proc_macro2::TokenStream; use quote::quote; -use syn2::{parse_quote, Ident, Token, Type}; +use syn::{parse_quote, Ident, Token, Type}; mod kw { - syn2::custom_keyword!(origin); + syn::custom_keyword!(origin); } const HAS_ORIGIN_ATTR: &str = "has_origin"; @@ -15,13 +13,13 @@ const HAS_ORIGIN_ATTR: &str = "has_origin"; pub struct HasOriginEnum { ident: Ident, #[allow(unused)] - generics: syn2::Generics, + generics: syn::Generics, variants: Vec, origin: Type, } impl FromDeriveInput for HasOriginEnum { - fn from_derive_input(input: &syn2::DeriveInput) -> darling::Result { + fn from_derive_input(input: &syn::DeriveInput) -> darling::Result { let ident = input.ident.clone(); let generics = input.generics.clone(); @@ -48,7 +46,7 @@ pub struct HasOriginVariant { } impl FromVariant for HasOriginVariant { - fn from_variant(variant: &syn2::Variant) -> darling::Result { + fn from_variant(variant: &syn::Variant) -> darling::Result { let ident = variant.ident.clone(); let extractor = parse_single_list_attr_opt(HAS_ORIGIN_ATTR, &variant.attrs)?; @@ -56,7 +54,7 @@ impl FromVariant for HasOriginVariant { } } -attr_struct2! { +attr_struct! { pub struct OriginAttr { _kw: kw::origin, _eq: Token![=], @@ -64,15 +62,15 @@ attr_struct2! { } } -attr_struct2! { +attr_struct! { pub struct OriginExtractorAttr { ident: Ident, _eq: Token![=>], - extractor: syn2::Expr, + extractor: syn::Expr, } } -pub fn impl_has_origin(emitter: &mut Emitter, input: &syn2::DeriveInput) -> TokenStream { +pub fn impl_has_origin(emitter: &mut Emitter, input: &syn::DeriveInput) -> TokenStream { let Some(enum_) = emitter.handle(HasOriginEnum::from_derive_input(input)) else { return quote!(); }; @@ -97,7 +95,7 @@ pub fn impl_has_origin(emitter: &mut Emitter, input: &syn2::DeriveInput) -> Toke }, ) }) - .collect::>(); + .collect::>(); let (impl_generics, ty_generics, where_clause) = enum_.generics.split_for_impl(); diff --git a/data_model/derive/src/id.rs b/data_model/derive/src/id.rs index 3b40a0da006..c9a64c64537 100644 --- a/data_model/derive/src/id.rs +++ b/data_model/derive/src/id.rs @@ -3,10 +3,10 @@ use iroha_macro_utils::{find_single_attr_opt, Emitter}; use manyhow::emit; use proc_macro2::TokenStream; use quote::{quote, ToTokens}; -use syn2::parse_quote; +use syn::parse_quote; mod kw { - syn2::custom_keyword!(transparent); + syn::custom_keyword!(transparent); } enum IdAttr { @@ -16,15 +16,15 @@ enum IdAttr { } impl FromAttributes for IdAttr { - fn from_attributes(attrs: &[syn2::Attribute]) -> darling::Result { + fn from_attributes(attrs: &[syn::Attribute]) -> darling::Result { let mut accumulator = darling::error::Accumulator::default(); let Some(attr) = find_single_attr_opt(&mut accumulator, "id", attrs) else { return accumulator.finish_with(IdAttr::Missing); }; let result = match &attr.meta { - syn2::Meta::Path(_) => IdAttr::Normal, - syn2::Meta::List(list) if list.parse_args::().is_ok() => { + syn::Meta::Path(_) => IdAttr::Normal, + syn::Meta::List(list) if list.parse_args::().is_ok() => { IdAttr::Transparent } _ => { @@ -43,19 +43,19 @@ impl FromAttributes for IdAttr { #[derive(FromDeriveInput)] #[darling(supports(struct_any))] struct IdDeriveInput { - ident: syn2::Ident, - generics: syn2::Generics, + ident: syn::Ident, + generics: syn::Generics, data: darling::ast::Data, } struct IdField { - ident: Option, - ty: syn2::Type, + ident: Option, + ty: syn::Type, id_attr: IdAttr, } impl FromField for IdField { - fn from_field(field: &syn2::Field) -> darling::Result { + fn from_field(field: &syn::Field) -> darling::Result { let ident = field.ident.clone(); let ty = field.ty.clone(); let id_attr = IdAttr::from_attributes(&field.attrs)?; @@ -73,7 +73,7 @@ impl IdDeriveInput { } } -pub fn impl_id_eq_ord_hash(emitter: &mut Emitter, input: &syn2::DeriveInput) -> TokenStream { +pub fn impl_id_eq_ord_hash(emitter: &mut Emitter, input: &syn::DeriveInput) -> TokenStream { let Some(input) = emitter.handle(IdDeriveInput::from_derive_input(input)) else { return quote!(); }; @@ -130,10 +130,10 @@ fn derive_identifiable(emitter: &mut Emitter, input: &IdDeriveInput) -> TokenStr } } -fn get_id_type(emitter: &mut Emitter, input: &IdDeriveInput) -> (syn2::Type, syn2::Expr) { +fn get_id_type(emitter: &mut Emitter, input: &IdDeriveInput) -> (syn::Type, syn::Expr) { for (field_index, IdField { ty, ident, id_attr }) in input.fields().iter().enumerate() { let field_name = ident.as_ref().map_or_else( - || syn2::Index::from(field_index).to_token_stream(), + || syn::Index::from(field_index).to_token_stream(), ToTokens::to_token_stream, ); match id_attr { diff --git a/data_model/derive/src/lib.rs b/data_model/derive/src/lib.rs index c661752a262..36aba376f4f 100644 --- a/data_model/derive/src/lib.rs +++ b/data_model/derive/src/lib.rs @@ -51,7 +51,7 @@ use proc_macro2::TokenStream; #[manyhow] #[proc_macro_derive(EnumRef, attributes(enum_ref))] pub fn enum_ref(input: TokenStream) -> Result { - let input = syn2::parse2(input)?; + let input = syn::parse2(input)?; enum_ref::impl_enum_ref(&input) } @@ -134,7 +134,7 @@ pub fn model(attr: TokenStream, input: TokenStream) -> TokenStream { emit!(emitter, attr, "This attribute does not take any arguments"); } - let Some(input) = emitter.handle(syn2::parse2(input)) else { + let Some(input) = emitter.handle(syn::parse2(input)) else { return emitter.finish_token_stream(); }; @@ -151,7 +151,7 @@ pub fn model(attr: TokenStream, input: TokenStream) -> TokenStream { pub fn model_single(input: TokenStream) -> TokenStream { let mut emitter = Emitter::new(); - let Some(input) = emitter.handle(syn2::parse2(input)) else { + let Some(input) = emitter.handle(syn::parse2(input)) else { return emitter.finish_token_stream(); }; @@ -277,7 +277,7 @@ pub fn model_single(input: TokenStream) -> TokenStream { pub fn id_eq_ord_hash(input: TokenStream) -> TokenStream { let mut emitter = Emitter::new(); - let Some(input) = emitter.handle(syn2::parse2(input)) else { + let Some(input) = emitter.handle(syn::parse2(input)) else { return emitter.finish_token_stream(); }; @@ -452,7 +452,7 @@ pub fn id_eq_ord_hash(input: TokenStream) -> TokenStream { pub fn filter_derive(input: TokenStream) -> TokenStream { let mut emitter = Emitter::new(); - let Some(input) = emitter.handle(syn2::parse2(input)) else { + let Some(input) = emitter.handle(syn::parse2(input)) else { return emitter.finish_token_stream(); }; @@ -489,7 +489,7 @@ pub fn filter_derive(input: TokenStream) -> TokenStream { #[manyhow] #[proc_macro_derive(PartiallyTaggedSerialize, attributes(serde_partially_tagged, serde))] pub fn partially_tagged_serialize_derive(input: TokenStream) -> Result { - let input = syn2::parse2(input)?; + let input = syn::parse2(input)?; partially_tagged::impl_partially_tagged_serialize(&input) } @@ -552,7 +552,7 @@ pub fn partially_tagged_serialize_derive(input: TokenStream) -> Result Result { - let input = syn2::parse2(input)?; + let input = syn::parse2(input)?; partially_tagged::impl_partially_tagged_deserialize(&input) } @@ -645,7 +645,7 @@ pub fn partially_tagged_deserialize_derive(input: TokenStream) -> Result TokenStream { let mut emitter = Emitter::new(); - let Some(input) = emitter.handle(syn2::parse2(input)) else { + let Some(input) = emitter.handle(syn::parse2(input)) else { return emitter.finish_token_stream(); }; diff --git a/data_model/derive/src/model.rs b/data_model/derive/src/model.rs index 32d163d27cb..a5fdb7a7510 100644 --- a/data_model/derive/src/model.rs +++ b/data_model/derive/src/model.rs @@ -2,10 +2,10 @@ use iroha_macro_utils::Emitter; use manyhow::emit; use proc_macro2::TokenStream; use quote::{quote, ToTokens}; -use syn2::{parse_quote, Attribute}; +use syn::{parse_quote, Attribute}; -pub fn impl_model(emitter: &mut Emitter, input: &syn2::ItemMod) -> TokenStream { - let syn2::ItemMod { +pub fn impl_model(emitter: &mut Emitter, input: &syn::ItemMod) -> TokenStream { + let syn::ItemMod { attrs, vis, mod_token, @@ -15,7 +15,7 @@ pub fn impl_model(emitter: &mut Emitter, input: &syn2::ItemMod) -> TokenStream { .. } = input; - let syn2::Visibility::Public(vis_public) = vis else { + let syn::Visibility::Public(vis_public) = vis else { emit!( emitter, input, @@ -44,16 +44,16 @@ pub fn impl_model(emitter: &mut Emitter, input: &syn2::ItemMod) -> TokenStream { } } -pub fn process_item(item: syn2::Item) -> TokenStream { - let mut input: syn2::DeriveInput = match item { - syn2::Item::Struct(item_struct) => item_struct.into(), - syn2::Item::Enum(item_enum) => item_enum.into(), - syn2::Item::Union(item_union) => item_union.into(), +pub fn process_item(item: syn::Item) -> TokenStream { + let mut input: syn::DeriveInput = match item { + syn::Item::Struct(item_struct) => item_struct.into(), + syn::Item::Enum(item_enum) => item_enum.into(), + syn::Item::Union(item_union) => item_union.into(), other => return other.into_token_stream(), }; let vis = &input.vis; - if matches!(vis, syn2::Visibility::Public(_)) { + if matches!(vis, syn::Visibility::Public(_)) { return process_pub_item(input); } @@ -74,21 +74,21 @@ pub fn process_item(item: syn2::Item) -> TokenStream { } } -fn process_pub_item(input: syn2::DeriveInput) -> TokenStream { +fn process_pub_item(input: syn::DeriveInput) -> TokenStream { let (impl_generics, _, where_clause) = input.generics.split_for_impl(); let attrs = input.attrs; let ident = input.ident; match input.data { - syn2::Data::Struct(item) => match &item.fields { - syn2::Fields::Named(fields) => { + syn::Data::Struct(item) => match &item.fields { + syn::Fields::Named(fields) => { let fields = fields.named.iter().map(|field| { let field_attrs = &field.attrs; let field_name = &field.ident; let field_ty = &field.ty; - if !matches!(field.vis, syn2::Visibility::Public(_)) { + if !matches!(field.vis, syn::Visibility::Public(_)) { return quote! {#field,}; } @@ -111,12 +111,12 @@ fn process_pub_item(input: syn2::DeriveInput) -> TokenStream { expose_ffi(attrs, &item) } - syn2::Fields::Unnamed(fields) => { + syn::Fields::Unnamed(fields) => { let fields = fields.unnamed.iter().map(|field| { let field_attrs = &field.attrs; let field_ty = &field.ty; - if !matches!(field.vis, syn2::Visibility::Public(_)) { + if !matches!(field.vis, syn::Visibility::Public(_)) { return quote! {#field,}; } @@ -137,7 +137,7 @@ fn process_pub_item(input: syn2::DeriveInput) -> TokenStream { expose_ffi(attrs, &item) } - syn2::Fields::Unit => { + syn::Fields::Unit => { let item = quote! { pub struct #ident #impl_generics #where_clause; }; @@ -145,7 +145,7 @@ fn process_pub_item(input: syn2::DeriveInput) -> TokenStream { expose_ffi(attrs, &item) } }, - syn2::Data::Enum(item) => { + syn::Data::Enum(item) => { let variants = &item.variants; let item = quote! { @@ -157,13 +157,13 @@ fn process_pub_item(input: syn2::DeriveInput) -> TokenStream { expose_ffi(attrs, &item) } // Triggers in `quote!` side, see https://github.com/rust-lang/rust-clippy/issues/10417 - syn2::Data::Union(item) => { + syn::Data::Union(item) => { let fields = item.fields.named.iter().map(|field| { let field_attrs = &field.attrs; let field_name = &field.ident; let field_ty = &field.ty; - if !matches!(field.vis, syn2::Visibility::Public(_)) { + if !matches!(field.vis, syn::Visibility::Public(_)) { return quote! {#field,}; } diff --git a/data_model/derive/src/partially_tagged/mod.rs b/data_model/derive/src/partially_tagged/mod.rs index 3e40d4518f0..cc61d63902a 100644 --- a/data_model/derive/src/partially_tagged/mod.rs +++ b/data_model/derive/src/partially_tagged/mod.rs @@ -8,7 +8,7 @@ use darling::{FromDeriveInput, FromVariant}; use manyhow::Result; use proc_macro2::TokenStream; use quote::{format_ident, quote}; -use syn2::{parse_quote, Attribute, Generics, Ident, Type}; +use syn::{parse_quote, Attribute, Generics, Ident, Type}; #[derive(FromDeriveInput)] #[darling(forward_attrs(serde), supports(enum_newtype))] @@ -23,7 +23,7 @@ pub struct PartiallyTaggedEnum { #[darling(forward_attrs(serde), attributes(serde_partially_tagged))] pub struct PartiallyTaggedVariant { ident: Ident, - fields: darling::ast::Fields, + fields: darling::ast::Fields, attrs: Vec, #[darling(default)] untagged: bool, @@ -44,7 +44,7 @@ impl PartiallyTaggedEnum { } /// Returns a type that corresponds to `Self`, handling the generics as necessary - fn self_ty(&self) -> syn2::Type { + fn self_ty(&self) -> syn::Type { let ident = &self.ident; let (_, type_generics, _) = self.generics.split_for_impl(); @@ -53,7 +53,7 @@ impl PartiallyTaggedEnum { } impl PartiallyTaggedVariant { - fn ty(&self, self_ty: &syn2::Type) -> syn2::Type { + fn ty(&self, self_ty: &syn::Type) -> syn::Type { let ty = self.fields.fields.first().expect( "BUG: Only newtype enums are supported. Enforced by `darling(supports(enum_newtype))`", ).clone(); @@ -64,7 +64,7 @@ impl PartiallyTaggedVariant { /// Convert from vector of variants to tuple of vectors consisting of variant's fields fn variants_to_tuple<'lt, I: Iterator>( - self_ty: &syn2::Type, + self_ty: &syn::Type, variants: I, ) -> (Vec<&'lt Ident>, Vec, Vec<&'lt [Attribute]>) { variants.fold( @@ -78,7 +78,7 @@ fn variants_to_tuple<'lt, I: Iterator>( ) } -pub fn impl_partially_tagged_serialize(input: &syn2::DeriveInput) -> Result { +pub fn impl_partially_tagged_serialize(input: &syn::DeriveInput) -> Result { let enum_ = PartiallyTaggedEnum::from_derive_input(input)?; let enum_ident = &enum_.ident; @@ -90,7 +90,7 @@ pub fn impl_partially_tagged_serialize(input: &syn2::DeriveInput) -> Result Result Result { +pub fn impl_partially_tagged_deserialize(input: &syn::DeriveInput) -> Result { let enum_ = PartiallyTaggedEnum::from_derive_input(input)?; let enum_ident = &enum_.ident; @@ -166,7 +166,7 @@ pub fn impl_partially_tagged_deserialize(input: &syn2::DeriveInput) -> Result { - self_ty: &'a syn2::Type, + self_ty: &'a syn::Type, } impl VisitMut for Visitor<'_> { - fn visit_type_mut(&mut self, ty: &mut syn2::Type) { + fn visit_type_mut(&mut self, ty: &mut syn::Type) { match ty { - syn2::Type::Path(path_ty) + syn::Type::Path(path_ty) if path_ty.qself.is_none() && path_ty.path.is_ident("Self") => { *ty = self.self_ty.clone(); } - _ => syn2::visit_mut::visit_type_mut(self, ty), + _ => syn::visit_mut::visit_type_mut(self, ty), } } } @@ -21,7 +21,7 @@ impl VisitMut for Visitor<'_> { /// /// This is required to be able to use `Self` in `PartiallyTaggedSerialize` and `PartiallyTaggedDeserialize`, /// as they define an additional intermediate type during serialization/deserialization. Using `Self` there would refer to an incorrect type. -pub fn resolve_self(self_ty: &syn2::Type, mut resolving_ty: syn2::Type) -> syn2::Type { +pub fn resolve_self(self_ty: &syn::Type, mut resolving_ty: syn::Type) -> syn::Type { Visitor { self_ty }.visit_type_mut(&mut resolving_ty); resolving_ty } @@ -29,7 +29,7 @@ pub fn resolve_self(self_ty: &syn2::Type, mut resolving_ty: syn2::Type) -> syn2: #[cfg(test)] mod tests { use quote::ToTokens; - use syn2::{parse_quote, Type}; + use syn::{parse_quote, Type}; #[test] fn test_resolve_self() { diff --git a/ffi/derive/Cargo.toml b/ffi/derive/Cargo.toml index 5004ea9a52c..6b84b382dc0 100644 --- a/ffi/derive/Cargo.toml +++ b/ffi/derive/Cargo.toml @@ -17,7 +17,7 @@ proc-macro = true [dependencies] iroha_macro_utils = { workspace = true } -syn2 = { workspace = true, features = ["full", "visit", "visit-mut", "extra-traits"] } +syn = { workspace = true, features = ["full", "visit", "visit-mut", "extra-traits"] } quote = { workspace = true } proc-macro2 = { workspace = true } manyhow = { workspace = true } diff --git a/ffi/derive/src/attr_parse/derive.rs b/ffi/derive/src/attr_parse/derive.rs index 7ee73ab107d..19ee35633dd 100644 --- a/ffi/derive/src/attr_parse/derive.rs +++ b/ffi/derive/src/attr_parse/derive.rs @@ -2,7 +2,7 @@ use darling::FromAttributes; use quote::ToTokens; -use syn2::{punctuated::Punctuated, Attribute, Token}; +use syn::{punctuated::Punctuated, Attribute, Token}; use super::getset::GetSetDerive; @@ -20,7 +20,7 @@ pub enum RustcDerive { } impl RustcDerive { - fn try_from_path(path: &syn2::Path) -> Option { + fn try_from_path(path: &syn::Path) -> Option { let ident = path.get_ident()?; match ident.to_string().as_str() { @@ -73,7 +73,7 @@ impl FromAttributes for DeriveAttrs { continue; }; let Some(paths) = accumulator.handle( - list.parse_args_with(Punctuated::::parse_terminated) + list.parse_args_with(Punctuated::::parse_terminated) .map_err(Into::into), ) else { continue; diff --git a/ffi/derive/src/attr_parse/doc.rs b/ffi/derive/src/attr_parse/doc.rs index 253fcf9e491..c3bae65c378 100644 --- a/ffi/derive/src/attr_parse/doc.rs +++ b/ffi/derive/src/attr_parse/doc.rs @@ -1,5 +1,5 @@ use darling::FromAttributes; -use syn2::Attribute; +use syn::Attribute; pub struct DocAttrs { pub attrs: Vec, diff --git a/ffi/derive/src/attr_parse/getset.rs b/ffi/derive/src/attr_parse/getset.rs index 208c949956e..4018cd2452a 100644 --- a/ffi/derive/src/attr_parse/getset.rs +++ b/ffi/derive/src/attr_parse/getset.rs @@ -5,7 +5,7 @@ use std::{collections::hash_map::Entry, str::FromStr}; use parse_display::{Display, FromStr}; use proc_macro2::Span; use rustc_hash::{FxHashMap, FxHashSet}; -use syn2::{parse::ParseStream, punctuated::Punctuated, Attribute, Token}; +use syn::{parse::ParseStream, punctuated::Punctuated, Attribute, Token}; use crate::attr_parse::derive::{Derive, DeriveAttrs}; @@ -19,7 +19,7 @@ pub enum GetSetDerive { } impl GetSetDerive { - pub fn try_from_path(path: &syn2::Path) -> Option { + pub fn try_from_path(path: &syn::Path) -> Option { // try to be smart and handle two cases: // - bare attribute name (like `Getters`, when it's imported) // - fully qualified path (like `getset::Getters`, when it's not imported) @@ -51,7 +51,7 @@ impl GetSetDerive { #[derive(Default, Debug, Eq, PartialEq, Clone)] pub struct GetSetOptions { - pub visibility: Option, + pub visibility: Option, pub with_prefix: bool, } @@ -60,29 +60,29 @@ struct SpannedGetSetOptions { options: GetSetOptions, } -impl syn2::parse::Parse for SpannedGetSetOptions { - fn parse(input: ParseStream) -> syn2::Result { +impl syn::parse::Parse for SpannedGetSetOptions { + fn parse(input: ParseStream) -> syn::Result { let mut result = GetSetOptions::default(); // an accumulator for syn errors? // this is getting out of hand... // we need an accumulator to rule them all! let mut errors = Vec::new(); - let lit = input.parse::()?; + let lit = input.parse::()?; for part in lit.value().split(' ') { if part == "with_prefix" { result.with_prefix = true; - } else if let Ok(vis) = syn2::parse_str::(part) { + } else if let Ok(vis) = syn::parse_str::(part) { if result.visibility.is_none() { result.visibility = Some(vis); } else { - errors.push(syn2::Error::new( + errors.push(syn::Error::new( lit.span(), format!("Failed to parse getset options at {part}: duplicate visibility",), )); } } else { - errors.push(syn2::Error::new(lit.span(), format!("Failed to parse getset options at `{part}`: expected visibility or `with_prefix`"))); + errors.push(syn::Error::new(lit.span(), format!("Failed to parse getset options at `{part}`: expected visibility or `with_prefix`"))); } } @@ -123,9 +123,9 @@ struct SpannedGetSetAttrToken { token: GetSetAttrToken, } -impl syn2::parse::Parse for SpannedGetSetAttrToken { - fn parse(input: ParseStream) -> syn2::Result { - let ident = input.parse::()?; +impl syn::parse::Parse for SpannedGetSetAttrToken { + fn parse(input: ParseStream) -> syn::Result { + let ident = input.parse::()?; match ident.to_string().as_str() { "skip" => Ok(SpannedGetSetAttrToken { @@ -154,7 +154,7 @@ impl syn2::parse::Parse for SpannedGetSetAttrToken { }) } } - _ => Err(syn2::Error::new( + _ => Err(syn::Error::new( ident.span(), "expected one of `get`, `get_copy`, `get_mut`, `set`, `skip`", )), @@ -346,7 +346,7 @@ mod test { use darling::FromAttributes; use quote::quote; use rustc_hash::FxHashMap; - use syn2::parse_quote; + use syn::parse_quote; use super::{GetSetFieldAttrs, GetSetGenMode, GetSetOptions, GetSetStructAttrs}; use crate::parse_attributes; @@ -637,7 +637,7 @@ mod test { use darling::FromAttributes; use proc_macro2::TokenStream; use quote::quote; - use syn2::parse_quote; + use syn::parse_quote; use super::{ GetSetFieldAttrs, GetSetGenMode, GetSetOptions, GetSetStructAttrs, RequestedAccessors, diff --git a/ffi/derive/src/attr_parse/repr.rs b/ffi/derive/src/attr_parse/repr.rs index f845fbd3393..f424c6bcee9 100644 --- a/ffi/derive/src/attr_parse/repr.rs +++ b/ffi/derive/src/attr_parse/repr.rs @@ -7,7 +7,7 @@ use std::str::FromStr; use darling::{error::Accumulator, util::SpannedValue, FromAttributes}; use parse_display::{Display, FromStr}; use proc_macro2::{Delimiter, Span}; -use syn2::{ +use syn::{ parse::{Parse, ParseStream}, punctuated::Punctuated, spanned::Spanned as _, @@ -57,7 +57,7 @@ struct SpannedReprToken { } impl Parse for SpannedReprToken { - fn parse(input: ParseStream) -> syn2::Result { + fn parse(input: ParseStream) -> syn::Result { let (span, token) = input.step(|cursor| { let Some((ident, after_token)) = cursor.ident() else { return Err(cursor.error("Expected repr kind")); @@ -80,7 +80,7 @@ impl Parse for SpannedReprToken { }; span = span.join(group_span.span()).unwrap_or(span); - let alignment = syn2::parse2::(inside_of_group.token_stream())?; + let alignment = syn::parse2::(inside_of_group.token_stream())?; let alignment = alignment.base10_parse::()?; Ok(( @@ -100,7 +100,7 @@ impl Parse for SpannedReprToken { struct ReprTokens(Vec); impl Parse for ReprTokens { - fn parse(input: ParseStream) -> syn2::Result { + fn parse(input: ParseStream) -> syn::Result { Ok(Self( Punctuated::<_, Token![,]>::parse_terminated(input)? .into_iter() @@ -137,7 +137,7 @@ impl FromAttributes for Repr { ), Meta::List(list) => { let Some(tokens) = accumulator.handle( - syn2::parse2::(list.tokens.clone()).map_err(Into::into), + syn::parse2::(list.tokens.clone()).map_err(Into::into), ) else { continue; }; diff --git a/ffi/derive/src/convert.rs b/ffi/derive/src/convert.rs index 9a3c256e337..e3be05e1d25 100644 --- a/ffi/derive/src/convert.rs +++ b/ffi/derive/src/convert.rs @@ -8,7 +8,7 @@ use iroha_macro_utils::{parse_single_list_attr_opt, Emitter}; use manyhow::{emit, error_message}; use proc_macro2::{Delimiter, Span, TokenStream}; use quote::quote; -use syn2::{parse::ParseStream, spanned::Spanned as _, visit::Visit as _, Attribute, Field, Ident}; +use syn::{parse::ParseStream, spanned::Spanned as _, visit::Visit as _, Attribute, Field, Ident}; use crate::attr_parse::{ derive::DeriveAttrs, @@ -43,8 +43,8 @@ struct SpannedFfiTypeToken { token: FfiTypeToken, } -impl syn2::parse::Parse for SpannedFfiTypeToken { - fn parse(input: ParseStream) -> syn2::Result { +impl syn::parse::Parse for SpannedFfiTypeToken { + fn parse(input: ParseStream) -> syn::Result { let (span, token) = input.step(|cursor| { let Some((token, after_token)) = cursor.ident() else { return Err(cursor.error("expected ffi type kind")); @@ -75,13 +75,13 @@ impl syn2::parse::Parse for SpannedFfiTypeToken { match token.as_str() { "robust" => Ok(((span, FfiTypeToken::UnsafeRobust), after_group)), "non_owning" => Ok(((span, FfiTypeToken::UnsafeNonOwning), after_group)), - other => Err(syn2::Error::new( + other => Err(syn::Error::new( token.span(), format!("unknown unsafe ffi type kind: {other}"), )), } } - other => Err(syn2::Error::new( + other => Err(syn::Error::new( span, format!("unknown unsafe ffi type kind: {other}"), )), @@ -100,15 +100,15 @@ pub enum FfiTypeKindAttribute { Local, } -impl syn2::parse::Parse for FfiTypeKindAttribute { - fn parse(input: ParseStream) -> syn2::Result { +impl syn::parse::Parse for FfiTypeKindAttribute { + fn parse(input: ParseStream) -> syn::Result { input.call(SpannedFfiTypeToken::parse).and_then(|token| { Ok(match token.token { FfiTypeToken::Opaque => FfiTypeKindAttribute::Opaque, FfiTypeToken::UnsafeRobust => FfiTypeKindAttribute::UnsafeRobust, FfiTypeToken::Local => FfiTypeKindAttribute::Local, other => { - return Err(syn2::Error::new( + return Err(syn::Error::new( token.span, format!("`{other}` cannot be used on a type"), )) @@ -124,13 +124,13 @@ pub enum FfiTypeKindFieldAttribute { UnsafeNonOwning, } -impl syn2::parse::Parse for FfiTypeKindFieldAttribute { - fn parse(input: ParseStream) -> syn2::Result { +impl syn::parse::Parse for FfiTypeKindFieldAttribute { + fn parse(input: ParseStream) -> syn::Result { input.call(SpannedFfiTypeToken::parse).and_then(|token| { Ok(match token.token { FfiTypeToken::UnsafeNonOwning => FfiTypeKindFieldAttribute::UnsafeNonOwning, other => { - return Err(syn2::Error::new( + return Err(syn::Error::new( token.span, format!("`{other}` cannot be used on a field"), )) @@ -166,9 +166,9 @@ pub type FfiTypeData = darling::ast::Data, FfiTypeF pub type FfiTypeFields = darling::ast::Fields; pub struct FfiTypeInput { - pub vis: syn2::Visibility, - pub ident: syn2::Ident, - pub generics: syn2::Generics, + pub vis: syn::Visibility, + pub ident: syn::Ident, + pub generics: syn::Generics, pub data: FfiTypeData, pub doc_attrs: DocAttrs, pub derive_attr: DeriveAttrs, @@ -177,7 +177,7 @@ pub struct FfiTypeInput { pub getset_attr: GetSetStructAttrs, pub span: Span, /// The original DeriveInput this structure was parsed from - pub ast: syn2::DeriveInput, + pub ast: syn::DeriveInput, } impl FfiTypeInput { @@ -188,7 +188,7 @@ impl FfiTypeInput { } impl darling::FromDeriveInput for FfiTypeInput { - fn from_derive_input(input: &syn2::DeriveInput) -> darling::Result { + fn from_derive_input(input: &syn::DeriveInput) -> darling::Result { let vis = input.vis.clone(); let ident = input.ident.clone(); let generics = input.generics.clone(); @@ -218,14 +218,14 @@ impl darling::FromDeriveInput for FfiTypeInput { #[derive(FromVariant)] pub struct FfiTypeVariant { - pub ident: syn2::Ident, - pub discriminant: Option, + pub ident: syn::Ident, + pub discriminant: Option, pub fields: darling::ast::Fields, } pub struct FfiTypeField { - pub ident: Option, - pub ty: syn2::Type, + pub ident: Option, + pub ty: syn::Type, pub doc_attrs: DocAttrs, pub ffi_type_attr: FfiTypeFieldAttr, pub getset_attr: GetSetFieldAttrs, @@ -248,7 +248,7 @@ impl FromField for FfiTypeField { } } -pub fn derive_ffi_type(emitter: &mut Emitter, input: &syn2::DeriveInput) -> TokenStream { +pub fn derive_ffi_type(emitter: &mut Emitter, input: &syn::DeriveInput) -> TokenStream { let Some(mut input) = emitter.handle(FfiTypeInput::from_derive_input(input)) else { return quote!(); }; @@ -312,7 +312,7 @@ pub fn derive_ffi_type(emitter: &mut Emitter, input: &syn2::DeriveInput) -> Toke let repr_c_impl = { let predicates = &mut input.generics.make_where_clause().predicates; - let add_bound = |ty| predicates.push(syn2::parse_quote! {#ty: iroha_ffi::ReprC}); + let add_bound = |ty| predicates.push(syn::parse_quote! {#ty: iroha_ffi::ReprC}); if item.style == Style::Unit { emit!( @@ -339,7 +339,7 @@ pub fn derive_ffi_type(emitter: &mut Emitter, input: &syn2::DeriveInput) -> Toke } /// Before deriving this trait make sure that all invariants are upheld -fn derive_unsafe_repr_c(name: &Ident, generics: &syn2::Generics) -> TokenStream { +fn derive_unsafe_repr_c(name: &Ident, generics: &syn::Generics) -> TokenStream { let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); quote! { @@ -348,7 +348,7 @@ fn derive_unsafe_repr_c(name: &Ident, generics: &syn2::Generics) -> TokenStream } } -fn derive_ffi_type_for_opaque_item(name: &Ident, generics: &syn2::Generics) -> TokenStream { +fn derive_ffi_type_for_opaque_item(name: &Ident, generics: &syn::Generics) -> TokenStream { let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); quote! { @@ -468,7 +468,7 @@ fn derive_ffi_type_for_fieldless_enum( fn derive_ffi_type_for_data_carrying_enum( emitter: &mut Emitter, enum_name: &Ident, - mut generics: syn2::Generics, + mut generics: syn::Generics, variants: &[SpannedValue], local: bool, ) -> TokenStream { @@ -596,7 +596,7 @@ fn derive_ffi_type_for_data_carrying_enum( }; non_local_where_clause.predicates.push( - syn2::parse_quote! {#ty: iroha_ffi::repr_c::NonLocal<<#ty as iroha_ffi::ir::Ir>::Type>}, + syn::parse_quote! {#ty: iroha_ffi::repr_c::NonLocal<<#ty as iroha_ffi::ir::Ir>::Type>}, ); } @@ -687,7 +687,7 @@ fn derive_ffi_type_for_repr_c(emitter: &mut Emitter, input: &FfiTypeInput) -> To fn gen_data_carrying_repr_c_enum( emitter: &mut Emitter, enum_name: &Ident, - generics: &syn2::Generics, + generics: &syn::Generics, variants: &[SpannedValue], ) -> (Ident, TokenStream) { let (payload_name, payload) = @@ -718,7 +718,7 @@ fn gen_data_carrying_repr_c_enum( fn gen_data_carrying_enum_payload( emitter: &mut Emitter, enum_name: &Ident, - generics: &syn2::Generics, + generics: &syn::Generics, variants: &[SpannedValue], ) -> (Ident, TokenStream) { let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); @@ -760,7 +760,7 @@ fn gen_data_carrying_enum_payload( fn gen_discriminants( enum_name: &Ident, variants: &[SpannedValue], - tag_type: &syn2::Type, + tag_type: &syn::Type, ) -> (Vec, Vec) { let variant_names: Vec<_> = variants.iter().map(|v| &v.ident).collect(); let discriminant_values = variant_discriminants(variants); @@ -837,8 +837,8 @@ fn verify_is_non_owning(emitter: &mut Emitter, data: &FfiTypeData) { struct PtrVisitor<'a> { emitter: &'a mut Emitter, } - impl syn2::visit::Visit<'_> for PtrVisitor<'_> { - fn visit_type_ptr(&mut self, node: &syn2::TypePtr) { + impl syn::visit::Visit<'_> for PtrVisitor<'_> { + fn visit_type_ptr(&mut self, node: &syn::TypePtr) { emit!(self.emitter, node, "Raw pointer found. If the pointer doesn't own the data, attach `#[ffi_type(unsafe {{non_owning}})` to the field. Otherwise, mark the entire type as opaque with `#[ffi_type(opaque)]`"); } } @@ -872,7 +872,7 @@ fn get_enum_repr_type( enum_name: &Ident, repr: &Repr, is_empty: bool, -) -> syn2::Type { +) -> syn::Type { let Some(kind) = repr.kind else { // empty enums are not allowed to have a `#[repr]` attribute // it's an error to use an `#[derive(FfiType)]` on them @@ -884,7 +884,7 @@ fn get_enum_repr_type( "Enum representation is not specified. Try adding `#[repr(u32)]` or similar" ); } - return syn2::parse_quote! {u32}; + return syn::parse_quote! {u32}; }; let ReprKind::Primitive(primitive) = &*kind else { @@ -893,17 +893,17 @@ fn get_enum_repr_type( &kind.span(), "Enum should have a primitive representation (like `#[repr(u32)]`)" ); - return syn2::parse_quote! {u32}; + return syn::parse_quote! {u32}; }; match primitive { - ReprPrimitive::U8 => syn2::parse_quote! {u8}, - ReprPrimitive::U16 => syn2::parse_quote! {u16}, - ReprPrimitive::U32 => syn2::parse_quote! {u32}, - ReprPrimitive::U64 => syn2::parse_quote! {u64}, - ReprPrimitive::I8 => syn2::parse_quote! {i8}, - ReprPrimitive::I16 => syn2::parse_quote! {i16}, - ReprPrimitive::I32 => syn2::parse_quote! {i32}, + ReprPrimitive::U8 => syn::parse_quote! {u8}, + ReprPrimitive::U16 => syn::parse_quote! {u16}, + ReprPrimitive::U32 => syn::parse_quote! {u32}, + ReprPrimitive::U64 => syn::parse_quote! {u64}, + ReprPrimitive::I8 => syn::parse_quote! {i8}, + ReprPrimitive::I16 => syn::parse_quote! {i16}, + ReprPrimitive::I32 => syn::parse_quote! {i32}, _ => { emit!( @@ -911,7 +911,7 @@ fn get_enum_repr_type( &kind.span(), "Enum representation is not supported" ); - syn2::parse_quote! {u32} + syn::parse_quote! {u32} } } } @@ -935,11 +935,11 @@ fn gen_enum_tag_type(variants: &[SpannedValue]) -> TokenStream { } fn split_for_impl( - generics: &syn2::Generics, + generics: &syn::Generics, ) -> ( - syn2::punctuated::Punctuated, - syn2::TypeGenerics<'_>, - Option<&syn2::WhereClause>, + syn::punctuated::Punctuated, + syn::TypeGenerics<'_>, + Option<&syn::WhereClause>, ) { let impl_generics = generics.params.clone(); let (_, ty_generics, where_clause) = generics.split_for_impl(); diff --git a/ffi/derive/src/ffi_fn.rs b/ffi/derive/src/ffi_fn.rs index f90a4763191..2b16204a07d 100644 --- a/ffi/derive/src/ffi_fn.rs +++ b/ffi/derive/src/ffi_fn.rs @@ -1,17 +1,17 @@ use proc_macro2::TokenStream; use quote::quote; -use syn2::{visit_mut::VisitMut, Ident}; +use syn::{visit_mut::VisitMut, Ident}; use crate::{ getset_gen::{gen_resolve_type, gen_store_name}, impl_visitor::{Arg, FnDescriptor}, }; -fn prune_fn_declaration_attributes<'a>(attrs: &[&'a syn2::Attribute]) -> Vec<&'a syn2::Attribute> { +fn prune_fn_declaration_attributes<'a>(attrs: &[&'a syn::Attribute]) -> Vec<&'a syn::Attribute> { let mut pruned = Vec::new(); for attr in attrs { - if **attr == syn2::parse_quote! {#[inline]} { + if **attr == syn::parse_quote! {#[inline]} { continue; } @@ -88,7 +88,7 @@ fn gen_doc(fn_descriptor: &FnDescriptor, trait_name: Option<&Ident>) -> String { let self_type = fn_descriptor .self_ty .as_ref() - .and_then(syn2::Path::get_ident); + .and_then(syn::Path::get_ident); let path = self_type.map_or_else( || method_name.to_string(), @@ -213,9 +213,9 @@ pub struct InjectColon; impl VisitMut for InjectColon { fn visit_angle_bracketed_generic_arguments_mut( &mut self, - i: &mut syn2::AngleBracketedGenericArguments, + i: &mut syn::AngleBracketedGenericArguments, ) { - i.colon2_token = Some(syn2::parse_quote!(::)); + i.colon2_token = Some(syn::parse_quote!(::)); } } diff --git a/ffi/derive/src/getset_gen.rs b/ffi/derive/src/getset_gen.rs index 89c628de71b..065fadea13d 100644 --- a/ffi/derive/src/getset_gen.rs +++ b/ffi/derive/src/getset_gen.rs @@ -6,7 +6,7 @@ use manyhow::emit; use proc_macro2::TokenStream; use quote::quote; use rustc_hash::FxHashMap; -use syn2::{parse_quote, visit::Visit, Ident}; +use syn::{parse_quote, visit::Visit, Ident}; use crate::{ attr_parse::{ @@ -141,7 +141,7 @@ fn gen_derived_method<'ast>( } } -fn gen_derived_method_sig(field: &FfiTypeField, mode: GetSetGenMode) -> syn2::Signature { +fn gen_derived_method_sig(field: &FfiTypeField, mode: GetSetGenMode) -> syn::Signature { let field_name = field.ident.as_ref().expect("BUG: Field name not defined"); let field_ty = &field.ty; @@ -176,7 +176,7 @@ pub fn gen_store_name(arg_name: &Ident) -> Ident { struct FfiTypeResolver<'itm>(&'itm Ident, TokenStream); impl<'itm> Visit<'itm> for FfiTypeResolver<'itm> { - fn visit_trait_bound(&mut self, i: &'itm syn2::TraitBound) { + fn visit_trait_bound(&mut self, i: &'itm syn::TraitBound) { let trait_ = i.path.segments.last().expect("Defined"); let arg_name = self.0; diff --git a/ffi/derive/src/impl_visitor.rs b/ffi/derive/src/impl_visitor.rs index 790728522e0..fde7e373c5f 100644 --- a/ffi/derive/src/impl_visitor.rs +++ b/ffi/derive/src/impl_visitor.rs @@ -5,7 +5,7 @@ use iroha_macro_utils::Emitter; use manyhow::emit; use proc_macro2::Span; -use syn2::{ +use syn::{ parse_quote, visit::{visit_signature, Visit}, visit_mut::VisitMut, @@ -33,7 +33,7 @@ impl Arg { &self.type_ } pub fn src_type_is_empty_tuple(&self) -> bool { - matches!(self.src_type_resolved(), Type::Tuple(syn2::TypeTuple { ref elems, .. }) if elems.is_empty()) + matches!(self.src_type_resolved(), Type::Tuple(syn::TypeTuple { ref elems, .. }) if elems.is_empty()) } pub fn src_type_resolved(&self) -> Type { resolve_type(self.self_ty.as_ref(), self.type_.clone()) @@ -93,7 +93,7 @@ pub struct FnDescriptor<'ast> { // TODO: Could just be a part of all attrs? pub doc: Vec<&'ast Attribute>, /// Original signature of the method - pub sig: syn2::Signature, + pub sig: syn::Signature, /// Receiver argument, i.e. `self` pub receiver: Option, @@ -124,7 +124,7 @@ struct FnVisitor<'ast, 'emitter> { self_ty: Option<&'ast Path>, /// Original signature of the method - sig: Option<&'ast syn2::Signature>, + sig: Option<&'ast syn::Signature>, /// Receiver argument, i.e. `self` receiver: Option, @@ -138,7 +138,7 @@ struct FnVisitor<'ast, 'emitter> { } impl<'ast> ImplDescriptor<'ast> { - pub fn from_impl(emitter: &mut Emitter, node: &'ast syn2::ItemImpl) -> Option { + pub fn from_impl(emitter: &mut Emitter, node: &'ast syn::ItemImpl) -> Option { let mut visitor = ImplVisitor::new(emitter); visitor.visit_item_impl(node); @@ -167,7 +167,7 @@ impl<'ast> FnDescriptor<'ast> { emitter: &mut Emitter, self_ty: &'ast Path, trait_name: Option<&'ast Path>, - node: &'ast syn2::ImplItemFn, + node: &'ast syn::ImplItemFn, ) -> Option { let mut visitor = FnVisitor::new(emitter, Some(self_ty), trait_name); @@ -175,7 +175,7 @@ impl<'ast> FnDescriptor<'ast> { FnDescriptor::from_visitor(visitor) } - pub fn from_fn(emitter: &mut Emitter, node: &'ast syn2::ItemFn) -> Option { + pub fn from_fn(emitter: &mut Emitter, node: &'ast syn::ItemFn) -> Option { let mut visitor = FnVisitor::new(emitter, None, None); visitor.visit_item_fn(node); @@ -289,14 +289,14 @@ impl<'ast, 'emitter> FnVisitor<'ast, 'emitter> { } impl<'ast> Visit<'ast> for ImplVisitor<'ast, '_> { - fn visit_attribute(&mut self, node: &'ast syn2::Attribute) { + fn visit_attribute(&mut self, node: &'ast syn::Attribute) { self.attrs.push(node); } - fn visit_generic_param(&mut self, node: &'ast syn2::GenericParam) { + fn visit_generic_param(&mut self, node: &'ast syn::GenericParam) { emit!(self.emitter, node, "Generics are not supported"); self.fatal = true; } - fn visit_item_impl(&mut self, node: &'ast syn2::ItemImpl) { + fn visit_item_impl(&mut self, node: &'ast syn::ItemImpl) { if node.unsafety.is_some() { emit!(self.emitter, node.unsafety, "Unsafe impl not supported"); } @@ -315,14 +315,14 @@ impl<'ast> Visit<'ast> for ImplVisitor<'ast, '_> { let self_ty = self.self_ty.expect("Defined"); self.associated_types .extend(node.items.iter().filter_map(|item| match item { - syn2::ImplItem::Type(associated_type) => { + syn::ImplItem::Type(associated_type) => { Some((&associated_type.ident, &associated_type.ty)) } _ => None, })); for item in &node.items { - if let syn2::ImplItem::Fn(method) = item { + if let syn::ImplItem::Fn(method) = item { // NOTE: private methods in inherent impl are skipped if self.trait_name.is_none() && !matches!(method.vis, Visibility::Public(_)) { continue; @@ -338,7 +338,7 @@ impl<'ast> Visit<'ast> for ImplVisitor<'ast, '_> { } impl<'ast> Visit<'ast> for FnVisitor<'ast, '_> { - fn visit_attribute(&mut self, node: &'ast syn2::Attribute) { + fn visit_attribute(&mut self, node: &'ast syn::Attribute) { if is_doc_attr(node) { self.doc.push(node); } else { @@ -346,14 +346,14 @@ impl<'ast> Visit<'ast> for FnVisitor<'ast, '_> { } } - fn visit_abi(&mut self, node: &'ast syn2::Abi) { + fn visit_abi(&mut self, node: &'ast syn::Abi) { emit!(self.emitter, node, "You shouldn't specify function ABI"); } - fn visit_generic_param(&mut self, node: &'ast syn2::GenericParam) { + fn visit_generic_param(&mut self, node: &'ast syn::GenericParam) { emit!(self.emitter, node, "Generics are not supported"); self.fatal = true; } - fn visit_impl_item_fn(&mut self, node: &'ast syn2::ImplItemFn) { + fn visit_impl_item_fn(&mut self, node: &'ast syn::ImplItemFn) { for attr in &node.attrs { self.visit_attribute(attr); } @@ -362,7 +362,7 @@ impl<'ast> Visit<'ast> for FnVisitor<'ast, '_> { self.visit_visibility(&node.vis); self.visit_signature(&node.sig); } - fn visit_item_fn(&mut self, node: &'ast syn2::ItemFn) { + fn visit_item_fn(&mut self, node: &'ast syn::ItemFn) { for attr in &node.attrs { self.visit_attribute(attr); } @@ -376,7 +376,7 @@ impl<'ast> Visit<'ast> for FnVisitor<'ast, '_> { emit!(self.emitter, node, "Private methods should not be exported"); } } - fn visit_signature(&mut self, node: &'ast syn2::Signature) { + fn visit_signature(&mut self, node: &'ast syn::Signature) { if node.constness.is_some() { emit!( self.emitter, @@ -416,7 +416,7 @@ impl<'ast> Visit<'ast> for FnVisitor<'ast, '_> { visit_signature(self, node); } - fn visit_receiver(&mut self, node: &'ast syn2::Receiver) { + fn visit_receiver(&mut self, node: &'ast syn::Receiver) { for it in &node.attrs { self.visit_attribute(it); } @@ -445,12 +445,12 @@ impl<'ast> Visit<'ast> for FnVisitor<'ast, '_> { self.receiver = Some(Arg::new(self.self_ty.cloned(), handle_name, src_type)); } - fn visit_pat_type(&mut self, node: &'ast syn2::PatType) { + fn visit_pat_type(&mut self, node: &'ast syn::PatType) { for it in &node.attrs { self.visit_attribute(it); } - if let syn2::Pat::Ident(ident) = &*node.pat { + if let syn::Pat::Ident(ident) = &*node.pat { self.visit_pat_ident(ident); } else { // if we don't have an identifier (when pattern matching is used), we generate a synthetic argument name @@ -460,7 +460,7 @@ impl<'ast> Visit<'ast> for FnVisitor<'ast, '_> { self.add_input_arg(&node.ty); } - fn visit_pat_ident(&mut self, node: &'ast syn2::PatIdent) { + fn visit_pat_ident(&mut self, node: &'ast syn::PatIdent) { for it in &node.attrs { self.visit_attribute(it); } @@ -485,17 +485,17 @@ impl<'ast> Visit<'ast> for FnVisitor<'ast, '_> { self.curr_arg_name = Some(&node.ident); } - fn visit_return_type(&mut self, node: &'ast syn2::ReturnType) { + fn visit_return_type(&mut self, node: &'ast syn::ReturnType) { match node { - syn2::ReturnType::Default => {} - syn2::ReturnType::Type(_, src_type) => { + syn::ReturnType::Default => {} + syn::ReturnType::Type(_, src_type) => { self.add_output_arg(src_type); } } } } -fn is_doc_attr(attr: &syn2::Attribute) -> bool { +fn is_doc_attr(attr: &syn::Attribute) -> bool { attr.path().is_ident("doc") } @@ -538,14 +538,14 @@ impl VisitMut for TypeImplTraitResolver { if let Type::ImplTrait(impl_trait) = node { for bound in &impl_trait.bounds { - if let syn2::TypeParamBound::Trait(trait_) = bound { + if let syn::TypeParamBound::Trait(trait_) = bound { let trait_ = trait_.path.segments.last().expect("Defined"); match trait_.ident.to_string().as_str() { "IntoIterator" | "ExactSizeIterator" => { - if let syn2::PathArguments::AngleBracketed(args) = &trait_.arguments { + if let syn::PathArguments::AngleBracketed(args) = &trait_.arguments { for arg in &args.args { - if let syn2::GenericArgument::AssocType(binding) = arg { + if let syn::GenericArgument::AssocType(binding) = arg { if binding.ident == "Item" { let mut ty = binding.ty.clone(); TypeImplTraitResolver.visit_type_mut(&mut ty); @@ -556,19 +556,19 @@ impl VisitMut for TypeImplTraitResolver { } } "Into" => { - if let syn2::PathArguments::AngleBracketed(args) = &trait_.arguments { + if let syn::PathArguments::AngleBracketed(args) = &trait_.arguments { for arg in &args.args { - if let syn2::GenericArgument::Type(type_) = arg { + if let syn::GenericArgument::Type(type_) = arg { new_node = Some(type_.clone()); } } } } "AsRef" => { - if let syn2::PathArguments::AngleBracketed(args) = &trait_.arguments { + if let syn::PathArguments::AngleBracketed(args) = &trait_.arguments { for arg in &args.args { - if let syn2::GenericArgument::Type(type_) = arg { - new_node = Some(syn2::parse_quote!(&#type_)); + if let syn::GenericArgument::Type(type_) = arg { + new_node = Some(syn::parse_quote!(&#type_)); } } } @@ -585,7 +585,7 @@ impl VisitMut for TypeImplTraitResolver { } } -fn last_seg_ident(path: &syn2::Path) -> &Ident { +fn last_seg_ident(path: &syn::Path) -> &Ident { &path.segments.last().expect("Defined").ident } @@ -594,8 +594,8 @@ pub fn unwrap_result_type(node: &Type) -> Option<(&Type, &Type)> { let last_seg = type_.path.segments.last().expect("Defined"); if last_seg.ident == "Result" { - if let syn2::PathArguments::AngleBracketed(args) = &last_seg.arguments { - if let (syn2::GenericArgument::Type(ok), syn2::GenericArgument::Type(err)) = + if let syn::PathArguments::AngleBracketed(args) = &last_seg.arguments { + if let (syn::GenericArgument::Type(ok), syn::GenericArgument::Type(err)) = (&args.args[0], &args.args[1]) { return Some((ok, err)); diff --git a/ffi/derive/src/lib.rs b/ffi/derive/src/lib.rs index 0d56d35a2dd..195c15ec0aa 100644 --- a/ffi/derive/src/lib.rs +++ b/ffi/derive/src/lib.rs @@ -5,7 +5,7 @@ use iroha_macro_utils::Emitter; use manyhow::{emit, manyhow}; use proc_macro2::TokenStream; use quote::quote; -use syn2::Item; +use syn::Item; use wrapper::wrap_method; use crate::{ @@ -22,12 +22,12 @@ mod wrapper; struct FfiItems(Vec); -impl syn2::parse::Parse for FfiItems { - fn parse(input: syn2::parse::ParseStream) -> syn2::Result { +impl syn::parse::Parse for FfiItems { + fn parse(input: syn::parse::ParseStream) -> syn::Result { let mut items = Vec::new(); while !input.is_empty() { - let input = input.parse::()?; + let input = input.parse::()?; let input = FfiTypeInput::from_derive_input(&input)?; items.push(input); @@ -39,15 +39,15 @@ impl syn2::parse::Parse for FfiItems { /// A test utility function that parses multiple attributes #[cfg(test)] -fn parse_attributes(ts: TokenStream) -> Vec { - struct Attributes(Vec); - impl syn2::parse::Parse for Attributes { - fn parse(input: syn2::parse::ParseStream) -> syn2::Result { - syn2::Attribute::parse_outer(input).map(Attributes) +fn parse_attributes(ts: TokenStream) -> Vec { + struct Attributes(Vec); + impl syn::parse::Parse for Attributes { + fn parse(input: syn::parse::ParseStream) -> syn::Result { + syn::Attribute::parse_outer(input).map(Attributes) } } - syn2::parse2::(ts) + syn::parse2::(ts) .expect("Failed to parse attributes") .0 } @@ -76,7 +76,7 @@ fn parse_attributes(ts: TokenStream) -> Vec { #[manyhow] #[proc_macro] pub fn ffi(input: TokenStream) -> TokenStream { - let items = match syn2::parse2::(input) { + let items = match syn::parse2::(input) { Ok(items) => items.0, Err(err) => return err.to_compile_error(), }; @@ -86,7 +86,7 @@ pub fn ffi(input: TokenStream) -> TokenStream { let items = items .into_iter() .map(|item| { - if !matches!(item.vis, syn2::Visibility::Public(_)) { + if !matches!(item.vis, syn::Visibility::Public(_)) { emit!(emitter, item.span, "Only public types are allowed in FFI"); } @@ -206,11 +206,11 @@ pub fn ffi(input: TokenStream) -> TokenStream { pub fn ffi_type_derive(input: TokenStream) -> TokenStream { let mut emitter = Emitter::new(); - let Some(item) = emitter.handle(syn2::parse2::(input)) else { + let Some(item) = emitter.handle(syn::parse2::(input)) else { return emitter.finish_token_stream(); }; - if !matches!(item.vis, syn2::Visibility::Public(_)) { + if !matches!(item.vis, syn::Visibility::Public(_)) { emit!(emitter, item, "Only public types are allowed in FFI"); } @@ -288,7 +288,7 @@ pub fn ffi_type_derive(input: TokenStream) -> TokenStream { #[manyhow] #[proc_macro_attribute] pub fn ffi_export(attr: TokenStream, item: TokenStream) -> TokenStream { - let item = match syn2::parse2::(item) { + let item = match syn::parse2::(item) { Ok(item) => item, Err(err) => return err.to_compile_error(), }; @@ -329,7 +329,7 @@ pub fn ffi_export(attr: TokenStream, item: TokenStream) -> TokenStream { } Item::Struct(item) => { // re-parse as a DeriveInput to utilize darling - let input = syn2::parse2(quote!(#item)).unwrap(); + let input = syn::parse2(quote!(#item)).unwrap(); let Some(input) = emitter.handle(FfiTypeInput::from_derive_input(&input)) else { return emitter.finish_token_stream(); }; @@ -429,7 +429,7 @@ pub fn ffi_export(attr: TokenStream, item: TokenStream) -> TokenStream { #[manyhow] #[proc_macro_attribute] pub fn ffi_import(attr: TokenStream, item: TokenStream) -> TokenStream { - let item = match syn2::parse2::(item) { + let item = match syn::parse2::(item) { Ok(item) => item, Err(err) => return err.to_compile_error(), }; diff --git a/ffi/derive/src/wrapper.rs b/ffi/derive/src/wrapper.rs index eb8fab7d9b0..a10a1bcade1 100644 --- a/ffi/derive/src/wrapper.rs +++ b/ffi/derive/src/wrapper.rs @@ -2,7 +2,7 @@ use iroha_macro_utils::Emitter; use manyhow::emit; use proc_macro2::{Span, TokenStream}; use quote::quote; -use syn2::{parse_quote, visit_mut::VisitMut, Attribute, Ident, Type}; +use syn::{parse_quote, visit_mut::VisitMut, Attribute, Ident, Type}; use crate::{ attr_parse::derive::{Derive, RustcDerive}, @@ -22,7 +22,7 @@ fn gen_ref_mut_name(name: &Ident) -> Ident { Ident::new(&format!("RefMut{name}"), Span::call_site()) } -fn add_handle_bound(name: &Ident, generics: &mut syn2::Generics) { +fn add_handle_bound(name: &Ident, generics: &mut syn::Generics) { let cloned_generics = generics.clone(); let (_, ty_generics, _) = cloned_generics.split_for_impl(); @@ -32,7 +32,7 @@ fn add_handle_bound(name: &Ident, generics: &mut syn2::Generics) { .push(parse_quote! {#name #ty_generics: iroha_ffi::Handle}); } -fn impl_clone_for_opaque(name: &Ident, generics: &syn2::Generics) -> TokenStream { +fn impl_clone_for_opaque(name: &Ident, generics: &syn::Generics) -> TokenStream { let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); quote! { @@ -53,7 +53,7 @@ fn impl_clone_for_opaque(name: &Ident, generics: &syn2::Generics) -> TokenStream } } -fn impl_default_for_opaque(name: &Ident, generics: &syn2::Generics) -> TokenStream { +fn impl_default_for_opaque(name: &Ident, generics: &syn::Generics) -> TokenStream { let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); quote! { @@ -74,11 +74,11 @@ fn impl_default_for_opaque(name: &Ident, generics: &syn2::Generics) -> TokenStre } } -fn impl_eq_for_opaque(name: &Ident, generics: &syn2::Generics) -> TokenStream { +fn impl_eq_for_opaque(name: &Ident, generics: &syn::Generics) -> TokenStream { let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); quote! { impl #impl_generics Eq for #name #ty_generics #where_clause {} } } -fn impl_partial_eq_for_opaque(name: &Ident, generics: &syn2::Generics) -> TokenStream { +fn impl_partial_eq_for_opaque(name: &Ident, generics: &syn::Generics) -> TokenStream { let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); quote! { @@ -99,7 +99,7 @@ fn impl_partial_eq_for_opaque(name: &Ident, generics: &syn2::Generics) -> TokenS } } -fn impl_partial_ord_for_opaque(name: &Ident, generics: &syn2::Generics) -> TokenStream { +fn impl_partial_ord_for_opaque(name: &Ident, generics: &syn::Generics) -> TokenStream { let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); quote! { @@ -110,7 +110,7 @@ fn impl_partial_ord_for_opaque(name: &Ident, generics: &syn2::Generics) -> Token } } } -fn impl_ord_for_opaque(name: &Ident, generics: &syn2::Generics) -> TokenStream { +fn impl_ord_for_opaque(name: &Ident, generics: &syn::Generics) -> TokenStream { let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); quote! { @@ -294,7 +294,7 @@ pub fn wrap_as_opaque(emitter: &mut Emitter, mut input: FfiTypeInput) -> TokenSt } #[allow(clippy::too_many_lines)] -fn gen_impl_ffi(name: &Ident, generics: &syn2::Generics) -> TokenStream { +fn gen_impl_ffi(name: &Ident, generics: &syn::Generics) -> TokenStream { let mut ref_generics = generics.clone(); let ref_name = gen_ref_name(name); @@ -308,7 +308,7 @@ fn gen_impl_ffi(name: &Ident, generics: &syn2::Generics) -> TokenStream { let lifetime_bounded_where_clause = generics .type_params() .map(|param| parse_quote! {#param: #lifetime}) - .collect::>(); + .collect::>(); let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); let (ref_impl_generics, ref_ty_generics, _) = ref_generics.split_for_impl(); @@ -518,7 +518,7 @@ pub fn wrap_impl_items(impl_desc: &ImplDescriptor) -> TokenStream { quote! { #(#result)* } } -fn gen_ref_wrapper_signature(fn_descriptor: &FnDescriptor) -> syn2::Signature { +fn gen_ref_wrapper_signature(fn_descriptor: &FnDescriptor) -> syn::Signature { let mut signature = gen_wrapper_signature(fn_descriptor); let add_lifetime = fn_descriptor @@ -535,7 +535,7 @@ fn gen_ref_wrapper_signature(fn_descriptor: &FnDescriptor) -> syn2::Signature { signature } -fn gen_wrapper_signature(fn_descriptor: &FnDescriptor) -> syn2::Signature { +fn gen_wrapper_signature(fn_descriptor: &FnDescriptor) -> syn::Signature { let mut signature = fn_descriptor.sig.clone(); let mut type_impl_trait_resolver = TypeImplTraitResolver; @@ -585,7 +585,7 @@ fn gen_self_ref_method( let fn_name = &fn_descriptor.sig.ident; let args = fn_descriptor.sig.inputs.iter().filter_map(|input| { - if let syn2::FnArg::Typed(arg) = input { + if let syn::FnArg::Typed(arg) = input { return Some(&arg.pat); } @@ -619,7 +619,7 @@ pub fn wrap_method(fn_descriptor: &FnDescriptor, trait_name: Option<&Ident>) -> fn wrap_method_with_signature( fn_descriptor: &FnDescriptor, trait_name: Option<&Ident>, - signature: &syn2::Signature, + signature: &syn::Signature, ) -> TokenStream { let ffi_fn_name = ffi_fn::gen_fn_name(fn_descriptor, trait_name); let method_body = gen_wrapper_method_body(fn_descriptor, &ffi_fn_name); @@ -629,7 +629,7 @@ fn wrap_method_with_signature( fn wrap_method_with_signature_and_body( fn_descriptor: &FnDescriptor, trait_name: Option<&Ident>, - signature: &syn2::Signature, + signature: &syn::Signature, method_body: &TokenStream, ) -> TokenStream { let ffi_fn_attrs = &fn_descriptor.attrs; @@ -789,7 +789,7 @@ impl WrapperTypeResolver { } } impl VisitMut for WrapperTypeResolver { - fn visit_receiver_mut(&mut self, i: &mut syn2::Receiver) { + fn visit_receiver_mut(&mut self, i: &mut syn::Receiver) { if i.reference.is_none() { i.mutability = None; } @@ -797,10 +797,10 @@ impl VisitMut for WrapperTypeResolver { // we do NOT want to visit the type in the receiver: // 1. what can actually go in there is severely limited // 2. in syn 2.0 even &self has a reconstructed type &Self, which, when patched, leads to an incorrect rust syntax - // syn2::visit_mut::visit_receiver_mut(self, i); + // syn::visit_mut::visit_receiver_mut(self, i); } - fn visit_type_mut(&mut self, i: &mut syn2::Type) { + fn visit_type_mut(&mut self, i: &mut syn::Type) { if self.0 { // Patch return type to facilitate returning types referencing local store *i = parse_quote! {<#i as iroha_ffi::FfiWrapperType>::ReturnType}; @@ -809,10 +809,10 @@ impl VisitMut for WrapperTypeResolver { *i = parse_quote! {<#i as iroha_ffi::FfiWrapperType>::InputType}; } } - fn visit_return_type_mut(&mut self, i: &mut syn2::ReturnType) { + fn visit_return_type_mut(&mut self, i: &mut syn::ReturnType) { self.0 = true; - if let syn2::ReturnType::Type(_, output) = i { + if let syn::ReturnType::Type(_, output) = i { if let Some((ok, err)) = unwrap_result_type(output) { let mut ok = ok.clone(); self.visit_type_mut(&mut ok); @@ -833,7 +833,7 @@ impl WrapperLifetimeResolver { } impl VisitMut for WrapperLifetimeResolver { - fn visit_type_reference_mut(&mut self, i: &mut syn2::TypeReference) { + fn visit_type_reference_mut(&mut self, i: &mut syn::TypeReference) { let lifetime = gen_lifetime_name_for_opaque(); if !self.0 || i.lifetime.is_some() { @@ -842,8 +842,8 @@ impl VisitMut for WrapperLifetimeResolver { i.lifetime = parse_quote! {#lifetime}; } - fn visit_return_type_mut(&mut self, i: &mut syn2::ReturnType) { + fn visit_return_type_mut(&mut self, i: &mut syn::ReturnType) { self.0 = true; - syn2::visit_mut::visit_return_type_mut(self, i); + syn::visit_mut::visit_return_type_mut(self, i); } } diff --git a/futures/derive/Cargo.toml b/futures/derive/Cargo.toml index cd0afdb1cb0..6ff76ece52e 100644 --- a/futures/derive/Cargo.toml +++ b/futures/derive/Cargo.toml @@ -21,7 +21,7 @@ proc-macro = true [dependencies] iroha_macro_utils = { workspace = true } -syn2 = { workspace = true, features = ["default", "full"] } +syn = { workspace = true, features = ["default", "full"] } quote = { workspace = true } proc-macro2 = { workspace = true } manyhow = { workspace = true } diff --git a/futures/derive/src/lib.rs b/futures/derive/src/lib.rs index 5212c38efe2..924f0ce1787 100644 --- a/futures/derive/src/lib.rs +++ b/futures/derive/src/lib.rs @@ -3,7 +3,7 @@ use iroha_macro_utils::Emitter; use manyhow::{emit, manyhow}; use proc_macro2::TokenStream; use quote::quote; -use syn2::{Generics, ItemFn, ReturnType, Signature}; +use syn::{Generics, ItemFn, ReturnType, Signature}; fn impl_telemetry_future( emitter: &mut Emitter, @@ -61,7 +61,7 @@ pub fn telemetry_future(args: TokenStream, input: TokenStream) -> TokenStream { emit!(emitter, args, "Unexpected arguments"); } - let Some(input) = emitter.handle(syn2::parse2(input)) else { + let Some(input) = emitter.handle(syn::parse2(input)) else { return emitter.finish_token_stream(); }; let result = if cfg!(feature = "telemetry") { diff --git a/macro/derive/Cargo.toml b/macro/derive/Cargo.toml index 5f09f48c489..dc9e23598d2 100644 --- a/macro/derive/Cargo.toml +++ b/macro/derive/Cargo.toml @@ -14,7 +14,7 @@ workspace = true proc-macro = true [dependencies] -syn2 = { workspace = true, features = ["default", "full"] } +syn = { workspace = true, features = ["default", "full"] } quote = { workspace = true } proc-macro2 = { workspace = true } manyhow = { workspace = true } diff --git a/macro/derive/src/lib.rs b/macro/derive/src/lib.rs index c8121d9a317..942d4faa316 100644 --- a/macro/derive/src/lib.rs +++ b/macro/derive/src/lib.rs @@ -4,7 +4,7 @@ use darling::{util::SpannedValue, FromDeriveInput}; use manyhow::{manyhow, Result}; use proc_macro2::{Span, TokenStream}; use quote::{quote, quote_spanned, ToTokens}; -use syn2::{spanned::Spanned, Token}; +use syn::{spanned::Spanned, Token}; /// Attribute for skipping from attribute const SKIP_FROM_ATTR: &str = "skip_from"; @@ -16,7 +16,7 @@ const SKIP_CONTAINER: &str = "skip_container"; #[manyhow] #[proc_macro_attribute] pub fn ffi_impl_opaque(_: TokenStream, item: TokenStream) -> Result { - let item: syn2::ItemImpl = syn2::parse2(item)?; + let item: syn::ItemImpl = syn::parse2(item)?; Ok(quote! { #[cfg_attr( @@ -31,15 +31,15 @@ pub fn ffi_impl_opaque(_: TokenStream, item: TokenStream) -> Result #[derive(darling::FromDeriveInput, Debug)] #[darling(supports(enum_any))] struct FromVariantInput { - ident: syn2::Ident, - generics: syn2::Generics, + ident: syn::Ident, + generics: syn::Generics, data: darling::ast::Data, darling::util::Ignored>, } // FromVariant manually implemented for additional validation #[derive(Debug)] struct FromVariantVariant { - ident: syn2::Ident, + ident: syn::Ident, fields: darling::ast::Fields>, } @@ -52,7 +52,7 @@ impl FromVariantVariant { } impl darling::FromVariant for FromVariantVariant { - fn from_variant(variant: &syn2::Variant) -> darling::Result { + fn from_variant(variant: &syn::Variant) -> darling::Result { let ident = variant.ident.clone(); let fields = darling::ast::Fields::try_from(&variant.fields)?; let mut accumulator = darling::error::Accumulator::default(); @@ -91,7 +91,7 @@ impl darling::FromVariant for FromVariantVariant { // FromField manually implemented for non-standard attributes #[derive(Debug)] struct FromVariantField { - ty: syn2::Type, + ty: syn::Type, skip_from: bool, skip_try_from: bool, skip_container: bool, @@ -104,7 +104,7 @@ struct FromVariantField { // Arguably, this is also more convenient for the user (?) // Hence, we fall back to manual parsing impl darling::FromField for FromVariantField { - fn from_field(field: &syn2::Field) -> darling::Result { + fn from_field(field: &syn::Field) -> darling::Result { let mut skip_from = false; let mut skip_try_from = false; let mut skip_container = false; @@ -158,21 +158,21 @@ impl darling::FromField for FromVariantField { #[manyhow] #[proc_macro_derive(FromVariant, attributes(skip_from, skip_try_from, skip_container))] pub fn from_variant_derive(input: TokenStream) -> Result { - let ast = syn2::parse2(input)?; + let ast = syn::parse2(input)?; let ast = FromVariantInput::from_derive_input(&ast)?; Ok(impl_from_variant(&ast)) } const CONTAINERS: &[&str] = &["Box", "RefCell", "Cell", "Rc", "Arc", "Mutex", "RwLock"]; -fn get_type_argument<'b>(s: &str, ty: &'b syn2::TypePath) -> Option<&'b syn2::GenericArgument> { - // NOTE: this is NOT syn2::Path::is_ident because it allows for generic parameters +fn get_type_argument<'b>(s: &str, ty: &'b syn::TypePath) -> Option<&'b syn::GenericArgument> { + // NOTE: this is NOT syn::Path::is_ident because it allows for generic parameters let segments = &ty.path.segments; if segments.len() != 1 || segments[0].ident != s { return None; } - if let syn2::PathArguments::AngleBracketed(ref bracketed_arguments) = segments[0].arguments { + if let syn::PathArguments::AngleBracketed(ref bracketed_arguments) = segments[0].arguments { assert_eq!(bracketed_arguments.args.len(), 1); Some(&bracketed_arguments.args[0]) } else { @@ -181,11 +181,11 @@ fn get_type_argument<'b>(s: &str, ty: &'b syn2::TypePath) -> Option<&'b syn2::Ge } fn from_container_variant_internal( - into_ty: &syn2::Ident, - into_variant: &syn2::Ident, - from_ty: &syn2::GenericArgument, - container_ty: &syn2::TypePath, - generics: &syn2::Generics, + into_ty: &syn::Ident, + into_variant: &syn::Ident, + from_ty: &syn::GenericArgument, + container_ty: &syn::TypePath, + generics: &syn::Generics, ) -> TokenStream { let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); @@ -200,10 +200,10 @@ fn from_container_variant_internal( fn from_variant_internal( span: Span, - into_ty: &syn2::Ident, - into_variant: &syn2::Ident, - from_ty: &syn2::Type, - generics: &syn2::Generics, + into_ty: &syn::Ident, + into_variant: &syn::Ident, + from_ty: &syn::Type, + generics: &syn::Generics, ) -> TokenStream { let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); @@ -218,15 +218,15 @@ fn from_variant_internal( fn from_variant( span: Span, - into_ty: &syn2::Ident, - into_variant: &syn2::Ident, - from_ty: &syn2::Type, - generics: &syn2::Generics, + into_ty: &syn::Ident, + into_variant: &syn::Ident, + from_ty: &syn::Type, + generics: &syn::Generics, skip_container: bool, ) -> TokenStream { let from_orig = from_variant_internal(span, into_ty, into_variant, from_ty, generics); - if let syn2::Type::Path(path) = from_ty { + if let syn::Type::Path(path) = from_ty { let mut code = from_orig; if skip_container { @@ -241,15 +241,15 @@ fn from_variant( .iter() .map(|segment| { let mut segment = segment.clone(); - segment.arguments = syn2::PathArguments::default(); + segment.arguments = syn::PathArguments::default(); segment }) - .collect::>(); - let path = syn2::Path { + .collect::>(); + let path = syn::Path { segments, leading_colon: None, }; - let path = &syn2::TypePath { path, qself: None }; + let path = &syn::TypePath { path, qself: None }; let from_inner = from_container_variant_internal(into_ty, into_variant, inner, path, generics); @@ -268,10 +268,10 @@ fn from_variant( fn try_into_variant_single( span: Span, - enum_ty: &syn2::Ident, - variant: &syn2::Ident, - variant_ty: &syn2::Type, - generics: &syn2::Generics, + enum_ty: &syn::Ident, + variant: &syn::Ident, + variant_ty: &syn::Type, + generics: &syn::Generics, ) -> TokenStream { let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); @@ -289,10 +289,10 @@ fn try_into_variant_single( fn try_into_variant( span: Span, - enum_ty: &syn2::Ident, - variant: &syn2::Ident, - variant_ty: &syn2::Type, - generics: &syn2::Generics, + enum_ty: &syn::Ident, + variant: &syn::Ident, + variant_ty: &syn::Type, + generics: &syn::Generics, ) -> TokenStream { let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); diff --git a/macro/utils/Cargo.toml b/macro/utils/Cargo.toml index 7167dafe639..2092e69889d 100644 --- a/macro/utils/Cargo.toml +++ b/macro/utils/Cargo.toml @@ -13,7 +13,7 @@ is-it-maintained-open-issues = { repository = "https://github.com/hyperledger/ir maintenance = { status = "actively-developed" } [dependencies] -syn2 = { workspace = true, features = ["default", "parsing", "printing"] } +syn = { workspace = true, features = ["default", "parsing", "printing"] } darling = { workspace = true } quote = { workspace = true } proc-macro2 = { workspace = true } diff --git a/macro/utils/src/lib.rs b/macro/utils/src/lib.rs index 77127e73c02..7a44ef5592f 100644 --- a/macro/utils/src/lib.rs +++ b/macro/utils/src/lib.rs @@ -46,8 +46,8 @@ impl DarlingErrorExt for darling::Error { pub fn find_single_attr_opt<'a>( accumulator: &mut darling::error::Accumulator, attr_name: &str, - attrs: &'a [syn2::Attribute], -) -> Option<&'a syn2::Attribute> { + attrs: &'a [syn::Attribute], +) -> Option<&'a syn::Attribute> { let matching_attrs = attrs .iter() .filter(|a| a.path().is_ident(attr_name)) @@ -61,7 +61,7 @@ pub fn find_single_attr_opt<'a>( // allow parsing to proceed further to collect more errors accumulator.push( darling::Error::custom(format!("Only one #[{}] attribute is allowed!", attr_name)) - .with_spans(tail.iter().map(syn2::spanned::Spanned::span)), + .with_spans(tail.iter().map(syn::spanned::Spanned::span)), ); attr } @@ -78,9 +78,9 @@ pub fn find_single_attr_opt<'a>( /// /// - If multiple attributes with specified name are found /// - If attribute is not a list -pub fn parse_single_list_attr_opt( +pub fn parse_single_list_attr_opt( attr_name: &str, - attrs: &[syn2::Attribute], + attrs: &[syn::Attribute], ) -> darling::Result> { let mut accumulator = darling::error::Accumulator::default(); @@ -91,11 +91,11 @@ pub fn parse_single_list_attr_opt( let mut kind = None; match &attr.meta { - syn2::Meta::Path(_) | syn2::Meta::NameValue(_) => accumulator.push(darling::Error::custom( + syn::Meta::Path(_) | syn::Meta::NameValue(_) => accumulator.push(darling::Error::custom( format!("Expected #[{}(...)] attribute to be a list", attr_name), )), - syn2::Meta::List(list) => { - kind = accumulator.handle(syn2::parse2(list.tokens.clone()).map_err(Into::into)); + syn::Meta::List(list) => { + kind = accumulator.handle(syn::parse2(list.tokens.clone()).map_err(Into::into)); } } @@ -111,9 +111,9 @@ pub fn parse_single_list_attr_opt( /// - If multiple attributes with specified name are found /// - If attribute is not a list /// - If attribute is not found -pub fn parse_single_list_attr( +pub fn parse_single_list_attr( attr_name: &str, - attrs: &[syn2::Attribute], + attrs: &[syn::Attribute], ) -> darling::Result { parse_single_list_attr_opt(attr_name, attrs)? .ok_or_else(|| darling::Error::custom(format!("Missing `#[{}(...)]` attribute", attr_name))) @@ -122,7 +122,7 @@ pub fn parse_single_list_attr( /// Macro for automatic [`syn::parse::Parse`] impl generation for keyword /// attribute structs in derive macros. #[macro_export] -macro_rules! attr_struct2 { +macro_rules! attr_struct { // Matching struct with named fields ( $( #[$meta:meta] )* @@ -144,8 +144,8 @@ macro_rules! attr_struct2 { ),* } - impl syn2::parse::Parse for $name { - fn parse(input: syn2::parse::ParseStream) -> syn2::Result { + impl syn::parse::Parse for $name { + fn parse(input: syn::parse::ParseStream) -> syn::Result { Ok(Self { $( $field_name: input.parse()?, diff --git a/primitives/derive/Cargo.toml b/primitives/derive/Cargo.toml index ac75b43b306..d6e018172a7 100644 --- a/primitives/derive/Cargo.toml +++ b/primitives/derive/Cargo.toml @@ -12,7 +12,7 @@ proc-macro = true [dependencies] quote = { workspace = true } -syn2 = { workspace = true } +syn = { workspace = true } manyhow = { workspace = true } proc-macro2 = { workspace = true } iroha_numeric = { path = "../numeric", default-features = false } diff --git a/primitives/derive/src/socket_addr.rs b/primitives/derive/src/socket_addr.rs index 4e387fae3ca..9a99a9332a6 100644 --- a/primitives/derive/src/socket_addr.rs +++ b/primitives/derive/src/socket_addr.rs @@ -3,7 +3,7 @@ use std::net; use manyhow::Result; use proc_macro2::{Delimiter, TokenStream, TokenTree}; use quote::quote; -use syn2::{bracketed, parse::ParseStream, Token}; +use syn::{bracketed, parse::ParseStream, Token}; /// Stringify [`TokenStream`], without inserting any spaces in between fn stringify_tokens(tokens: TokenStream) -> String { @@ -39,13 +39,13 @@ enum IpAddress { // so we parse them separately on the `syn` level IPv6 { #[allow(unused)] - bracket_token: syn2::token::Bracket, + bracket_token: syn::token::Bracket, ip_tokens: TokenStream, }, } impl IpAddress { - fn parse_v4(input: ParseStream) -> syn2::Result { + fn parse_v4(input: ParseStream) -> syn::Result { input.step(|cursor| { let mut rest = *cursor; @@ -67,7 +67,7 @@ impl IpAddress { }) } - fn parse_v6(input: ParseStream) -> syn2::Result { + fn parse_v6(input: ParseStream) -> syn::Result { let ip_tokens; Ok(IpAddress::IPv6 { bracket_token: bracketed!(ip_tokens in input), @@ -75,7 +75,7 @@ impl IpAddress { }) } - fn parse_tokens(&self) -> syn2::Result { + fn parse_tokens(&self) -> syn::Result { match self { IpAddress::IPv4 { ip_tokens } => { let ip_string = stringify_tokens(ip_tokens.clone()); @@ -83,7 +83,7 @@ impl IpAddress { .parse::() .map(net::IpAddr::V4) .map_err(|e| { - syn2::Error::new_spanned( + syn::Error::new_spanned( ip_tokens, format!("Failed to parse `{}` as an IPv4 address: {}", ip_string, e), ) @@ -95,7 +95,7 @@ impl IpAddress { .parse::() .map(net::IpAddr::V6) .map_err(|e| { - syn2::Error::new_spanned( + syn::Error::new_spanned( ip_tokens, format!("Failed to parse `{}` as an IPv6 address: {}", ip_string, e), ) @@ -105,11 +105,11 @@ impl IpAddress { } } -impl syn2::parse::Parse for IpAddress { - fn parse(input: ParseStream) -> syn2::Result { +impl syn::parse::Parse for IpAddress { + fn parse(input: ParseStream) -> syn::Result { let lookahead = input.lookahead1(); - if lookahead.peek(syn2::token::Bracket) { + if lookahead.peek(syn::token::Bracket) { Self::parse_v6(input) } else { Self::parse_v4(input) @@ -121,14 +121,14 @@ struct SocketAddress { ip: IpAddress, #[allow(unused)] colon: Token![:], - port: syn2::Expr, + port: syn::Expr, } -impl syn2::parse::Parse for SocketAddress { - fn parse(input: ParseStream) -> syn2::Result { +impl syn::parse::Parse for SocketAddress { + fn parse(input: ParseStream) -> syn::Result { let ip = input.parse::()?; let colon = input.parse::()?; - let port = input.parse::()?; + let port = input.parse::()?; Ok(SocketAddress { ip, colon, port }) } @@ -137,7 +137,7 @@ impl syn2::parse::Parse for SocketAddress { // it's fine, these are just segments of IPv6 addresses #[allow(clippy::many_single_char_names)] pub fn socket_addr_impl(input: TokenStream) -> Result { - let socket_address = syn2::parse2::(input)?; + let socket_address = syn::parse2::(input)?; let ip_address = socket_address.ip.parse_tokens()?; let port = socket_address.port; diff --git a/schema/derive/Cargo.toml b/schema/derive/Cargo.toml index d7d8e10527f..5dc64ef0aad 100644 --- a/schema/derive/Cargo.toml +++ b/schema/derive/Cargo.toml @@ -14,7 +14,7 @@ workspace = true proc-macro = true [dependencies] -syn2 = { workspace = true, features = ["default", "full"] } +syn = { workspace = true, features = ["default", "full"] } proc-macro2 = { workspace = true } quote = { workspace = true } manyhow = { workspace = true, features = ["darling"] } diff --git a/schema/derive/src/lib.rs b/schema/derive/src/lib.rs index 91a970c8ef4..e9e72a47cec 100644 --- a/schema/derive/src/lib.rs +++ b/schema/derive/src/lib.rs @@ -7,7 +7,7 @@ use darling::{ast::Style, FromAttributes, FromDeriveInput, FromField, FromMeta, use manyhow::{bail, emit, error_message, manyhow, Emitter, Result}; use proc_macro2::{Span, TokenStream}; use quote::{quote, ToTokens}; -use syn2::parse_quote; +use syn::parse_quote; /// Derive [`iroha_schema::TypeId`] /// @@ -15,17 +15,17 @@ use syn2::parse_quote; #[manyhow] #[proc_macro_derive(TypeId, attributes(type_id))] pub fn type_id_derive(input: TokenStream) -> Result { - let mut input = syn2::parse2(input)?; + let mut input = syn::parse2(input)?; Ok(impl_type_id(&mut input)) } -fn impl_type_id(input: &mut syn2::DeriveInput) -> TokenStream { +fn impl_type_id(input: &mut syn::DeriveInput) -> TokenStream { let name = &input.ident; input.generics.type_params_mut().for_each(|ty_param| { ty_param .bounds - .push(syn2::parse_quote! {iroha_schema::TypeId}); + .push(syn::parse_quote! {iroha_schema::TypeId}); }); let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); @@ -43,7 +43,7 @@ fn impl_type_id(input: &mut syn2::DeriveInput) -> TokenStream { #[derive(Debug, Clone)] enum Transparent { NotTransparent, - Transparent(Option), + Transparent(Option), } impl FromMeta for Transparent { @@ -56,7 +56,7 @@ impl FromMeta for Transparent { } fn from_string(value: &str) -> darling::Result { - let ty = syn2::parse_str(value)?; + let ty = syn::parse_str(value)?; Ok(Self::Transparent(Some(ty))) } } @@ -83,14 +83,14 @@ type IntoSchemaData = darling::ast::Data; #[derive(Debug, Clone)] struct IntoSchemaInput { - ident: syn2::Ident, - generics: syn2::Generics, + ident: syn::Ident, + generics: syn::Generics, data: IntoSchemaData, schema_attrs: SchemaAttributes, } impl FromDeriveInput for IntoSchemaInput { - fn from_derive_input(input: &syn2::DeriveInput) -> darling::Result { + fn from_derive_input(input: &syn::DeriveInput) -> darling::Result { let ident = input.ident.clone(); let generics = input.generics.clone(); let data = darling::ast::Data::try_from(&input.data)?; @@ -107,14 +107,14 @@ impl FromDeriveInput for IntoSchemaInput { #[derive(Debug, Clone)] struct IntoSchemaVariant { - ident: syn2::Ident, - discriminant: Option, + ident: syn::Ident, + discriminant: Option, fields: IntoSchemaFields, codec_attrs: CodecAttributes, } impl FromVariant for IntoSchemaVariant { - fn from_variant(variant: &syn2::Variant) -> darling::Result { + fn from_variant(variant: &syn::Variant) -> darling::Result { let ident = variant.ident.clone(); let discriminant = variant.discriminant.clone().map(|(_, expr)| expr); let fields = IntoSchemaFields::try_from(&variant.fields)?; @@ -133,13 +133,13 @@ type IntoSchemaFields = darling::ast::Fields; #[derive(Debug, Clone)] struct IntoSchemaField { - ident: Option, - ty: syn2::Type, + ident: Option, + ty: syn::Type, codec_attrs: CodecAttributes, } impl FromField for IntoSchemaField { - fn from_field(field: &syn2::Field) -> darling::Result { + fn from_field(field: &syn::Field) -> darling::Result { let ident = field.ident.clone(); let ty = field.ty.clone(); let codec_attrs = CodecAttributes::from_attributes(&field.attrs)?; @@ -154,8 +154,8 @@ impl FromField for IntoSchemaField { #[derive(Debug, Clone)] struct CodegenField { - ident: Option, - ty: syn2::Type, + ident: Option, + ty: syn::Type, } /// Derive [`iroha_schema::IntoSchema`] and [`iroha_schema::TypeId`] @@ -171,7 +171,7 @@ struct CodegenField { pub fn schema_derive(input: TokenStream) -> Result { let original_input = input.clone(); - let input: syn2::DeriveInput = syn2::parse2(input)?; + let input: syn::DeriveInput = syn::parse2(input)?; let mut input = IntoSchemaInput::from_derive_input(&input)?; input.generics.type_params_mut().for_each(|ty_param| { @@ -182,7 +182,7 @@ pub fn schema_derive(input: TokenStream) -> Result { let mut emitter = Emitter::new(); - let impl_type_id = impl_type_id(&mut syn2::parse2(original_input).unwrap()); + let impl_type_id = impl_type_id(&mut syn::parse2(original_input).unwrap()); let impl_schema = match &input.schema_attrs.transparent { Transparent::NotTransparent => impl_into_schema(&input, input.schema_attrs.bounds.as_ref()), @@ -215,13 +215,13 @@ pub fn schema_derive(input: TokenStream) -> Result { fn impl_transparent_into_schema( input: &IntoSchemaInput, - transparent_type: &syn2::Type, + transparent_type: &syn::Type, bounds: Option<&String>, ) -> Result { let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); let name = &input.ident; - let where_clause: Option = match bounds { - Some(bounds) => Some(syn2::parse_str(&format!("where {bounds}"))?), + let where_clause: Option = match bounds { + Some(bounds) => Some(syn::parse_str(&format!("where {bounds}"))?), None => where_clause.cloned(), }; @@ -251,8 +251,8 @@ fn impl_into_schema(input: &IntoSchemaInput, bounds: Option<&String>) -> Result< let type_name_body = trait_body(name, &input.generics, false); let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); let metadata = metadata(&input.data)?; - let where_clause: Option = match bounds { - Some(bounds) => Some(syn2::parse_str(&format!("where {bounds}"))?), + let where_clause: Option = match bounds { + Some(bounds) => Some(syn::parse_str(&format!("where {bounds}"))?), None => where_clause.cloned(), }; @@ -269,7 +269,7 @@ fn impl_into_schema(input: &IntoSchemaInput, bounds: Option<&String>) -> Result< }) } -fn infer_transparent_type(input: &IntoSchemaData, emitter: &mut Emitter) -> syn2::Type { +fn infer_transparent_type(input: &IntoSchemaData, emitter: &mut Emitter) -> syn::Type { const TRY_MESSAGE: &str = "try to specify it explicitly using #[schema(transparent = \"Type\")]"; @@ -354,20 +354,16 @@ fn infer_transparent_type(input: &IntoSchemaData, emitter: &mut Emitter) -> syn2 } /// Body of [`IntoSchema::type_name`] method -fn trait_body( - name: &syn2::Ident, - generics: &syn2::Generics, - is_type_id_trait: bool, -) -> TokenStream { +fn trait_body(name: &syn::Ident, generics: &syn::Generics, is_type_id_trait: bool) -> TokenStream { let generics = &generics .params .iter() .filter_map(|param| match param { - syn2::GenericParam::Type(ty) => Some(&ty.ident), + syn::GenericParam::Type(ty) => Some(&ty.ident), _ => None, }) .collect::>(); - let name = syn2::LitStr::new(&name.to_string(), Span::call_site()); + let name = syn::LitStr::new(&name.to_string(), Span::call_site()); if generics.is_empty() { return quote! { format!("{}", #name) }; @@ -382,7 +378,7 @@ fn trait_body( .join(", "), ); format_str.push('>'); - let format_str = syn2::LitStr::new(&format_str, Span::mixed_site()); + let format_str = syn::LitStr::new(&format_str, Span::mixed_site()); let generics = if is_type_id_trait { quote!(#(<#generics as iroha_schema::TypeId>::id()),*) @@ -416,7 +412,7 @@ fn metadata(data: &IntoSchemaData) -> Result { IntoSchemaData::Struct(IntoSchemaFields { style: Style::Unit, .. }) => { - let expr: syn2::Expr = parse_quote! { + let expr: syn::Expr = parse_quote! { iroha_schema::Metadata::Tuple( iroha_schema::UnnamedFieldsMeta { types: Vec::new() @@ -437,7 +433,7 @@ fn metadata(data: &IntoSchemaData) -> Result { } /// Returns types for which schema should be called and metadata for tuplestruct -fn metadata_for_tuplestructs(fields: &[IntoSchemaField]) -> (Vec, syn2::Expr) { +fn metadata_for_tuplestructs(fields: &[IntoSchemaField]) -> (Vec, syn::Expr) { let fields = fields.iter().filter_map(convert_field_to_codegen); let fields_ty = fields.clone().map(|field| field.ty).collect(); let types = fields @@ -458,7 +454,7 @@ fn metadata_for_tuplestructs(fields: &[IntoSchemaField]) -> (Vec, sy } /// Returns types for which schema should be called and metadata for struct -fn metadata_for_structs(fields: &[IntoSchemaField]) -> (Vec, syn2::Expr) { +fn metadata_for_structs(fields: &[IntoSchemaField]) -> (Vec, syn::Expr) { let fields = fields.iter().filter_map(convert_field_to_codegen); let declarations = fields.clone().map(|field| field_to_declaration(&field)); let fields_ty = fields.map(|field| field.ty).collect(); @@ -477,7 +473,7 @@ fn metadata_for_structs(fields: &[IntoSchemaField]) -> (Vec, syn2::E } /// Takes variant fields and gets its type -fn variant_field(fields: &IntoSchemaFields) -> Result> { +fn variant_field(fields: &IntoSchemaFields) -> Result> { let field = match fields.style { Style::Unit => return Ok(None), Style::Tuple if fields.len() == 1 => fields.iter().next().unwrap(), @@ -492,7 +488,7 @@ fn variant_field(fields: &IntoSchemaFields) -> Result> { } /// Returns types for which schema should be called and metadata for struct -fn metadata_for_enums(variants: &[IntoSchemaVariant]) -> Result<(Vec, syn2::Expr)> { +fn metadata_for_enums(variants: &[IntoSchemaVariant]) -> Result<(Vec, syn::Expr)> { let variant_exprs: Vec<_> = variants .iter() .enumerate() diff --git a/smart_contract/derive/Cargo.toml b/smart_contract/derive/Cargo.toml index 8ecc878acec..d6be1860ead 100644 --- a/smart_contract/derive/Cargo.toml +++ b/smart_contract/derive/Cargo.toml @@ -16,7 +16,7 @@ proc-macro = true [dependencies] iroha_macro_utils = { workspace = true } -syn2 = { workspace = true } +syn = { workspace = true } manyhow = { workspace = true } quote = { workspace = true } proc-macro2 = { workspace = true } diff --git a/smart_contract/derive/src/entrypoint.rs b/smart_contract/derive/src/entrypoint.rs index 426c2ab091f..081651fc878 100644 --- a/smart_contract/derive/src/entrypoint.rs +++ b/smart_contract/derive/src/entrypoint.rs @@ -6,22 +6,22 @@ use iroha_macro_utils::Emitter; use manyhow::emit; use proc_macro2::TokenStream; use quote::quote; -use syn2::parse_quote; +use syn::parse_quote; mod export { pub const SMART_CONTRACT_MAIN: &str = "_iroha_smart_contract_main"; } #[allow(clippy::needless_pass_by_value)] -pub fn impl_entrypoint(emitter: &mut Emitter, item: syn2::ItemFn) -> TokenStream { - let syn2::ItemFn { +pub fn impl_entrypoint(emitter: &mut Emitter, item: syn::ItemFn) -> TokenStream { + let syn::ItemFn { attrs, vis, sig, mut block, } = item; - if sig.output != syn2::ReturnType::Default { + if sig.output != syn::ReturnType::Default { emit!( emitter, "Smart contract entrypoint must not have a return type" @@ -39,8 +39,7 @@ pub fn impl_entrypoint(emitter: &mut Emitter, item: syn2::ItemFn) -> TokenStream ), ); - let main_fn_name = - syn2::Ident::new(export::SMART_CONTRACT_MAIN, proc_macro2::Span::call_site()); + let main_fn_name = syn::Ident::new(export::SMART_CONTRACT_MAIN, proc_macro2::Span::call_site()); quote! { /// Smart contract entrypoint diff --git a/smart_contract/derive/src/lib.rs b/smart_contract/derive/src/lib.rs index da3faa41190..ca6b1789cd5 100644 --- a/smart_contract/derive/src/lib.rs +++ b/smart_contract/derive/src/lib.rs @@ -37,7 +37,7 @@ pub fn main(attr: TokenStream, item: TokenStream) -> TokenStream { ); } - let Some(item) = emitter.handle(syn2::parse2(item)) else { + let Some(item) = emitter.handle(syn::parse2(item)) else { return emitter.finish_token_stream(); }; diff --git a/smart_contract/executor/derive/Cargo.toml b/smart_contract/executor/derive/Cargo.toml index 43e093218fd..4a9a9c66fd1 100644 --- a/smart_contract/executor/derive/Cargo.toml +++ b/smart_contract/executor/derive/Cargo.toml @@ -17,7 +17,7 @@ proc-macro = true [dependencies] iroha_macro_utils = { workspace = true } -syn2 = { workspace = true, features = ["full", "derive"] } +syn = { workspace = true, features = ["full", "derive"] } quote = { workspace = true } proc-macro2 = { workspace = true } manyhow = { workspace = true } diff --git a/smart_contract/executor/derive/src/conversion.rs b/smart_contract/executor/derive/src/conversion.rs index 009ace5a426..4ea3e505f2b 100644 --- a/smart_contract/executor/derive/src/conversion.rs +++ b/smart_contract/executor/derive/src/conversion.rs @@ -2,15 +2,15 @@ use proc_macro2::TokenStream; use quote::quote; -use syn2::DeriveInput; +use syn::DeriveInput; /// [`derive_ref_into_asset_owner`](crate::derive_ref_into_asset_owner) macro implementation pub fn impl_derive_ref_into_asset_owner(input: &DeriveInput) -> TokenStream { impl_from( &input.ident, &input.generics, - &syn2::parse_quote!(::iroha_executor::permission::asset::Owner), - &syn2::parse_quote!(asset_id), + &syn::parse_quote!(::iroha_executor::permission::asset::Owner), + &syn::parse_quote!(asset_id), ) } @@ -20,8 +20,8 @@ pub fn impl_derive_ref_into_asset_definition_owner(input: &DeriveInput) -> Token impl_from( &input.ident, &input.generics, - &syn2::parse_quote!(::iroha_executor::permission::asset_definition::Owner), - &syn2::parse_quote!(asset_definition_id), + &syn::parse_quote!(::iroha_executor::permission::asset_definition::Owner), + &syn::parse_quote!(asset_definition_id), ) } @@ -30,8 +30,8 @@ pub fn impl_derive_ref_into_account_owner(input: &DeriveInput) -> TokenStream { impl_from( &input.ident, &input.generics, - &syn2::parse_quote!(::iroha_executor::permission::account::Owner), - &syn2::parse_quote!(account_id), + &syn::parse_quote!(::iroha_executor::permission::account::Owner), + &syn::parse_quote!(account_id), ) } @@ -40,27 +40,27 @@ pub fn impl_derive_ref_into_domain_owner(input: &DeriveInput) -> TokenStream { impl_from( &input.ident, &input.generics, - &syn2::parse_quote!(::iroha_executor::permission::domain::Owner), - &syn2::parse_quote!(domain_id), + &syn::parse_quote!(::iroha_executor::permission::domain::Owner), + &syn::parse_quote!(domain_id), ) } fn impl_from( - ident: &syn2::Ident, - generics: &syn2::Generics, - pass_condition_type: &syn2::Type, - field: &syn2::Ident, + ident: &syn::Ident, + generics: &syn::Generics, + pass_condition_type: &syn::Type, + field: &syn::Ident, ) -> TokenStream { use quote::ToTokens; let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); - let mut generics: TokenStream = syn2::parse_str("<'token, ").unwrap(); + let mut generics: TokenStream = syn::parse_str("<'token, ").unwrap(); let impl_generics_tokens = impl_generics.into_token_stream(); if impl_generics_tokens.is_empty() { generics.extend(core::iter::once(proc_macro2::TokenTree::Punct( - syn2::parse_str(">").unwrap(), + syn::parse_str(">").unwrap(), ))); } else { generics.extend(impl_generics_tokens.into_iter().skip(1)); diff --git a/smart_contract/executor/derive/src/default.rs b/smart_contract/executor/derive/src/default.rs index 37d62cd25c0..4e46084bde5 100644 --- a/smart_contract/executor/derive/src/default.rs +++ b/smart_contract/executor/derive/src/default.rs @@ -3,9 +3,9 @@ use iroha_macro_utils::Emitter; use manyhow::emit; use proc_macro2::{Span, TokenStream as TokenStream2}; use quote::{quote, ToTokens}; -use syn2::{parse_quote, Ident}; +use syn::{parse_quote, Ident}; -type ExecutorData = darling::ast::Data; +type ExecutorData = darling::ast::Data; #[derive(Debug)] struct Custom(Vec); @@ -14,7 +14,7 @@ impl FromMeta for Custom { fn from_list(items: &[NestedMeta]) -> darling::Result { let mut res = Vec::new(); for item in items { - if let NestedMeta::Meta(syn2::Meta::Path(p)) = item { + if let NestedMeta::Meta(syn::Meta::Path(p)) = item { let fn_name = p.get_ident().expect("Path should be ident"); res.push(fn_name.clone()); } else { @@ -35,7 +35,7 @@ struct ExecutorDeriveInput { custom: Option, } -pub fn impl_derive_entrypoints(emitter: &mut Emitter, input: &syn2::DeriveInput) -> TokenStream2 { +pub fn impl_derive_entrypoints(emitter: &mut Emitter, input: &syn::DeriveInput) -> TokenStream2 { let Some(input) = emitter.handle(ExecutorDeriveInput::from_derive_input(input)) else { return quote!(); }; @@ -49,7 +49,7 @@ pub fn impl_derive_entrypoints(emitter: &mut Emitter, input: &syn2::DeriveInput) let (custom_idents, custom_args) = custom_field_idents_and_fn_args(data); - let mut entrypoint_fns: Vec = vec![ + let mut entrypoint_fns: Vec = vec![ parse_quote! { #[::iroha_executor::prelude::entrypoint] pub fn validate_instruction( @@ -108,12 +108,12 @@ pub fn impl_derive_entrypoints(emitter: &mut Emitter, input: &syn2::DeriveInput) } #[allow(clippy::too_many_lines)] -pub fn impl_derive_visit(emitter: &mut Emitter, input: &syn2::DeriveInput) -> TokenStream2 { +pub fn impl_derive_visit(emitter: &mut Emitter, input: &syn::DeriveInput) -> TokenStream2 { let Some(input) = emitter.handle(ExecutorDeriveInput::from_derive_input(input)) else { return quote!(); }; let ExecutorDeriveInput { ident, custom, .. } = &input; - let default_visit_sigs: Vec = [ + let default_visit_sigs: Vec = [ "fn visit_transaction(operation: &SignedTransaction)", "fn visit_instruction(operation: &InstructionBox)", "fn visit_register_peer(operation: &Register)", @@ -164,10 +164,10 @@ pub fn impl_derive_visit(emitter: &mut Emitter, input: &syn2::DeriveInput) -> To ] .into_iter() .map(|item| { - let mut sig: syn2::Signature = - syn2::parse_str(item).expect("Function names and operation signatures should be valid"); - let recv_arg: syn2::Receiver = parse_quote!(&mut self); - let auth_arg: syn2::FnArg = parse_quote!(authority: &AccountId); + let mut sig: syn::Signature = + syn::parse_str(item).expect("Function names and operation signatures should be valid"); + let recv_arg: syn::Receiver = parse_quote!(&mut self); + let auth_arg: syn::FnArg = parse_quote!(authority: &AccountId); sig.inputs.insert(0, recv_arg.into()); sig.inputs.insert(1, auth_arg); sig @@ -211,7 +211,7 @@ pub fn impl_derive_visit(emitter: &mut Emitter, input: &syn2::DeriveInput) -> To } } -pub fn impl_derive_validate(emitter: &mut Emitter, input: &syn2::DeriveInput) -> TokenStream2 { +pub fn impl_derive_validate(emitter: &mut Emitter, input: &syn::DeriveInput) -> TokenStream2 { let Some(input) = emitter.handle(ExecutorDeriveInput::from_derive_input(input)) else { return quote!(); }; @@ -234,7 +234,7 @@ pub fn impl_derive_validate(emitter: &mut Emitter, input: &syn2::DeriveInput) -> } } -pub fn impl_derive_constructor(emitter: &mut Emitter, input: &syn2::DeriveInput) -> TokenStream2 { +pub fn impl_derive_constructor(emitter: &mut Emitter, input: &syn::DeriveInput) -> TokenStream2 { let Some(input) = emitter.handle(ExecutorDeriveInput::from_derive_input(input)) else { return quote!(); }; @@ -260,7 +260,7 @@ pub fn impl_derive_constructor(emitter: &mut Emitter, input: &syn2::DeriveInput) } fn check_required_fields(ast: &ExecutorData, emitter: &mut Emitter) { - let required_fields: syn2::FieldsNamed = + let required_fields: syn::FieldsNamed = parse_quote!({ verdict: ::iroha_executor::prelude::Result, block_height: u64 }); let struct_fields = ast .as_ref() @@ -289,9 +289,9 @@ fn check_required_fields(ast: &ExecutorData, emitter: &mut Emitter) { /// Check that the required fields of an `Executor` are of the correct types. As /// the types can be completely or partially unqualified, we need to go through the type path segments to /// determine equivalence. We can't account for any aliases though -fn check_type_equivalence(full_ty: &syn2::Type, given_ty: &syn2::Type) -> bool { +fn check_type_equivalence(full_ty: &syn::Type, given_ty: &syn::Type) -> bool { match (full_ty, given_ty) { - (syn2::Type::Path(full_ty_path), syn2::Type::Path(given_ty_path)) => { + (syn::Type::Path(full_ty_path), syn::Type::Path(given_ty_path)) => { if full_ty_path.path.segments.len() == given_ty_path.path.segments.len() { full_ty_path == given_ty_path } else { @@ -310,7 +310,7 @@ fn check_type_equivalence(full_ty: &syn2::Type, given_ty: &syn2::Type) -> bool { /// Processes an `Executor` by draining it of default fields and returning the idents of the /// custom fields and the corresponding function arguments for use in the constructor -fn custom_field_idents_and_fn_args(ast: &ExecutorData) -> (Vec<&Ident>, Vec) { +fn custom_field_idents_and_fn_args(ast: &ExecutorData) -> (Vec<&Ident>, Vec) { let required_idents: Vec = ["verdict", "block_height"] .iter() .map(|s| Ident::new(s, Span::call_site())) @@ -341,7 +341,7 @@ fn custom_field_idents_and_fn_args(ast: &ExecutorData) -> (Vec<&Ident>, Vec>(); diff --git a/smart_contract/executor/derive/src/entrypoint.rs b/smart_contract/executor/derive/src/entrypoint.rs index 01c69e99c03..222a37639b1 100644 --- a/smart_contract/executor/derive/src/entrypoint.rs +++ b/smart_contract/executor/derive/src/entrypoint.rs @@ -4,7 +4,7 @@ use iroha_macro_utils::Emitter; use manyhow::emit; use proc_macro2::TokenStream; use quote::quote; -use syn2::parse_quote; +use syn::parse_quote; mod export { pub const EXECUTOR_VALIDATE_TRANSACTION: &str = "_iroha_executor_validate_transaction"; @@ -21,7 +21,7 @@ mod import { /// [`executor_entrypoint`](crate::executor_entrypoint()) macro implementation #[allow(clippy::needless_pass_by_value)] -pub fn impl_entrypoint(emitter: &mut Emitter, item: syn2::ItemFn) -> TokenStream { +pub fn impl_entrypoint(emitter: &mut Emitter, item: syn::ItemFn) -> TokenStream { macro_rules! match_entrypoints { (validate: { $($user_entrypoint_name:ident => @@ -68,12 +68,12 @@ pub fn impl_entrypoint(emitter: &mut Emitter, item: syn2::ItemFn) -> TokenStream } fn impl_validate_entrypoint( - fn_item: syn2::ItemFn, + fn_item: syn::ItemFn, user_entrypoint_name: &'static str, generated_entrypoint_name: &'static str, get_validation_payload_fn_name: &'static str, ) -> TokenStream { - let syn2::ItemFn { + let syn::ItemFn { attrs, vis, sig, @@ -82,7 +82,7 @@ fn impl_validate_entrypoint( let fn_name = &sig.ident; assert!( - matches!(sig.output, syn2::ReturnType::Type(_, _)), + matches!(sig.output, syn::ReturnType::Type(_, _)), "Executor `{user_entrypoint_name}` entrypoint must have `Result` return type" ); @@ -93,11 +93,11 @@ fn impl_validate_entrypoint( ), ); - let generated_entrypoint_ident: syn2::Ident = syn2::parse_str(generated_entrypoint_name) + let generated_entrypoint_ident: syn::Ident = syn::parse_str(generated_entrypoint_name) .expect("Provided entrypoint name to generate is not a valid Ident, this is a bug"); - let get_validation_payload_fn_ident: syn2::Ident = - syn2::parse_str(get_validation_payload_fn_name).expect( + let get_validation_payload_fn_ident: syn::Ident = + syn::parse_str(get_validation_payload_fn_name).expect( "Provided function name to query validating object is not a valid Ident, this is a bug", ); @@ -128,8 +128,8 @@ fn impl_validate_entrypoint( } } -fn impl_migrate_entrypoint(fn_item: syn2::ItemFn) -> TokenStream { - let syn2::ItemFn { +fn impl_migrate_entrypoint(fn_item: syn::ItemFn) -> TokenStream { + let syn::ItemFn { attrs, vis, sig, @@ -138,12 +138,11 @@ fn impl_migrate_entrypoint(fn_item: syn2::ItemFn) -> TokenStream { let fn_name = &sig.ident; assert!( - matches!(sig.output, syn2::ReturnType::Type(_, _)), + matches!(sig.output, syn::ReturnType::Type(_, _)), "Executor `migrate()` entrypoint must have `MigrationResult` return type" ); - let migrate_fn_name = - syn2::Ident::new(export::EXECUTOR_MIGRATE, proc_macro2::Span::call_site()); + let migrate_fn_name = syn::Ident::new(export::EXECUTOR_MIGRATE, proc_macro2::Span::call_site()); quote! { /// Executor `permission_token_schema` entrypoint diff --git a/smart_contract/executor/derive/src/lib.rs b/smart_contract/executor/derive/src/lib.rs index c9bc81dc6d8..59beda04b12 100644 --- a/smart_contract/executor/derive/src/lib.rs +++ b/smart_contract/executor/derive/src/lib.rs @@ -55,7 +55,7 @@ pub fn entrypoint(attr: TokenStream, item: TokenStream) -> TokenStream { ); } - let Some(item) = emitter.handle(syn2::parse2(item)) else { + let Some(item) = emitter.handle(syn::parse2(item)) else { return emitter.finish_token_stream(); }; @@ -95,7 +95,7 @@ pub fn entrypoint(attr: TokenStream, item: TokenStream) -> TokenStream { #[manyhow] #[proc_macro_derive(Token)] pub fn derive_token(input: TokenStream) -> Result { - let input = syn2::parse2(input)?; + let input = syn::parse2(input)?; Ok(token::impl_derive_token(&input)) } @@ -167,7 +167,7 @@ pub fn derive_token(input: TokenStream) -> Result { attributes(validate, validate_grant, validate_revoke) )] pub fn derive_validate_grant_revoke(input: TokenStream) -> Result { - let input = syn2::parse2(input)?; + let input = syn::parse2(input)?; validate::impl_derive_validate_grant_revoke(&input) } @@ -181,7 +181,7 @@ pub fn derive_validate_grant_revoke(input: TokenStream) -> Result { #[manyhow] #[proc_macro_derive(RefIntoAssetDefinitionOwner)] pub fn derive_ref_into_asset_definition_owner(input: TokenStream) -> Result { - let input = syn2::parse2(input)?; + let input = syn::parse2(input)?; Ok(conversion::impl_derive_ref_into_asset_definition_owner( &input, @@ -198,7 +198,7 @@ pub fn derive_ref_into_asset_definition_owner(input: TokenStream) -> Result Result { - let input = syn2::parse2(input)?; + let input = syn::parse2(input)?; Ok(conversion::impl_derive_ref_into_asset_owner(&input)) } @@ -213,7 +213,7 @@ pub fn derive_ref_into_asset_owner(input: TokenStream) -> Result { #[manyhow] #[proc_macro_derive(RefIntoAccountOwner)] pub fn derive_ref_into_account_owner(input: TokenStream) -> Result { - let input = syn2::parse2(input)?; + let input = syn::parse2(input)?; Ok(conversion::impl_derive_ref_into_account_owner(&input)) } @@ -228,7 +228,7 @@ pub fn derive_ref_into_account_owner(input: TokenStream) -> Result #[manyhow] #[proc_macro_derive(RefIntoDomainOwner)] pub fn derive_ref_into_domain_owner(input: TokenStream) -> Result { - let input = syn2::parse2(input)?; + let input = syn::parse2(input)?; Ok(conversion::impl_derive_ref_into_domain_owner(&input)) } @@ -245,7 +245,7 @@ pub fn derive_ref_into_domain_owner(input: TokenStream) -> Result { pub fn derive_validate(input: TokenStream) -> TokenStream { let mut emitter = Emitter::new(); - let Some(input) = emitter.handle(syn2::parse2(input)) else { + let Some(input) = emitter.handle(syn::parse2(input)) else { return emitter.finish_token_stream(); }; @@ -290,7 +290,7 @@ pub fn derive_validate(input: TokenStream) -> TokenStream { pub fn derive_visit(input: TokenStream) -> TokenStream { let mut emitter = Emitter::new(); - let Some(input) = emitter.handle(syn2::parse2(input)) else { + let Some(input) = emitter.handle(syn::parse2(input)) else { return emitter.finish_token_stream(); }; @@ -331,7 +331,7 @@ pub fn derive_visit(input: TokenStream) -> TokenStream { pub fn derive_entrypoints(input: TokenStream) -> TokenStream { let mut emitter = Emitter::new(); - let Some(input) = emitter.handle(syn2::parse2(input)) else { + let Some(input) = emitter.handle(syn::parse2(input)) else { return emitter.finish_token_stream(); }; @@ -353,7 +353,7 @@ pub fn derive_entrypoints(input: TokenStream) -> TokenStream { pub fn derive_constructor(input: TokenStream) -> TokenStream { let mut emitter = Emitter::new(); - let Some(input) = emitter.handle(syn2::parse2(input)) else { + let Some(input) = emitter.handle(syn::parse2(input)) else { return emitter.finish_token_stream(); }; diff --git a/smart_contract/executor/derive/src/token.rs b/smart_contract/executor/derive/src/token.rs index e9c2b03f271..91e3839826b 100644 --- a/smart_contract/executor/derive/src/token.rs +++ b/smart_contract/executor/derive/src/token.rs @@ -4,7 +4,7 @@ use proc_macro2::TokenStream; use quote::quote; /// [`derive_token`](crate::derive_token()) macro implementation -pub fn impl_derive_token(input: &syn2::DeriveInput) -> TokenStream { +pub fn impl_derive_token(input: &syn::DeriveInput) -> TokenStream { let generics = &input.generics; let ident = &input.ident; @@ -17,7 +17,7 @@ pub fn impl_derive_token(input: &syn2::DeriveInput) -> TokenStream { } } -fn impl_token(ident: &syn2::Ident, generics: &syn2::Generics) -> proc_macro2::TokenStream { +fn impl_token(ident: &syn::Ident, generics: &syn::Generics) -> proc_macro2::TokenStream { let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); quote! { @@ -45,7 +45,7 @@ fn impl_token(ident: &syn2::Ident, generics: &syn2::Generics) -> proc_macro2::To } } -fn impl_try_from_permission_token(ident: &syn2::Ident, generics: &syn2::Generics) -> TokenStream { +fn impl_try_from_permission_token(ident: &syn::Ident, generics: &syn::Generics) -> TokenStream { let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); let token_id = quote! { <#ident #ty_generics as ::iroha_executor::permission::Token>::name() }; diff --git a/smart_contract/executor/derive/src/validate.rs b/smart_contract/executor/derive/src/validate.rs index 35e43dd8fcb..130ee7cd4fa 100644 --- a/smart_contract/executor/derive/src/validate.rs +++ b/smart_contract/executor/derive/src/validate.rs @@ -4,10 +4,10 @@ use darling::FromAttributes; use manyhow::Result; use proc_macro2::{Span, TokenStream}; use quote::quote; -use syn2::{Attribute, Ident, Type}; +use syn::{Attribute, Ident, Type}; /// [`derive_validate`](crate::derive_validate()) macro implementation -pub fn impl_derive_validate_grant_revoke(input: &syn2::DeriveInput) -> Result { +pub fn impl_derive_validate_grant_revoke(input: &syn::DeriveInput) -> Result { let ident = &input.ident; let (validate_grant_impl, validate_revoke_impl) = gen_validate_impls(&input.attrs)?; @@ -80,7 +80,7 @@ impl FromAttributes for ValidateAttribute { general_condition = general_condition .or(accumulator - .handle(syn2::parse2(tokens.clone()).map_err(darling::Error::from))); + .handle(syn::parse2(tokens.clone()).map_err(darling::Error::from))); } else if path.is_ident("grant") { if general_condition.is_some() { accumulator.push( @@ -101,7 +101,7 @@ impl FromAttributes for ValidateAttribute { grant_condition = grant_condition .or(accumulator - .handle(syn2::parse2(tokens.clone()).map_err(darling::Error::from))); + .handle(syn::parse2(tokens.clone()).map_err(darling::Error::from))); } else if path.is_ident("revoke") { if general_condition.is_some() { accumulator.push( @@ -122,7 +122,7 @@ impl FromAttributes for ValidateAttribute { revoke_condition = revoke_condition .or(accumulator - .handle(syn2::parse2(tokens.clone()).map_err(darling::Error::from))); + .handle(syn::parse2(tokens.clone()).map_err(darling::Error::from))); } else { unreachable!() } diff --git a/smart_contract/trigger/derive/Cargo.toml b/smart_contract/trigger/derive/Cargo.toml index b2c4d84a6b4..19a02bc9cc0 100644 --- a/smart_contract/trigger/derive/Cargo.toml +++ b/smart_contract/trigger/derive/Cargo.toml @@ -17,7 +17,7 @@ proc-macro = true [dependencies] iroha_macro_utils = { workspace = true } -syn2 = { workspace = true } +syn = { workspace = true } manyhow = { workspace = true } quote = { workspace = true } proc-macro2 = { workspace = true } diff --git a/smart_contract/trigger/derive/src/entrypoint.rs b/smart_contract/trigger/derive/src/entrypoint.rs index 57a5b467e93..a054363cdfe 100644 --- a/smart_contract/trigger/derive/src/entrypoint.rs +++ b/smart_contract/trigger/derive/src/entrypoint.rs @@ -4,7 +4,7 @@ use iroha_macro_utils::Emitter; use manyhow::emit; use proc_macro2::TokenStream; use quote::quote; -use syn2::parse_quote; +use syn::parse_quote; mod export { pub const TRIGGER_MAIN: &str = "_iroha_trigger_main"; @@ -12,15 +12,15 @@ mod export { /// [`main`](super::main()) macro implementation #[allow(clippy::needless_pass_by_value)] -pub fn impl_entrypoint(emitter: &mut Emitter, item: syn2::ItemFn) -> TokenStream { - let syn2::ItemFn { +pub fn impl_entrypoint(emitter: &mut Emitter, item: syn::ItemFn) -> TokenStream { + let syn::ItemFn { attrs, vis, sig, mut block, } = item; - if sig.output != syn2::ReturnType::Default { + if sig.output != syn::ReturnType::Default { emit!( emitter, sig.output, @@ -39,7 +39,7 @@ pub fn impl_entrypoint(emitter: &mut Emitter, item: syn2::ItemFn) -> TokenStream ), ); - let main_fn_name = syn2::Ident::new(export::TRIGGER_MAIN, proc_macro2::Span::call_site()); + let main_fn_name = syn::Ident::new(export::TRIGGER_MAIN, proc_macro2::Span::call_site()); quote! { /// Smart contract entrypoint diff --git a/smart_contract/trigger/derive/src/lib.rs b/smart_contract/trigger/derive/src/lib.rs index 01701a708e9..8e05e163f87 100644 --- a/smart_contract/trigger/derive/src/lib.rs +++ b/smart_contract/trigger/derive/src/lib.rs @@ -31,7 +31,7 @@ pub fn main(attr: TokenStream, item: TokenStream) -> TokenStream { emit!(emitter, "#[main] attribute does not accept arguments"); } - let Some(item) = emitter.handle(syn2::parse2(item)) else { + let Some(item) = emitter.handle(syn::parse2(item)) else { return emitter.finish_token_stream(); }; diff --git a/telemetry/derive/Cargo.toml b/telemetry/derive/Cargo.toml index de03e2bb488..3a4f7e9fe21 100644 --- a/telemetry/derive/Cargo.toml +++ b/telemetry/derive/Cargo.toml @@ -19,7 +19,7 @@ is-it-maintained-open-issues = { repository = "https://github.com/hyperledger/ir maintenance = { status = "actively-developed" } [dependencies] -syn2 = { workspace = true } +syn = { workspace = true } quote = { workspace = true } proc-macro2 = { workspace = true } manyhow = { workspace = true } diff --git a/telemetry/derive/src/lib.rs b/telemetry/derive/src/lib.rs index c0420a4a868..48fbef3e848 100644 --- a/telemetry/derive/src/lib.rs +++ b/telemetry/derive/src/lib.rs @@ -5,7 +5,7 @@ use iroha_macro_utils::Emitter; use manyhow::{emit, manyhow, Result}; use proc_macro2::TokenStream; use quote::{quote, ToTokens}; -use syn2::{parse::Parse, punctuated::Punctuated, token::Comma, FnArg, LitStr, Path, Type}; +use syn::{parse::Parse, punctuated::Punctuated, token::Comma, FnArg, LitStr, Path, Type}; // TODO: export these as soon as proc-macro crates are able to export // anything other than proc-macros. @@ -39,19 +39,19 @@ fn type_has_metrics_field(ty: &Type) -> bool { /// /// # Errors /// If no argument is of type `WorldStateView`. -fn arg_metrics(input: &Punctuated) -> Result> { +fn arg_metrics(input: &Punctuated) -> Result> { input .iter() .find(|arg| match arg { FnArg::Typed(typ) => match &*typ.ty { - syn2::Type::Reference(typ) => type_has_metrics_field(&typ.elem), + syn::Type::Reference(typ) => type_has_metrics_field(&typ.elem), _ => false, }, _ => false, }) .and_then(|arg| match arg { FnArg::Typed(typ) => match *typ.pat.clone() { - syn2::Pat::Ident(ident) => Some(ident.ident), + syn::Pat::Ident(ident) => Some(ident.ident), _ => None, }, _ => None, @@ -62,7 +62,7 @@ fn arg_metrics(input: &Punctuated) -> Result); // `HashSet` — idiomatic; slow impl Parse for MetricSpecs { - fn parse(input: syn2::parse::ParseStream) -> syn2::Result { + fn parse(input: syn::parse::ParseStream) -> syn::Result { let vars = Punctuated::::parse_terminated(input)?; Ok(Self(vars.into_iter().collect())) } @@ -75,14 +75,14 @@ struct MetricSpec { } impl Parse for MetricSpec { - fn parse(input: syn2::parse::ParseStream) -> syn2::Result { - let _timing = ::parse(input).is_ok(); - let metric_name_lit = syn2::Lit::parse(input)?; + fn parse(input: syn::parse::ParseStream) -> syn::Result { + let _timing = ::parse(input).is_ok(); + let metric_name_lit = syn::Lit::parse(input)?; let metric_name = match metric_name_lit { - syn2::Lit::Str(lit_str) => { + syn::Lit::Str(lit_str) => { if lit_str.value().contains(' ') { - return Err(syn2::Error::new( + return Err(syn::Error::new( proc_macro2::Span::call_site(), "Spaces are not allowed. Use underscores '_'", )); @@ -90,7 +90,7 @@ impl Parse for MetricSpec { lit_str } _ => { - return Err(syn2::Error::new( + return Err(syn::Error::new( proc_macro2::Span::call_site(), "Must be a string literal. Format `[+]\"name_of_metric\"`.", )) @@ -145,7 +145,7 @@ impl ToTokens for MetricSpec { pub fn metrics(attr: TokenStream, item: TokenStream) -> TokenStream { let mut emitter = Emitter::new(); - let Some(func): Option = emitter.handle(syn2::parse2(item)) else { + let Some(func): Option = emitter.handle(syn::parse2(item)) else { return emitter.finish_token_stream(); }; @@ -167,7 +167,7 @@ pub fn metrics(attr: TokenStream, item: TokenStream) -> TokenStream { return emitter.finish_token_stream(); } - let Some(metric_specs): Option = emitter.handle(syn2::parse2(attr)) else { + let Some(metric_specs): Option = emitter.handle(syn::parse2(attr)) else { return emitter.finish_token_stream(); }; @@ -176,8 +176,8 @@ pub fn metrics(attr: TokenStream, item: TokenStream) -> TokenStream { emitter.finish_token_stream_with(result) } -fn impl_metrics(emitter: &mut Emitter, _specs: &MetricSpecs, func: &syn2::ItemFn) -> TokenStream { - let syn2::ItemFn { +fn impl_metrics(emitter: &mut Emitter, _specs: &MetricSpecs, func: &syn::ItemFn) -> TokenStream { + let syn::ItemFn { attrs, vis, sig, @@ -185,13 +185,13 @@ fn impl_metrics(emitter: &mut Emitter, _specs: &MetricSpecs, func: &syn2::ItemFn } = func; match sig.output.clone() { - syn2::ReturnType::Default => emit!( + syn::ReturnType::Default => emit!( emitter, sig.output, "`Fn` must return `Result`. Returns nothing instead. " ), #[allow(clippy::string_to_string)] - syn2::ReturnType::Type(_, typ) => match *typ { + syn::ReturnType::Type(_, typ) => match *typ { Type::Path(pth) => { let Path { segments, .. } = pth.path; let type_name = &segments.last().expect("non-empty path").ident; diff --git a/torii/derive/Cargo.toml b/torii/derive/Cargo.toml index 8e089a971ec..249ae035fd8 100644 --- a/torii/derive/Cargo.toml +++ b/torii/derive/Cargo.toml @@ -14,7 +14,7 @@ workspace = true proc-macro = true [dependencies] -syn2 = { workspace = true } +syn = { workspace = true } quote = { workspace = true } proc-macro2 = { workspace = true } manyhow = { workspace = true } diff --git a/torii/derive/src/lib.rs b/torii/derive/src/lib.rs index 05b5f3e5ed0..1f302cab7b2 100644 --- a/torii/derive/src/lib.rs +++ b/torii/derive/src/lib.rs @@ -3,7 +3,7 @@ use manyhow::{manyhow, Result}; use proc_macro2::{Span, TokenStream}; use quote::quote; -use syn2::{ +use syn::{ parse::{Parse, ParseStream}, punctuated::Punctuated, Ident, LitInt, Token, @@ -51,7 +51,7 @@ use syn2::{ #[manyhow] #[proc_macro] pub fn generate_endpoints(input: TokenStream) -> Result { - let EndpointList(list) = syn2::parse2(input)?; + let EndpointList(list) = syn::parse2(input)?; let lazy_arg_names = (1_u8..).map(|count| { Ident::new( format!("__endpoint_arg_{count}").as_str(), @@ -121,7 +121,7 @@ enum EndpointItem { } impl Parse for EndpointList { - fn parse(input: ParseStream) -> syn2::Result { + fn parse(input: ParseStream) -> syn::Result { let items = Punctuated::::parse_terminated(input)?; let mut seen_arg_counts = Vec::new(); for item in &items { @@ -130,7 +130,7 @@ impl Parse for EndpointList { | EndpointItem::ArgCount(arg_count) => { let curr_count = arg_count.base10_parse::()?; if seen_arg_counts.contains(&curr_count) { - return Err(syn2::Error::new_spanned( + return Err(syn::Error::new_spanned( arg_count.token(), "argument counts for all endpoints should be distinct", )); @@ -145,7 +145,7 @@ impl Parse for EndpointList { } impl Parse for EndpointItem { - fn parse(input: ParseStream) -> syn2::Result { + fn parse(input: ParseStream) -> syn::Result { let lookahead = input.lookahead1(); if lookahead.peek(LitInt) { input.parse().map(EndpointItem::ArgCount) diff --git a/version/derive/Cargo.toml b/version/derive/Cargo.toml index be02b1e5acf..0cb685b23b1 100644 --- a/version/derive/Cargo.toml +++ b/version/derive/Cargo.toml @@ -14,7 +14,7 @@ workspace = true proc-macro = true [dependencies] -syn2 = { workspace = true, features = ["default", "full"] } +syn = { workspace = true, features = ["default", "full"] } quote = { workspace = true } proc-macro2 = { workspace = true } manyhow = { workspace = true } diff --git a/version/derive/src/lib.rs b/version/derive/src/lib.rs index 8d7fdc71e16..db641e9e7c5 100644 --- a/version/derive/src/lib.rs +++ b/version/derive/src/lib.rs @@ -6,7 +6,7 @@ use darling::{ast::NestedMeta, FromMeta}; use manyhow::{bail, manyhow, Result}; use proc_macro2::{Span, TokenStream}; use quote::{format_ident, quote}; -use syn2::{ +use syn::{ parse::{Parse, ParseStream}, parse_quote, punctuated::Punctuated, @@ -85,7 +85,7 @@ pub fn version_with_json(args: TokenStream, item: TokenStream) -> Result Result { - let args = syn2::parse2(input)?; + let args = syn::parse2(input)?; Ok(impl_declare_versioned(&args, true, true)) } @@ -93,7 +93,7 @@ pub fn declare_versioned(input: TokenStream) -> Result { #[manyhow] #[proc_macro] pub fn declare_versioned_with_scale(input: TokenStream) -> Result { - let args = syn2::parse2(input)?; + let args = syn::parse2(input)?; Ok(impl_declare_versioned(&args, true, false)) } @@ -101,14 +101,14 @@ pub fn declare_versioned_with_scale(input: TokenStream) -> Result { #[manyhow] #[proc_macro] pub fn declare_versioned_with_json(input: TokenStream) -> Result { - let args = syn2::parse2(input)?; + let args = syn::parse2(input)?; Ok(impl_declare_versioned(&args, false, true)) } #[derive(FromMeta)] struct VersionArgs { version: u32, - versioned_alias: syn2::Ident, + versioned_alias: syn::Ident, } fn impl_version(args: TokenStream, item: &TokenStream) -> Result { @@ -119,7 +119,7 @@ fn impl_version(args: TokenStream, item: &TokenStream) -> Result { } = VersionArgs::from_list(&args)?; let (struct_name, generics) = { - let item = syn2::parse2::(item.clone())?; + let item = syn::parse2::(item.clone())?; match &item.data { Data::Struct(_) | Data::Enum(_) => {} _ => bail!("The attribute should be attached to either struct or enum."), @@ -141,7 +141,7 @@ fn impl_version(args: TokenStream, item: &TokenStream) -> Result { struct DeclareVersionedArgs { pub enum_name: Ident, - pub generics: syn2::Generics, + pub generics: syn::Generics, pub range: Range, pub _comma: Option, pub derive: Punctuated, @@ -170,7 +170,7 @@ impl DeclareVersionedArgs { impl Parse for DeclareVersionedArgs { fn parse(input: ParseStream) -> SynResult { let enum_name: Ident = input.parse()?; - let generics: syn2::Generics = input.parse()?; + let generics: syn::Generics = input.parse()?; let start_version: LitInt = input.parse()?; let start_version: u8 = start_version.base10_parse()?; let _: Token![..] = input.parse::()?; @@ -192,7 +192,7 @@ impl Parse for DeclareVersionedArgs { } } -fn impl_decode_versioned(enum_name: &Ident, generics: &syn2::Generics) -> proc_macro2::TokenStream { +fn impl_decode_versioned(enum_name: &Ident, generics: &syn::Generics) -> proc_macro2::TokenStream { let mut decode_where_clause = generics .where_clause .clone() @@ -243,7 +243,7 @@ fn impl_decode_versioned(enum_name: &Ident, generics: &syn2::Generics) -> proc_m fn impl_json( enum_name: &Ident, - generics: &syn2::Generics, + generics: &syn::Generics, version_field_name: &str, ) -> proc_macro2::TokenStream { let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); diff --git a/wasm_codec/derive/Cargo.toml b/wasm_codec/derive/Cargo.toml index 5dc2f1134d7..13c66ba9e6c 100644 --- a/wasm_codec/derive/Cargo.toml +++ b/wasm_codec/derive/Cargo.toml @@ -13,7 +13,7 @@ workspace = true proc-macro = true [dependencies] -syn2 = { workspace = true } +syn = { workspace = true } quote = { workspace = true } proc-macro2 = { workspace = true } once_cell = { workspace = true } diff --git a/wasm_codec/derive/src/lib.rs b/wasm_codec/derive/src/lib.rs index f5886b98ea3..55c7f226afe 100644 --- a/wasm_codec/derive/src/lib.rs +++ b/wasm_codec/derive/src/lib.rs @@ -8,24 +8,24 @@ use iroha_macro_utils::Emitter; use manyhow::{bail, emit, manyhow, Result}; use proc_macro2::TokenStream; use quote::quote; -use syn2::{parse_quote, punctuated::Punctuated}; +use syn::{parse_quote, punctuated::Punctuated}; mod kw { - syn2::custom_keyword!(state); + syn::custom_keyword!(state); } struct StateAttr { _state: kw::state, - _equal: syn2::Token![=], - ty: syn2::Type, + _equal: syn::Token![=], + ty: syn::Type, } -impl syn2::parse::Parse for StateAttr { - fn parse(input: syn2::parse::ParseStream) -> syn2::Result { +impl syn::parse::Parse for StateAttr { + fn parse(input: syn::parse::ParseStream) -> syn::Result { let state = input.parse()?; let equal = input.parse()?; - let type_str: syn2::LitStr = input.parse()?; - let ty = syn2::parse_str(&type_str.value())?; + let type_str: syn::LitStr = input.parse()?; + let ty = syn::parse_str(&type_str.value())?; Ok(Self { _state: state, _equal: equal, @@ -63,13 +63,13 @@ pub fn wrap(attr: TokenStream, item: TokenStream) -> TokenStream { let state_attr_opt: Option = if attr.is_empty() { None - } else if let Some(v) = emitter.handle(syn2::parse2(attr)) { + } else if let Some(v) = emitter.handle(syn::parse2(attr)) { Some(v) } else { return emitter.finish_token_stream(); }; - let Some(fn_item): Option = emitter.handle(syn2::parse2(item)) else { + let Some(fn_item): Option = emitter.handle(syn::parse2(item)) else { return emitter.finish_token_stream(); }; @@ -85,12 +85,12 @@ pub fn wrap(attr: TokenStream, item: TokenStream) -> TokenStream { fn impl_wrap_fn( emitter: &mut Emitter, state_attr_opt: &Option, - mut fn_item: syn2::ItemFn, + mut fn_item: syn::ItemFn, ) -> Option { let ident = &fn_item.sig.ident; let mut inner_fn_item = fn_item.clone(); - let inner_fn_ident = syn2::Ident::new(&format!("__{ident}_inner"), ident.span()); + let inner_fn_ident = syn::Ident::new(&format!("__{ident}_inner"), ident.span()); inner_fn_item.sig.ident = inner_fn_ident.clone(); let fn_class = classify_fn(emitter, &fn_item.sig)?; @@ -137,13 +137,13 @@ pub fn wrap_trait_fn(attr: TokenStream, item: TokenStream) -> TokenStream { let state_attr_opt: Option = if attr.is_empty() { None - } else if let Some(v) = emitter.handle(syn2::parse2(attr)) { + } else if let Some(v) = emitter.handle(syn::parse2(attr)) { Some(v) } else { return emitter.finish_token_stream(); }; - let Some(fn_item): Option = emitter.handle(syn2::parse2(item)) else { + let Some(fn_item): Option = emitter.handle(syn::parse2(item)) else { return emitter.finish_token_stream(); }; @@ -159,12 +159,12 @@ pub fn wrap_trait_fn(attr: TokenStream, item: TokenStream) -> TokenStream { fn impl_wrap_trait_fn( emitter: &mut Emitter, state_attr_opt: &Option, - mut fn_item: syn2::TraitItemFn, + mut fn_item: syn::TraitItemFn, ) -> Option { let ident = &fn_item.sig.ident; let mut inner_fn_item = fn_item.clone(); - let inner_fn_ident = syn2::Ident::new(&format!("__{ident}_inner"), ident.span()); + let inner_fn_ident = syn::Ident::new(&format!("__{ident}_inner"), ident.span()); inner_fn_item.sig.ident = inner_fn_ident; let fn_class = classify_fn(emitter, &fn_item.sig)?; @@ -197,9 +197,9 @@ fn gen_params( state: state_ty_from_fn_sig, return_type, }: &FnClass, - state_ty_from_attr: Option<&syn2::Type>, + state_ty_from_attr: Option<&syn::Type>, with_body: bool, -) -> Option> { +) -> Option> { let mut params = Punctuated::new(); if state_ty_from_fn_sig.is_some() || param.is_some() || return_type.is_some() { let state_ty = @@ -230,7 +230,7 @@ fn gen_output( FnClass { param, return_type, .. }: &FnClass, -) -> syn2::Type { +) -> syn::Type { match (param, return_type) { (None, None) => parse_quote! { () }, (Some(_), None | Some(ReturnType::Result(None, ErrType::WasmtimeError))) => parse_quote! { @@ -262,13 +262,13 @@ impl TokenStream> quote::ToTokens for LazyTokenStream { fn gen_body( emitter: &mut Emitter, - inner_fn_ident: &syn2::Ident, + inner_fn_ident: &syn::Ident, FnClass { param, state: state_ty_from_fn_sig, return_type, }: &FnClass, - state_ty_from_attr: Option<&syn2::Type>, + state_ty_from_attr: Option<&syn::Type>, ) -> Option { let decode_param = param.as_ref().map_or_else( || quote! {}, @@ -378,9 +378,9 @@ fn gen_body( /// Classified function struct FnClass { /// Input parameter - param: Option, + param: Option, /// Does function require state explicitly? - state: Option, + state: Option, /// Return type. /// [`None`] means `()` return_type: Option, @@ -389,10 +389,10 @@ struct FnClass { /// Classified return type enum ReturnType { /// [`Result`] type with [`Ok`] and [`Err`] types respectively - Result(Option, ErrType), + Result(Option, ErrType), /// Something other than [`Result`] #[allow(dead_code)] // May be used in future - Other(syn2::Type), + Other(syn::Type), } /// Classified error type @@ -401,10 +401,10 @@ enum ErrType { WasmtimeError, /// Something other than `wasmtime::Error` #[allow(dead_code)] // May be used in future - Other(syn2::Type), + Other(syn::Type), } -fn classify_fn(emitter: &mut Emitter, fn_sig: &syn2::Signature) -> Option { +fn classify_fn(emitter: &mut Emitter, fn_sig: &syn::Signature) -> Option { let params = &fn_sig.inputs; // It does not make sense to check further if the next function fails @@ -413,14 +413,14 @@ fn classify_fn(emitter: &mut Emitter, fn_sig: &syn2::Signature) -> Option { + syn::ReturnType::Default => { return Some(FnClass { param, state, return_type: None, }) } - syn2::ReturnType::Type(_, ref ty) => ty, + syn::ReturnType::Type(_, ref ty) => ty, }; let output_type_path = unwrap_path(emitter, output_ty)?; @@ -433,7 +433,7 @@ fn classify_fn(emitter: &mut Emitter, fn_sig: &syn2::Signature) -> Option Option Option { - if let syn2::FnArg::Typed(pat_type) = fn_arg { +fn extract_type_from_fn_arg(emitter: &mut Emitter, fn_arg: syn::FnArg) -> Option { + if let syn::FnArg::Typed(pat_type) = fn_arg { Some(pat_type) } else { emit!(emitter, fn_arg, "`self` arguments are forbidden"); @@ -481,8 +481,8 @@ fn extract_type_from_fn_arg(emitter: &mut Emitter, fn_arg: syn2::FnArg) -> Optio fn classify_params_and_state( emitter: &mut Emitter, - params: &Punctuated, -) -> Option<(Option, Option)> { + params: &Punctuated, +) -> Option<(Option, Option)> { match params.len() { 0 => Some((None, None)), 1 => { @@ -517,15 +517,15 @@ fn classify_params_and_state( } } -fn parse_state_param(param: &syn2::PatType) -> Result<&syn2::Type> { - let syn2::Pat::Ident(pat_ident) = &*param.pat else { +fn parse_state_param(param: &syn::PatType) -> Result<&syn::Type> { + let syn::Pat::Ident(pat_ident) = &*param.pat else { bail!(param, "State parameter should be an ident"); }; if !["state", "_state"].contains(&&*pat_ident.ident.to_string()) { bail!(param, "State parameter should be named `state` or `_state`"); } - let syn2::Type::Reference(ty_ref) = &*param.ty else { + let syn::Type::Reference(ty_ref) = &*param.ty else { bail!( param.ty, "State parameter should be either reference or mutable reference" @@ -536,19 +536,19 @@ fn parse_state_param(param: &syn2::PatType) -> Result<&syn2::Type> { } fn classify_ok_type( - generics: &Punctuated, -) -> Result> { + generics: &Punctuated, +) -> Result> { let Some(ok_generic) = generics.first() else { bail!("First generic argument expected in `Result` return type"); }; - let syn2::GenericArgument::Type(ok_type) = ok_generic else { + let syn::GenericArgument::Type(ok_type) = ok_generic else { bail!( ok_generic, "First generic of `Result` return type expected to be a type" ); }; - if let syn2::Type::Tuple(syn2::TypeTuple { elems, .. }) = ok_type { + if let syn::Type::Tuple(syn::TypeTuple { elems, .. }) = ok_type { Ok((!elems.is_empty()).then_some(ok_type.clone())) } else { Ok(Some(ok_type.clone())) @@ -557,8 +557,8 @@ fn classify_ok_type( fn extract_err_type<'arg>( emitter: &mut Emitter, - generics: &'arg Punctuated, -) -> Option<&'arg syn2::Type> { + generics: &'arg Punctuated, +) -> Option<&'arg syn::Type> { let Some(err_generic) = generics.iter().nth(1) else { emit!( emitter, @@ -567,7 +567,7 @@ fn extract_err_type<'arg>( return None; }; - if let syn2::GenericArgument::Type(err_type) = err_generic { + if let syn::GenericArgument::Type(err_type) = err_generic { Some(err_type) } else { emit!( @@ -579,8 +579,8 @@ fn extract_err_type<'arg>( } } -fn unwrap_path<'ty>(emitter: &mut Emitter, ty: &'ty syn2::Type) -> Option<&'ty syn2::Path> { - if let syn2::Type::Path(syn2::TypePath { ref path, .. }) = ty { +fn unwrap_path<'ty>(emitter: &mut Emitter, ty: &'ty syn::Type) -> Option<&'ty syn::Path> { + if let syn::Type::Path(syn::TypePath { ref path, .. }) = ty { Some(path) } else { emit!(emitter, ty, "Expected path"); @@ -590,8 +590,8 @@ fn unwrap_path<'ty>(emitter: &mut Emitter, ty: &'ty syn2::Type) -> Option<&'ty s fn last_segment<'path>( emitter: &mut Emitter, - path: &'path syn2::Path, -) -> Option<&'path syn2::PathSegment> { + path: &'path syn::Path, +) -> Option<&'path syn::PathSegment> { path.segments.last().or_else(|| { emit!(emitter, "At least one path segment expected"); None @@ -600,9 +600,9 @@ fn last_segment<'path>( fn retrieve_state_ty<'ty>( emitter: &mut Emitter, - state_ty_from_attr: Option<&'ty syn2::Type>, - state_ty_from_fn_sig: Option<&'ty syn2::Type>, -) -> Option<&'ty syn2::Type> { + state_ty_from_attr: Option<&'ty syn::Type>, + state_ty_from_fn_sig: Option<&'ty syn::Type>, +) -> Option<&'ty syn::Type> { state_ty_from_attr.or(state_ty_from_fn_sig).or_else(|| { emit!(emitter, "`state` attribute is required"); None