From 1381a1db3f4bd2baea2476ede9dbb20228bc4a7e Mon Sep 17 00:00:00 2001 From: abenso Date: Tue, 19 Aug 2025 16:45:50 -0300 Subject: [PATCH 1/3] remove proc-macro-error --- bolos-derive/src/enum_init.rs | 5 +---- bolos-derive/src/lib.rs | 2 -- bolos-derive/src/utils.rs | 13 ++++++------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/bolos-derive/src/enum_init.rs b/bolos-derive/src/enum_init.rs index 1788049..a548dfb 100644 --- a/bolos-derive/src/enum_init.rs +++ b/bolos-derive/src/enum_init.rs @@ -14,7 +14,6 @@ * limitations under the License. ********************************************************************************/ use proc_macro::TokenStream; -use proc_macro_error::{abort, abort_if_dirty}; use quote::{quote, ToTokens}; use syn::{ parse_macro_input, parse_quote, parse_quote_spanned, punctuated::Punctuated, token::Comma, @@ -107,7 +106,7 @@ pub fn enum_init(_metadata: TokenStream, input: TokenStream) -> TokenStream { let unnamed = &unnamed.unnamed; if unnamed.len() != 1 { - abort!(variant.ident.span(), "only 1 item in field supported") + panic!("only 1 item in field supported") } else { let field = unnamed.first().unwrap(); let variant_struct = create_variant_struct_for_unnamed( @@ -137,8 +136,6 @@ pub fn enum_init(_metadata: TokenStream, input: TokenStream) -> TokenStream { } }); - //if we emitted errors let's abort before we emit weird data - abort_if_dirty(); quote! { #type_enum diff --git a/bolos-derive/src/lib.rs b/bolos-derive/src/lib.rs index aef2b54..89346a1 100644 --- a/bolos-derive/src/lib.rs +++ b/bolos-derive/src/lib.rs @@ -28,7 +28,6 @@ use proc_macro::TokenStream; use quote::quote; use syn::{parse_macro_input, ItemStatic}; -use proc_macro_error::proc_macro_error; pub(crate) mod utils; @@ -123,7 +122,6 @@ pub fn lazy_static(metadata: TokenStream, input: TokenStream) -> TokenStream { mod enum_init; -#[proc_macro_error] #[proc_macro_attribute] /// The aim of this macro is to ease the writing of boilerplate for enums /// where we want to initialize said enum using [`MaybeUninit`]. diff --git a/bolos-derive/src/utils.rs b/bolos-derive/src/utils.rs index f74d62f..c959f61 100644 --- a/bolos-derive/src/utils.rs +++ b/bolos-derive/src/utils.rs @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. ********************************************************************************/ -use proc_macro_error::emit_error; use syn::{ - punctuated::Punctuated, spanned::Spanned, visit::Visit, Attribute, GenericArgument, + punctuated::Punctuated, visit::Visit, Attribute, GenericArgument, GenericParam, Generics, Ident, Type, TypePath, }; @@ -68,7 +67,7 @@ impl<'ast> GenericArgumentsCollector<'ast> { Type::Array(i) => this.visit_type_array(i), Type::Path(i) => this.visit_type_path(i), Type::Tuple(i) => this.visit_type_tuple(i), - _ => emit_error!(ty.span(), "unsupported type"), + _ => panic!("unsupported type"), } this @@ -97,9 +96,9 @@ impl<'ast> GenericArgumentsCollector<'ast> { impl<'ast> Visit<'ast> for GenericArgumentsCollector<'ast> { fn visit_parenthesized_generic_arguments( &mut self, - i: &'ast syn::ParenthesizedGenericArguments, + _i: &'ast syn::ParenthesizedGenericArguments, ) { - emit_error!(i.span(), "paranthesized generics arguments not supported") + panic!("paranthesized generics arguments not supported") } fn visit_generic_argument(&mut self, i: &'ast GenericArgument) { @@ -186,7 +185,7 @@ impl<'ast> Visit<'ast> for GenericParamsCollector<'ast> { pub fn remove_doc_comment_attributes(attrs: Vec) -> Vec { attrs .into_iter() - .filter(|a| !a.path.is_ident("doc")) + .filter(|a| !a.path().is_ident("doc")) .collect() } @@ -196,7 +195,7 @@ pub fn remove_doc_comment_attributes(attrs: Vec) -> Vec { pub fn cfg_variant_attributes(attrs: Vec) -> Vec { attrs .into_iter() - .filter(|a| a.path.is_ident("cfg")) + .filter(|a| a.path().is_ident("cfg")) .collect() } From c83e68e2bd366ed34c13bd6deedbaecfad42fb8e Mon Sep 17 00:00:00 2001 From: abenso Date: Tue, 19 Aug 2025 17:02:00 -0300 Subject: [PATCH 2/3] update derive --- bolos-derive/Cargo.toml | 9 ++++----- bolos-derive/src/enum_init.rs | 1 + bolos-derive/src/lazy_static.rs | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bolos-derive/Cargo.toml b/bolos-derive/Cargo.toml index 9e29d46..b3fbd52 100644 --- a/bolos-derive/Cargo.toml +++ b/bolos-derive/Cargo.toml @@ -9,12 +9,11 @@ edition = "2018" proc-macro = true [dependencies] -syn = { version = "1.0", features = ["full", "extra-traits", "visit"] } -quote = "1.0" -proc-macro2 = "1" -proc-macro-error = { version = "1" } +syn = { version = "2.0.106", features = ["full", "extra-traits", "visit"] } +quote = "1.0.40" +proc-macro2 = "1.0.101" -convert_case = "0.6" +convert_case = "0.8.0" [dev-dependencies] bolos = { path = "../bolos" } diff --git a/bolos-derive/src/enum_init.rs b/bolos-derive/src/enum_init.rs index a548dfb..72a3d13 100644 --- a/bolos-derive/src/enum_init.rs +++ b/bolos-derive/src/enum_init.rs @@ -73,6 +73,7 @@ pub fn enum_init(_metadata: TokenStream, input: TokenStream) -> TokenStream { &Field { attrs: variant.attrs.clone(), vis: Visibility::Inherited, + mutability: syn::FieldMutability::None, ident: None, colon_token: None, ty: inner.clone(), diff --git a/bolos-derive/src/lazy_static.rs b/bolos-derive/src/lazy_static.rs index 21ec046..c8a989a 100644 --- a/bolos-derive/src/lazy_static.rs +++ b/bolos-derive/src/lazy_static.rs @@ -17,12 +17,12 @@ use proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; use quote::quote; use syn::{ - parse_macro_input, spanned::Spanned, AttributeArgs, Error, Expr, Ident, ItemStatic, Meta, - NestedMeta, Token, Type, + parse_macro_input, spanned::Spanned, Error, Expr, Ident, ItemStatic, Meta, + Token, Type, punctuated::Punctuated, parse::Parser, }; pub fn lazy_static(metadata: TokenStream, input: TokenStream) -> TokenStream { - let args = parse_macro_input!(metadata as AttributeArgs); + let args = Punctuated::::parse_terminated.parse(metadata).unwrap(); let input = parse_macro_input!(input as ItemStatic); let ItemStatic { @@ -39,7 +39,7 @@ pub fn lazy_static(metadata: TokenStream, input: TokenStream) -> TokenStream { &name, *ty, *expr, - mutability.is_some(), + matches!(mutability, syn::StaticMutability::Mut(_)), is_cbindgen_mode(&args), ) .map_err(|e| e.into_compile_error()) @@ -242,9 +242,9 @@ fn produce_custom_ty( // For example, it will return true for //#[attr(cbindgen)] #[allow(clippy::ptr_arg)] -fn is_cbindgen_mode(args: &AttributeArgs) -> bool { +fn is_cbindgen_mode(args: &Punctuated) -> bool { for arg in args { - if let NestedMeta::Meta(Meta::Path(path)) = arg { + if let Meta::Path(path) = arg { if path .segments .iter() From d7d26586bbdada70d51e3121c95a6197714bbde6 Mon Sep 17 00:00:00 2001 From: abenso Date: Tue, 19 Aug 2025 20:17:14 -0300 Subject: [PATCH 3/3] format --- bolos-derive/src/enum_init.rs | 1 - bolos-derive/src/lazy_static.rs | 8 +++++--- bolos-derive/src/lib.rs | 1 - bolos-derive/src/utils.rs | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bolos-derive/src/enum_init.rs b/bolos-derive/src/enum_init.rs index 72a3d13..d2fd9c0 100644 --- a/bolos-derive/src/enum_init.rs +++ b/bolos-derive/src/enum_init.rs @@ -137,7 +137,6 @@ pub fn enum_init(_metadata: TokenStream, input: TokenStream) -> TokenStream { } }); - quote! { #type_enum diff --git a/bolos-derive/src/lazy_static.rs b/bolos-derive/src/lazy_static.rs index c8a989a..e867dae 100644 --- a/bolos-derive/src/lazy_static.rs +++ b/bolos-derive/src/lazy_static.rs @@ -17,12 +17,14 @@ use proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; use quote::quote; use syn::{ - parse_macro_input, spanned::Spanned, Error, Expr, Ident, ItemStatic, Meta, - Token, Type, punctuated::Punctuated, parse::Parser, + parse::Parser, parse_macro_input, punctuated::Punctuated, spanned::Spanned, Error, Expr, Ident, + ItemStatic, Meta, Token, Type, }; pub fn lazy_static(metadata: TokenStream, input: TokenStream) -> TokenStream { - let args = Punctuated::::parse_terminated.parse(metadata).unwrap(); + let args = Punctuated::::parse_terminated + .parse(metadata) + .unwrap(); let input = parse_macro_input!(input as ItemStatic); let ItemStatic { diff --git a/bolos-derive/src/lib.rs b/bolos-derive/src/lib.rs index 89346a1..587d399 100644 --- a/bolos-derive/src/lib.rs +++ b/bolos-derive/src/lib.rs @@ -28,7 +28,6 @@ use proc_macro::TokenStream; use quote::quote; use syn::{parse_macro_input, ItemStatic}; - pub(crate) mod utils; // #[bolos::nvm] diff --git a/bolos-derive/src/utils.rs b/bolos-derive/src/utils.rs index c959f61..ad52db5 100644 --- a/bolos-derive/src/utils.rs +++ b/bolos-derive/src/utils.rs @@ -14,8 +14,8 @@ * limitations under the License. ********************************************************************************/ use syn::{ - punctuated::Punctuated, visit::Visit, Attribute, GenericArgument, - GenericParam, Generics, Ident, Type, TypePath, + punctuated::Punctuated, visit::Visit, Attribute, GenericArgument, GenericParam, Generics, + Ident, Type, TypePath, }; /// Helper extension iterator to `syn` things