Update scale-info to 2.5.0 (#896)

* Upodate scale-info to 2.5.0

* A couple more clippy fixes

* more deprecation things that appeared
This commit is contained in:
James Wilson
2023-04-03 12:52:25 +01:00
committed by GitHub
parent 34f0521fd2
commit c08eb6c8f1
25 changed files with 150 additions and 155 deletions
+4 -4
View File
@@ -37,7 +37,7 @@ pub fn generate_calls(
let mut struct_defs = super::generate_structs_from_variants(
type_gen,
call.ty.id(),
call.ty.id,
|name| name.to_upper_camel_case().into(),
"Call",
crate_path,
@@ -61,7 +61,7 @@ pub fn generate_calls(
.unzip(),
CompositeDefFields::NoFields => Default::default(),
CompositeDefFields::Unnamed(_) => {
return Err(CodegenError::InvalidCallVariant(call.ty.id()))
return Err(CodegenError::InvalidCallVariant(call.ty.id))
}
};
@@ -106,8 +106,8 @@ pub fn generate_calls(
.into_iter()
.unzip();
let call_ty = type_gen.resolve_type(call.ty.id());
let docs = call_ty.docs();
let call_ty = type_gen.resolve_type(call.ty.id);
let docs = &call_ty.docs;
let docs = should_gen_docs
.then_some(quote! { #( #[doc = #docs ] )* })
.unwrap_or_default();
+1 -1
View File
@@ -56,7 +56,7 @@ pub fn generate_constants(
return Err(CodegenError::MissingConstantMetadata(constant_name.into(), pallet_name.into()));
};
let return_ty = type_gen.resolve_type_path(constant.ty.id());
let return_ty = type_gen.resolve_type_path(constant.ty.id);
let docs = &constant.docs;
let docs = should_gen_docs
.then_some(quote! { #( #[doc = #docs ] )* })
+4 -4
View File
@@ -53,7 +53,7 @@ pub fn generate_events(
let struct_defs = super::generate_structs_from_variants(
type_gen,
event.ty.id(),
event.ty.id,
|name| name.into(),
"Event",
crate_path,
@@ -74,9 +74,9 @@ pub fn generate_events(
}
}
});
let event_type = type_gen.resolve_type_path(event.ty.id());
let event_ty = type_gen.resolve_type(event.ty.id());
let docs = event_ty.docs();
let event_type = type_gen.resolve_type_path(event.ty.id);
let event_ty = type_gen.resolve_type(event.ty.id);
let docs = &event_ty.docs;
let docs = should_gen_docs
.then_some(quote! { #( #[doc = #docs ] )* })
.unwrap_or_default();
+7 -7
View File
@@ -260,13 +260,13 @@ impl RuntimeGenerator {
// Get the path to the `Runtime` struct. We assume that the same path contains
// RuntimeCall and RuntimeEvent.
let runtime_type_id = self.metadata.ty.id();
let runtime_type_id = self.metadata.ty.id;
let runtime_path_segments = self
.metadata
.types
.resolve(runtime_type_id)
.ok_or(CodegenError::TypeNotFound(runtime_type_id))?
.path()
.path
.namespace()
.iter()
.map(|part| syn::PathSegment::from(format_ident!("{}", part)));
@@ -489,24 +489,24 @@ where
{
let ty = type_gen.resolve_type(type_id);
let scale_info::TypeDef::Variant(variant) = ty.type_def() else {
let scale_info::TypeDef::Variant(variant) = &ty.type_def else {
return Err(CodegenError::InvalidType(error_message_type_name.into()))
};
variant
.variants()
.variants
.iter()
.map(|var| {
let struct_name = variant_to_struct_name(var.name());
let struct_name = variant_to_struct_name(&var.name);
let fields = CompositeDefFields::from_scale_info_fields(
struct_name.as_ref(),
var.fields(),
&var.fields,
&[],
type_gen,
)?;
let docs = should_gen_docs.then_some(var.docs()).unwrap_or_default();
let docs = should_gen_docs.then_some(&*var.docs).unwrap_or_default();
let struct_def = CompositeDef::struct_def(
&ty,
struct_name.as_ref(),
+6 -6
View File
@@ -74,17 +74,17 @@ fn generate_storage_entry_fns(
let (fields, key_impl) = match &storage_entry.ty {
StorageEntryType::Plain(_) => (vec![], quote!(vec![])),
StorageEntryType::Map { key, .. } => {
let key_ty = type_gen.resolve_type(key.id());
match key_ty.type_def() {
let key_ty = type_gen.resolve_type(key.id);
match &key_ty.type_def {
// An N-map; return each of the keys separately.
TypeDef::Tuple(tuple) => {
let fields = tuple
.fields()
.fields
.iter()
.enumerate()
.map(|(i, f)| {
let field_name = format_ident!("_{}", syn::Index::from(i));
let field_type = type_gen.resolve_type_path(f.id());
let field_type = type_gen.resolve_type_path(f.id);
(field_name, field_type)
})
.collect::<Vec<_>>();
@@ -102,7 +102,7 @@ fn generate_storage_entry_fns(
}
// A map with a single key; return the single key.
_ => {
let ty_path = type_gen.resolve_type_path(key.id());
let ty_path = type_gen.resolve_type_path(key.id);
let fields = vec![(format_ident!("_0"), ty_path)];
let key_impl = quote! {
vec![ #crate_path::storage::address::make_static_storage_map_key(_0.borrow()) ]
@@ -125,7 +125,7 @@ fn generate_storage_entry_fns(
StorageEntryType::Plain(ref ty) => ty,
StorageEntryType::Map { ref value, .. } => value,
};
let storage_entry_value_ty = type_gen.resolve_type_path(storage_entry_ty.id());
let storage_entry_value_ty = type_gen.resolve_type_path(storage_entry_ty.id);
let docs = &storage_entry.docs;
let docs = should_gen_docs
+4 -4
View File
@@ -52,7 +52,7 @@ impl CompositeDef {
{
let ty = type_gen.resolve_type(field.type_id);
if matches!(
ty.type_def(),
ty.type_def,
TypeDef::Primitive(
TypeDefPrimitive::U8
| TypeDefPrimitive::U16
@@ -173,11 +173,11 @@ impl CompositeDefFields {
let mut unnamed_fields = Vec::new();
for field in fields {
let type_path = type_gen.resolve_field_type_path(field.ty().id(), parent_type_params);
let type_path = type_gen.resolve_field_type_path(field.ty.id, parent_type_params);
let field_type =
CompositeDefFieldType::new(field.ty().id(), type_path, field.type_name().cloned());
CompositeDefFieldType::new(field.ty.id, type_path, field.type_name.clone());
if let Some(name) = field.name() {
if let Some(name) = &field.name {
let field_name = format_ident!("{}", name);
named_fields.push((field_name, field_type))
} else {
+21 -26
View File
@@ -73,8 +73,8 @@ impl<'a> TypeGenerator<'a> {
let root_mod_ident = &self.types_mod_ident;
let mut root_mod = Module::new(root_mod_ident.clone(), root_mod_ident.clone());
for ty in self.type_registry.types() {
let path = ty.ty().path();
for ty in &self.type_registry.types {
let path = &ty.ty.path;
// Don't generate a type if it was substituted - the target type might
// not be in the type registry + our resolution already performs the substitution.
if self.type_substitutes.contains(path) {
@@ -101,7 +101,7 @@ impl<'a> TypeGenerator<'a> {
innermost_module.types.insert(
path.clone(),
TypeDefGen::from_type(ty.ty(), self, &self.crate_path, self.should_gen_docs)?,
TypeDefGen::from_type(&ty.ty, self, &self.crate_path, self.should_gen_docs)?,
);
}
@@ -169,67 +169,62 @@ impl<'a> TypeGenerator<'a> {
let mut ty = self.resolve_type(id);
if ty.path().ident() == Some("Cow".to_string()) {
if ty.path.ident() == Some("Cow".to_string()) {
ty = self.resolve_type(
ty.type_params()[0]
.ty()
ty.type_params[0]
.ty
.expect("type parameters to Cow are not expected to be skipped; qed")
.id(),
.id,
)
}
let params: Vec<_> = ty
.type_params()
.type_params
.iter()
.filter_map(|f| {
f.ty()
.map(|f| self.resolve_type_path_recurse(f.id(), false, parent_type_params))
f.ty.map(|f| self.resolve_type_path_recurse(f.id, false, parent_type_params))
})
.collect();
let ty = match ty.type_def() {
let ty = match &ty.type_def {
TypeDef::Composite(_) | TypeDef::Variant(_) => {
if let Some(ty) = self
.type_substitutes
.for_path_with_params(ty.path(), &params)
.for_path_with_params(&ty.path, &params)
{
ty
} else {
TypePathType::from_type_def_path(
ty.path(),
self.types_mod_ident.clone(),
params,
)
TypePathType::from_type_def_path(&ty.path, self.types_mod_ident.clone(), params)
}
}
TypeDef::Primitive(primitive) => TypePathType::Primitive {
def: primitive.clone(),
},
TypeDef::Array(arr) => TypePathType::Array {
len: arr.len() as usize,
len: arr.len as usize,
of: Box::new(self.resolve_type_path_recurse(
arr.type_param().id(),
arr.type_param.id,
false,
parent_type_params,
)),
},
TypeDef::Sequence(seq) => TypePathType::Vec {
of: Box::new(self.resolve_type_path_recurse(
seq.type_param().id(),
seq.type_param.id,
false,
parent_type_params,
)),
},
TypeDef::Tuple(tuple) => TypePathType::Tuple {
elements: tuple
.fields()
.fields
.iter()
.map(|f| self.resolve_type_path_recurse(f.id(), false, parent_type_params))
.map(|f| self.resolve_type_path_recurse(f.id, false, parent_type_params))
.collect(),
},
TypeDef::Compact(compact) => TypePathType::Compact {
inner: Box::new(self.resolve_type_path_recurse(
compact.type_param().id(),
compact.type_param.id,
false,
parent_type_params,
)),
@@ -238,12 +233,12 @@ impl<'a> TypeGenerator<'a> {
},
TypeDef::BitSequence(bitseq) => TypePathType::BitVec {
bit_order_type: Box::new(self.resolve_type_path_recurse(
bitseq.bit_order_type().id(),
bitseq.bit_order_type.id,
false,
parent_type_params,
)),
bit_store_type: Box::new(self.resolve_type_path_recurse(
bitseq.bit_store_type().id(),
bitseq.bit_store_type.id,
false,
parent_type_params,
)),
@@ -261,7 +256,7 @@ impl<'a> TypeGenerator<'a> {
/// Returns the derives to be applied to a generated type.
pub fn type_derives(&self, ty: &Type<PortableForm>) -> Result<Derives, CodegenError> {
let joined_path = ty.path().segments().join("::");
let joined_path = ty.path.segments.join("::");
let ty_path: syn::TypePath = syn::parse_str(&joined_path)
.map_err(|e| CodegenError::InvalidTypePath(joined_path, e))?;
Ok(self.derives.resolve(&ty_path))
+1 -1
View File
@@ -305,7 +305,7 @@ impl From<&syn::Path> for PathSegments {
impl<T: scale_info::form::Form> From<&scale_info::Path<T>> for PathSegments {
fn from(path: &scale_info::Path<T>) -> Self {
PathSegments(
path.segments()
path.segments
.iter()
.map(|x| x.as_ref().to_owned())
.collect(),
+16 -16
View File
@@ -40,15 +40,15 @@ impl TypeDefGen {
let derives = type_gen.type_derives(ty)?;
let type_params = ty
.type_params()
.type_params
.iter()
.enumerate()
.filter_map(|(i, tp)| match tp.ty() {
.filter_map(|(i, tp)| match &tp.ty {
Some(ty) => {
let tp_name = format_ident!("_{}", i);
Some(TypeParameter {
concrete_type_id: ty.id(),
original_name: tp.name().clone(),
concrete_type_id: ty.id,
original_name: tp.name.clone(),
name: tp_name,
})
}
@@ -58,17 +58,17 @@ impl TypeDefGen {
let mut type_params = TypeDefParameters::new(type_params);
let ty_kind = match ty.type_def() {
let ty_kind = match &ty.type_def {
TypeDef::Composite(composite) => {
let type_name = ty.path().ident().expect("structs should have a name");
let type_name = ty.path.ident().expect("structs should have a name");
let fields = CompositeDefFields::from_scale_info_fields(
&type_name,
composite.fields(),
&composite.fields,
type_params.params(),
type_gen,
)?;
type_params.update_unused(fields.field_types());
let docs = should_gen_docs.then_some(ty.docs()).unwrap_or_default();
let docs = should_gen_docs.then_some(&*ty.docs).unwrap_or_default();
let composite_def = CompositeDef::struct_def(
ty,
&type_name,
@@ -82,22 +82,22 @@ impl TypeDefGen {
TypeDefGenKind::Struct(composite_def)
}
TypeDef::Variant(variant) => {
let type_name = ty.path().ident().expect("variants should have a name");
let type_name = ty.path.ident().expect("variants should have a name");
let variants = variant
.variants()
.variants
.iter()
.map(|v| {
let fields = CompositeDefFields::from_scale_info_fields(
v.name(),
v.fields(),
&v.name,
&v.fields,
type_params.params(),
type_gen,
)?;
type_params.update_unused(fields.field_types());
let docs = should_gen_docs.then_some(v.docs()).unwrap_or_default();
let variant_def = CompositeDef::enum_variant_def(v.name(), fields, docs);
Ok((v.index(), variant_def))
let docs = should_gen_docs.then_some(&*v.docs).unwrap_or_default();
let variant_def = CompositeDef::enum_variant_def(&v.name, fields, docs);
Ok((v.index, variant_def))
})
.collect::<Result<Vec<_>, CodegenError>>()?;
@@ -106,7 +106,7 @@ impl TypeDefGen {
_ => TypeDefGenKind::BuiltIn,
};
let docs = ty.docs();
let docs = &ty.docs;
let ty_docs = should_gen_docs
.then_some(quote! { #( #[doc = #docs ] )* })
.unwrap_or_default();
+1 -1
View File
@@ -132,7 +132,7 @@ impl TypePathType {
root_mod_ident: Ident,
params: Vec<TypePath>,
) -> Self {
let path_segments = path.segments();
let path_segments = &*path.segments;
let path: syn::Path = match path_segments {
[] => panic!("Type has no ident"),