diff --git a/lang/syn/src/codegen/program/common.rs b/lang/syn/src/codegen/program/common.rs index d94c7975c0..969b30f2f3 100644 --- a/lang/syn/src/codegen/program/common.rs +++ b/lang/syn/src/codegen/program/common.rs @@ -23,7 +23,7 @@ pub fn gen_discriminator(namespace: &str, name: impl ToString) -> proc_macro2::T format!("&{:?}", discriminator).parse().unwrap() } -pub fn generate_ix_variant(name: String, args: &[IxArg]) -> proc_macro2::TokenStream { +pub fn generate_ix_variant(name: &str, args: &[IxArg]) -> proc_macro2::TokenStream { let ix_arg_names: Vec<&syn::Ident> = args.iter().map(|arg| &arg.name).collect(); let ix_name_camel = generate_ix_variant_name(name); @@ -40,7 +40,7 @@ pub fn generate_ix_variant(name: String, args: &[IxArg]) -> proc_macro2::TokenSt } } -pub fn generate_ix_variant_name(name: String) -> proc_macro2::TokenStream { +pub fn generate_ix_variant_name(name: &str) -> proc_macro2::TokenStream { let n = name.to_camel_case(); n.parse().unwrap() } diff --git a/lang/syn/src/codegen/program/cpi.rs b/lang/syn/src/codegen/program/cpi.rs index a11e446b5f..5b1e5828c3 100644 --- a/lang/syn/src/codegen/program/cpi.rs +++ b/lang/syn/src/codegen/program/cpi.rs @@ -12,11 +12,12 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream { let accounts_ident: proc_macro2::TokenStream = format!("crate::cpi::accounts::{}", &ix.anchor_ident.to_string()).parse().unwrap(); let cpi_method = { let name = &ix.raw_method.sig.ident; - let ix_variant = generate_ix_variant(&name, &ix.args); + let name_str = name.to_string(); + let ix_variant = generate_ix_variant(&name_str, &ix.args); let method_name = &ix.ident; let args: Vec<&syn::PatType> = ix.args.iter().map(|arg| &arg.raw_arg).collect(); let discriminator = { - let name = generate_ix_variant_name(name.to_string()); + let name = generate_ix_variant_name(&name_str); quote! { ::DISCRIMINATOR } }; let ret_type = &ix.returns.ty.to_token_stream(); diff --git a/lang/syn/src/codegen/program/handlers.rs b/lang/syn/src/codegen/program/handlers.rs index d7ec39b2bb..1eb6d0214f 100644 --- a/lang/syn/src/codegen/program/handlers.rs +++ b/lang/syn/src/codegen/program/handlers.rs @@ -97,11 +97,12 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream { .iter() .map(|ix| { let ix_arg_names: Vec<&syn::Ident> = ix.args.iter().map(|arg| &arg.name).collect(); - let ix_name = generate_ix_variant_name(ix.raw_method.sig.ident.to_string()); let ix_method_name = &ix.raw_method.sig.ident; - let anchor = &ix.anchor_ident; - let variant_arm = generate_ix_variant(ix.raw_method.sig.ident.to_string(), &ix.args); + let ix_method_name_str = ix_method_name.to_string(); + let ix_name = generate_ix_variant_name(&ix_method_name_str); + let variant_arm = generate_ix_variant(&ix_method_name_str, &ix.args); let ix_name_log = format!("Instruction: {ix_name}"); + let anchor = &ix.anchor_ident; let ret_type = &ix.returns.ty.to_token_stream(); let cfgs = &ix.cfgs; let maybe_set_return_data = match ret_type.to_string().as_str() {