Retain Rust code items from mod decorated with subxt attribute (#721)

* refactor: Simplify collecting type substitutes

* Simplify ItemMod::from

* Preserve inner Rust items when expanding the subxt::subxt macro

* No named lifetimes

* Update codegen/src/api/mod.rs

Co-authored-by: Andrew Jones <ascjones@gmail.com>

* Move passing UI tests under `ui_tests`

Co-authored-by: Andrew Jones <ascjones@gmail.com>
This commit is contained in:
Igor Matuszewski
2022-11-23 12:28:49 +01:00
committed by GitHub
parent 15ffbb6c4b
commit 8b46f5c786
4 changed files with 54 additions and 9 deletions
+7 -4
View File
@@ -204,9 +204,7 @@ impl RuntimeGenerator {
})
.collect::<HashMap<_, _>>();
for (path, substitute) in item_mod_ir.type_substitutes().iter() {
type_substitutes.insert(path.to_string(), substitute.clone());
}
type_substitutes.extend(item_mod_ir.type_substitutes().into_iter());
let type_gen = TypeGenerator::new(
&self.metadata.types,
@@ -302,7 +300,7 @@ impl RuntimeGenerator {
}
};
let mod_ident = item_mod_ir.ident;
let mod_ident = &item_mod_ir.ident;
let pallets_with_constants: Vec<_> = pallets_with_mod_names
.iter()
.filter_map(|(pallet, pallet_mod_name)| {
@@ -324,9 +322,14 @@ impl RuntimeGenerator {
})
.collect();
let rust_items = item_mod_ir.rust_items();
quote! {
#[allow(dead_code, unused_imports, non_camel_case_types)]
pub mod #mod_ident {
// Preserve any Rust items that were previously defined in the adorned module
#( #rust_items ) *
// Make it easy to access the root via `root_mod` at different levels:
use super::#mod_ident as root_mod;
// Identify the pallets composing the static metadata by name.