Skip to content

Commit 7726cc0

Browse files
authored
Chore update bolos-derive (#51)
* remove proc-macro-error * format
1 parent 5e8481e commit 7726cc0

File tree

5 files changed

+21
-27
lines changed

5 files changed

+21
-27
lines changed

bolos-derive/Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ edition = "2018"
99
proc-macro = true
1010

1111
[dependencies]
12-
syn = { version = "1.0", features = ["full", "extra-traits", "visit"] }
13-
quote = "1.0"
14-
proc-macro2 = "1"
15-
proc-macro-error = { version = "1" }
12+
syn = { version = "2.0.106", features = ["full", "extra-traits", "visit"] }
13+
quote = "1.0.40"
14+
proc-macro2 = "1.0.101"
1615

17-
convert_case = "0.6"
16+
convert_case = "0.8.0"
1817

1918
[dev-dependencies]
2019
bolos = { path = "../bolos" }

bolos-derive/src/enum_init.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
********************************************************************************/
1616
use proc_macro::TokenStream;
17-
use proc_macro_error::{abort, abort_if_dirty};
1817
use quote::{quote, ToTokens};
1918
use syn::{
2019
parse_macro_input, parse_quote, parse_quote_spanned, punctuated::Punctuated, token::Comma,
@@ -74,6 +73,7 @@ pub fn enum_init(_metadata: TokenStream, input: TokenStream) -> TokenStream {
7473
&Field {
7574
attrs: variant.attrs.clone(),
7675
vis: Visibility::Inherited,
76+
mutability: syn::FieldMutability::None,
7777
ident: None,
7878
colon_token: None,
7979
ty: inner.clone(),
@@ -107,7 +107,7 @@ pub fn enum_init(_metadata: TokenStream, input: TokenStream) -> TokenStream {
107107

108108
let unnamed = &unnamed.unnamed;
109109
if unnamed.len() != 1 {
110-
abort!(variant.ident.span(), "only 1 item in field supported")
110+
panic!("only 1 item in field supported")
111111
} else {
112112
let field = unnamed.first().unwrap();
113113
let variant_struct = create_variant_struct_for_unnamed(
@@ -137,9 +137,6 @@ pub fn enum_init(_metadata: TokenStream, input: TokenStream) -> TokenStream {
137137
}
138138
});
139139

140-
//if we emitted errors let's abort before we emit weird data
141-
abort_if_dirty();
142-
143140
quote! {
144141
#type_enum
145142

bolos-derive/src/lazy_static.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ use proc_macro::TokenStream;
1717
use proc_macro2::TokenStream as TokenStream2;
1818
use quote::quote;
1919
use syn::{
20-
parse_macro_input, spanned::Spanned, AttributeArgs, Error, Expr, Ident, ItemStatic, Meta,
21-
NestedMeta, Token, Type,
20+
parse::Parser, parse_macro_input, punctuated::Punctuated, spanned::Spanned, Error, Expr, Ident,
21+
ItemStatic, Meta, Token, Type,
2222
};
2323

2424
pub fn lazy_static(metadata: TokenStream, input: TokenStream) -> TokenStream {
25-
let args = parse_macro_input!(metadata as AttributeArgs);
25+
let args = Punctuated::<Meta, Token![,]>::parse_terminated
26+
.parse(metadata)
27+
.unwrap();
2628
let input = parse_macro_input!(input as ItemStatic);
2729

2830
let ItemStatic {
@@ -39,7 +41,7 @@ pub fn lazy_static(metadata: TokenStream, input: TokenStream) -> TokenStream {
3941
&name,
4042
*ty,
4143
*expr,
42-
mutability.is_some(),
44+
matches!(mutability, syn::StaticMutability::Mut(_)),
4345
is_cbindgen_mode(&args),
4446
)
4547
.map_err(|e| e.into_compile_error())
@@ -242,9 +244,9 @@ fn produce_custom_ty(
242244
// For example, it will return true for
243245
//#[attr(cbindgen)]
244246
#[allow(clippy::ptr_arg)]
245-
fn is_cbindgen_mode(args: &AttributeArgs) -> bool {
247+
fn is_cbindgen_mode(args: &Punctuated<Meta, Token![,]>) -> bool {
246248
for arg in args {
247-
if let NestedMeta::Meta(Meta::Path(path)) = arg {
249+
if let Meta::Path(path) = arg {
248250
if path
249251
.segments
250252
.iter()

bolos-derive/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ use proc_macro::TokenStream;
2828
use quote::quote;
2929
use syn::{parse_macro_input, ItemStatic};
3030

31-
use proc_macro_error::proc_macro_error;
32-
3331
pub(crate) mod utils;
3432

3533
// #[bolos::nvm]
@@ -123,7 +121,6 @@ pub fn lazy_static(metadata: TokenStream, input: TokenStream) -> TokenStream {
123121

124122
mod enum_init;
125123

126-
#[proc_macro_error]
127124
#[proc_macro_attribute]
128125
/// The aim of this macro is to ease the writing of boilerplate for enums
129126
/// where we want to initialize said enum using [`MaybeUninit`].

bolos-derive/src/utils.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
********************************************************************************/
16-
use proc_macro_error::emit_error;
1716
use syn::{
18-
punctuated::Punctuated, spanned::Spanned, visit::Visit, Attribute, GenericArgument,
19-
GenericParam, Generics, Ident, Type, TypePath,
17+
punctuated::Punctuated, visit::Visit, Attribute, GenericArgument, GenericParam, Generics,
18+
Ident, Type, TypePath,
2019
};
2120

2221
/// Helper extension iterator to `syn` things
@@ -68,7 +67,7 @@ impl<'ast> GenericArgumentsCollector<'ast> {
6867
Type::Array(i) => this.visit_type_array(i),
6968
Type::Path(i) => this.visit_type_path(i),
7069
Type::Tuple(i) => this.visit_type_tuple(i),
71-
_ => emit_error!(ty.span(), "unsupported type"),
70+
_ => panic!("unsupported type"),
7271
}
7372

7473
this
@@ -97,9 +96,9 @@ impl<'ast> GenericArgumentsCollector<'ast> {
9796
impl<'ast> Visit<'ast> for GenericArgumentsCollector<'ast> {
9897
fn visit_parenthesized_generic_arguments(
9998
&mut self,
100-
i: &'ast syn::ParenthesizedGenericArguments,
99+
_i: &'ast syn::ParenthesizedGenericArguments,
101100
) {
102-
emit_error!(i.span(), "paranthesized generics arguments not supported")
101+
panic!("paranthesized generics arguments not supported")
103102
}
104103

105104
fn visit_generic_argument(&mut self, i: &'ast GenericArgument) {
@@ -186,7 +185,7 @@ impl<'ast> Visit<'ast> for GenericParamsCollector<'ast> {
186185
pub fn remove_doc_comment_attributes(attrs: Vec<Attribute>) -> Vec<Attribute> {
187186
attrs
188187
.into_iter()
189-
.filter(|a| !a.path.is_ident("doc"))
188+
.filter(|a| !a.path().is_ident("doc"))
190189
.collect()
191190
}
192191

@@ -196,7 +195,7 @@ pub fn remove_doc_comment_attributes(attrs: Vec<Attribute>) -> Vec<Attribute> {
196195
pub fn cfg_variant_attributes(attrs: Vec<Attribute>) -> Vec<Attribute> {
197196
attrs
198197
.into_iter()
199-
.filter(|a| a.path.is_ident("cfg"))
198+
.filter(|a| a.path().is_ident("cfg"))
200199
.collect()
201200
}
202201

0 commit comments

Comments
 (0)