Skip to content

Commit

Permalink
[refactor] #3682: unrename the syn2, as we no longer have two syn ver…
Browse files Browse the repository at this point in the history
…sions in our codebase

Signed-off-by: Nikita Strygin <[email protected]>
  • Loading branch information
DCNick3 committed Mar 11, 2024
1 parent fbade98 commit 56c5fbb
Show file tree
Hide file tree
Showing 52 changed files with 517 additions and 525 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion data_model/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
26 changes: 13 additions & 13 deletions data_model/derive/src/enum_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TokenStream> {
pub fn impl_enum_ref(input: &syn::DeriveInput) -> manyhow::Result<TokenStream> {
let input = EnumRef::from_derive_input(input)?;
Ok(quote! { #input })
}
Expand Down Expand Up @@ -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<EnumRefVariant, darling::util::Ignored>,
}

Expand All @@ -66,7 +66,7 @@ impl FromMeta for EnumRefDeriveAttrs {
}

impl FromVariant for EnumRefVariant {
fn from_variant(variant: &syn2::Variant) -> darling::Result<Self> {
fn from_variant(variant: &syn::Variant) -> darling::Result<Self> {
let transparent = EnumRefVariantAttrs::from_attributes(&variant.attrs)?;

let mut fields: Vec<_> = variant
Expand Down Expand Up @@ -96,7 +96,7 @@ impl FromVariant for EnumRefVariant {
}

impl FromDeriveInput for EnumRef {
fn from_derive_input(input: &syn2::DeriveInput) -> darling::Result<Self> {
fn from_derive_input(input: &syn::DeriveInput) -> darling::Result<Self> {
Ok(Self {
attrs: EnumRefAttrs::from_attributes(&input.attrs)?,
ident: gen_enum_ref_ident(&input.ident),
Expand Down Expand Up @@ -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)
}
8 changes: 4 additions & 4 deletions data_model/derive/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand All @@ -29,7 +29,7 @@ enum EventVariant {

impl FromVariant for EventVariant {
fn from_variant(variant: &Variant) -> darling::Result<Self> {
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),
Expand All @@ -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),
Expand Down Expand Up @@ -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!();
};
Expand Down
24 changes: 11 additions & 13 deletions data_model/derive/src/has_origin.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
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";

pub struct HasOriginEnum {
ident: Ident,
#[allow(unused)]
generics: syn2::Generics,
generics: syn::Generics,
variants: Vec<HasOriginVariant>,
origin: Type,
}

impl FromDeriveInput for HasOriginEnum {
fn from_derive_input(input: &syn2::DeriveInput) -> darling::Result<Self> {
fn from_derive_input(input: &syn::DeriveInput) -> darling::Result<Self> {
let ident = input.ident.clone();
let generics = input.generics.clone();

Expand All @@ -48,31 +46,31 @@ pub struct HasOriginVariant {
}

impl FromVariant for HasOriginVariant {
fn from_variant(variant: &syn2::Variant) -> darling::Result<Self> {
fn from_variant(variant: &syn::Variant) -> darling::Result<Self> {
let ident = variant.ident.clone();
let extractor = parse_single_list_attr_opt(HAS_ORIGIN_ATTR, &variant.attrs)?;

Ok(Self { ident, extractor })
}
}

attr_struct2! {
attr_struct! {
pub struct OriginAttr {
_kw: kw::origin,
_eq: Token![=],
ty: Type,
}
}

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!();
};
Expand All @@ -97,7 +95,7 @@ pub fn impl_has_origin(emitter: &mut Emitter, input: &syn2::DeriveInput) -> Toke
},
)
})
.collect::<Vec<syn2::Arm>>();
.collect::<Vec<syn::Arm>>();

let (impl_generics, ty_generics, where_clause) = enum_.generics.split_for_impl();

Expand Down
26 changes: 13 additions & 13 deletions data_model/derive/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -16,15 +16,15 @@ enum IdAttr {
}

impl FromAttributes for IdAttr {
fn from_attributes(attrs: &[syn2::Attribute]) -> darling::Result<Self> {
fn from_attributes(attrs: &[syn::Attribute]) -> darling::Result<Self> {
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::<kw::transparent>().is_ok() => {
syn::Meta::Path(_) => IdAttr::Normal,
syn::Meta::List(list) if list.parse_args::<kw::transparent>().is_ok() => {
IdAttr::Transparent
}
_ => {
Expand All @@ -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<darling::util::Ignored, IdField>,
}

struct IdField {
ident: Option<syn2::Ident>,
ty: syn2::Type,
ident: Option<syn::Ident>,
ty: syn::Type,
id_attr: IdAttr,
}

impl FromField for IdField {
fn from_field(field: &syn2::Field) -> darling::Result<Self> {
fn from_field(field: &syn::Field) -> darling::Result<Self> {
let ident = field.ident.clone();
let ty = field.ty.clone();
let id_attr = IdAttr::from_attributes(&field.attrs)?;
Expand All @@ -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!();
};
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 8 additions & 8 deletions data_model/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use proc_macro2::TokenStream;
#[manyhow]
#[proc_macro_derive(EnumRef, attributes(enum_ref))]
pub fn enum_ref(input: TokenStream) -> Result<TokenStream> {
let input = syn2::parse2(input)?;
let input = syn::parse2(input)?;
enum_ref::impl_enum_ref(&input)
}

Expand Down Expand Up @@ -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();
};

Expand All @@ -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();
};

Expand Down Expand Up @@ -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();
};

Expand Down Expand Up @@ -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();
};

Expand Down Expand Up @@ -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<TokenStream> {
let input = syn2::parse2(input)?;
let input = syn::parse2(input)?;

partially_tagged::impl_partially_tagged_serialize(&input)
}
Expand Down Expand Up @@ -552,7 +552,7 @@ pub fn partially_tagged_serialize_derive(input: TokenStream) -> Result<TokenStre
#[manyhow]
#[proc_macro_derive(PartiallyTaggedDeserialize, attributes(serde_partially_tagged, serde))]
pub fn partially_tagged_deserialize_derive(input: TokenStream) -> Result<TokenStream> {
let input = syn2::parse2(input)?;
let input = syn::parse2(input)?;

partially_tagged::impl_partially_tagged_deserialize(&input)
}
Expand Down Expand Up @@ -645,7 +645,7 @@ pub fn partially_tagged_deserialize_derive(input: TokenStream) -> Result<TokenSt
pub fn has_origin_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();
};

Expand Down
Loading

0 comments on commit 56c5fbb

Please sign in to comment.