Skip to content

Commit

Permalink
[fix]: Removed unnecessary indiretion to strings for proc-macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
batconjurer committed Dec 20, 2022
1 parent 189e9b6 commit 3ea7feb
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ pub fn validity_predicate(
// TODO: use this crate for errors: https://crates.io/crates/proc-macro-error
pub fn derive_storage_keys(item: TokenStream) -> TokenStream {
let struct_def = parse_macro_input!(item as ItemStruct);
create_storage_keys(struct_def).parse().unwrap()
create_storage_keys(struct_def).into()
}

#[inline]
// TODO: emit allow_deadcode in ALL and VALUES
fn create_storage_keys(struct_def: ItemStruct) -> String {
fn create_storage_keys(struct_def: ItemStruct) -> TokenStream2 {
// type check the struct - all fields must be of type `&'static str`
let fields = match &struct_def.fields {
syn::Fields::Named(fields) => &fields.named,
Expand Down Expand Up @@ -225,7 +225,6 @@ fn create_storage_keys(struct_def: ItemStruct) -> String {
};
}
}
.to_string()
}

#[inline]
Expand Down Expand Up @@ -277,7 +276,7 @@ mod test_proc_macros {
"#;
let struct_def = syn::parse_str(TEST).unwrap();
let result = create_storage_keys(struct_def);
let result: ItemImpl = syn::parse_str(&result).unwrap();
let result: ItemImpl = syn::parse2(result).unwrap();
let expected = syn::parse_str(EXPECT).unwrap();
assert_eq!(result, expected);
}
Expand Down

0 comments on commit 3ea7feb

Please sign in to comment.