From 18d300b64ad6aa81b23210bdff54479eade6cc4a Mon Sep 17 00:00:00 2001 From: borngraced Date: Wed, 13 Dec 2023 02:09:20 +0100 Subject: [PATCH] downgrade syn dep Signed-off-by: borngraced --- .../derives/skip_serializing_none/Cargo.toml | 2 +- .../derives/skip_serializing_none/src/lib.rs | 74 +++++++++++-------- mm2src/komodefi_cli/Cargo.lock | 2 +- mm2src/komodefi_cli/Cargo.toml | 2 +- 4 files changed, 48 insertions(+), 32 deletions(-) diff --git a/mm2src/derives/skip_serializing_none/Cargo.toml b/mm2src/derives/skip_serializing_none/Cargo.toml index 90a49aaf42..b7346c79c1 100644 --- a/mm2src/derives/skip_serializing_none/Cargo.toml +++ b/mm2src/derives/skip_serializing_none/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies] quote = "1.0" proc-macro2 = "1.0" -syn = { version = "2", features = ["full"] } +syn = { version = "1.0", features = ["full"] } [lib] proc-macro = true diff --git a/mm2src/derives/skip_serializing_none/src/lib.rs b/mm2src/derives/skip_serializing_none/src/lib.rs index dc2f42432f..9f7b5781b2 100644 --- a/mm2src/derives/skip_serializing_none/src/lib.rs +++ b/mm2src/derives/skip_serializing_none/src/lib.rs @@ -1,6 +1,6 @@ use proc_macro::TokenStream; use proc_macro2::{Span, TokenStream as TokenStream2}; -use quote::quote; +use quote::{quote, ToTokens}; use syn::{parse::Parser, parse_quote, punctuated::Punctuated, spanned::Spanned, Error, Field, Fields, ItemEnum, ItemStruct, Meta, Token, Type}; @@ -77,11 +77,19 @@ fn skip_serializing_none_add_attr_to_field(field: &mut Field) -> Result<(), Stri let has_skip_serializing_if = field_has_attribute(field, "serde", "skip_serializing_if"); let mut has_always_attr = false; - field.attrs.retain(|attr| { - let has_attr = attr.path().is_ident("serialize_always"); + for attr in field.clone().attrs { + let has_attr = attr + .parse_meta() + .map_err(|e| e.to_string())? + .path() + .is_ident("serialize_always"); + has_always_attr |= has_attr; - !has_attr - }); + + if !has_attr { + field.attrs.retain(|ele| *ele == attr); + } + } if has_always_attr && has_skip_serializing_if { let mut msg = r#"The attributes `serialize_always` and `serde(skip_serializing_if = "...")` cannot be used on the same field"#.to_string(); @@ -103,9 +111,15 @@ fn skip_serializing_none_add_attr_to_field(field: &mut Field) -> Result<(), Stri ); field.attrs.push(attr); } else { - let has_attr = field.attrs.iter().any(|attr| attr.path().is_ident("serialize_always")); - if has_attr { - return Err("`serialize_always` may only be used on fields of type `Option`.".into()); + for attr in field.attrs.iter() { + if attr + .parse_meta() + .map_err(|e| e.to_string())? + .path() + .is_ident("serialize_always") + { + return Err("`serialize_always` may only be used on fields of type `Option`.".into()); + } } } Ok(()) @@ -146,29 +160,31 @@ fn is_std_option(type_: &Type) -> bool { fn field_has_attribute(field: &Field, namespace: &str, name: &str) -> bool { for attr in &field.attrs { - if attr.path().is_ident(namespace) { - if let Meta::List(expr) = &attr.meta { - let nested = match Punctuated::::parse_terminated.parse2(expr.tokens.clone()) { - Ok(nested) => nested, - Err(_) => continue, - }; - for expr in nested { - match expr { - Meta::NameValue(expr) => { - if let Some(ident) = expr.path.get_ident() { - if *ident == name { - return true; + if let Ok(meta) = attr.parse_meta() { + if meta.path().is_ident(namespace) { + if let Ok(Meta::List(expr)) = &attr.parse_meta() { + let nested = match Punctuated::::parse_terminated.parse2(expr.to_token_stream()) { + Ok(nested) => nested, + Err(_) => continue, + }; + for expr in nested { + match expr { + Meta::NameValue(expr) => { + if let Some(ident) = expr.path.get_ident() { + if *ident == name { + return true; + } } - } - }, - Meta::Path(expr) => { - if let Some(ident) = expr.get_ident() { - if *ident == name { - return true; + }, + Meta::Path(expr) => { + if let Some(ident) = expr.get_ident() { + if *ident == name { + return true; + } } - } - }, - _ => (), + }, + _ => (), + } } } } diff --git a/mm2src/komodefi_cli/Cargo.lock b/mm2src/komodefi_cli/Cargo.lock index 1609e73323..d7935bad06 100644 --- a/mm2src/komodefi_cli/Cargo.lock +++ b/mm2src/komodefi_cli/Cargo.lock @@ -3578,7 +3578,7 @@ version = "0.1.0" dependencies = [ "proc-macro2", "quote 1.0.33", - "syn 2.0.39", + "syn 1.0.95", ] [[package]] diff --git a/mm2src/komodefi_cli/Cargo.toml b/mm2src/komodefi_cli/Cargo.toml index 28c45441db..959c918497 100644 --- a/mm2src/komodefi_cli/Cargo.toml +++ b/mm2src/komodefi_cli/Cargo.toml @@ -9,7 +9,7 @@ description = "Provides a CLI interface and facilitates interoperating to komodo [target.'cfg(not(target_arch = "wasm32"))'.dependencies] anyhow = { version = "1.0.42", features = ["std"] } async-trait = "0.1.52" -clap = { version = "4.2.7", features = ["derive"] } +clap = { version = "4.0", features = ["derive"] } chrono = "0.4.23" common = { path = "../common" } crypto = { path = "../crypto" }