fix for when runtime API field name is _ (#1191)

* fix for when runtime API field name is _

* add a test

* formatting

---------

Co-authored-by: Tadeo hepperle <tadeo@do-mix.de>
This commit is contained in:
James Wilson
2023-10-05 15:16:15 +02:00
committed by GitHub
parent e91d0c7b37
commit 919b866c0f
5 changed files with 62 additions and 9 deletions
+8 -2
View File
@@ -36,8 +36,14 @@ fn generate_runtime_api(
.then_some(quote! { #( #[doc = #docs ] )* })
.unwrap_or_default();
let inputs: Vec<_> = method.inputs().map(|input| {
let name = format_ident!("{}", &input.name);
let inputs: Vec<_> = method.inputs().enumerate().map(|(idx, input)| {
// These are method names, which can just be '_', but struct field names can't
// just be an underscore, so fix any such names we find to work in structs.
let name = if input.name == "_" {
format_ident!("_{}", idx)
} else {
format_ident!("{}", &input.name)
};
let ty = type_gen.resolve_type_path(input.ty);
let param = quote!(#name: #ty);