Run cargo fmt on the whole code base (#9394)

* Run cargo fmt on the whole code base

* Second run

* Add CI check

* Fix compilation

* More unnecessary braces

* Handle weights

* Use --all

* Use correct attributes...

* Fix UI tests

* AHHHHHHHHH

* 🤦

* Docs

* Fix compilation

* 🤷

* Please stop

* 🤦 x 2

* More

* make rustfmt.toml consistent with polkadot

Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
Bastian Köcher
2021-07-21 16:32:32 +02:00
committed by GitHub
parent d451c38c1c
commit 7b56ab15b4
1010 changed files with 53339 additions and 51208 deletions
@@ -17,22 +17,22 @@
//! `decl_storage` input definition and expansion.
mod storage_struct;
mod storage_info;
mod parse;
mod store_trait;
mod getters;
mod metadata;
mod instance_trait;
mod genesis_config;
mod getters;
mod instance_trait;
mod metadata;
mod parse;
mod print_pallet_upgrade;
mod storage_info;
mod storage_struct;
mod store_trait;
pub(crate) use instance_trait::INHERENT_INSTANCE_NAME;
use quote::quote;
use frame_support_procedural_tools::{
generate_crate_access, generate_hidden_includes, syn_ext as ext
generate_crate_access, generate_hidden_includes, syn_ext as ext,
};
use quote::quote;
/// All information contained in input of decl_storage
pub struct DeclStorageDef {
@@ -115,34 +115,37 @@ pub struct DeclStorageDefExt {
impl From<DeclStorageDef> for DeclStorageDefExt {
fn from(mut def: DeclStorageDef) -> Self {
let hidden_crate_name = def.hidden_crate.as_ref().map(|i| i.to_string())
let hidden_crate_name = def
.hidden_crate
.as_ref()
.map(|i| i.to_string())
.unwrap_or_else(|| "decl_storage".to_string());
let hidden_crate = generate_crate_access(&hidden_crate_name, "frame-support");
let hidden_imports = generate_hidden_includes(&hidden_crate_name, "frame-support");
let storage_lines = def.storage_lines.drain(..).collect::<Vec<_>>();
let storage_lines = storage_lines.into_iter()
let storage_lines = storage_lines
.into_iter()
.map(|line| StorageLineDefExt::from_def(line, &def, &hidden_crate))
.collect();
let (
optional_instance,
optional_instance_bound,
optional_instance_bound_optional_default,
) = if let Some(instance) = def.module_instance.as_ref() {
let instance_generic = &instance.instance_generic;
let instance_trait= &instance.instance_trait;
let optional_equal_instance_default = instance.instance_default.as_ref()
.map(|d| quote!( = #d ));
(
Some(quote!(#instance_generic)),
Some(quote!(#instance_generic: #instance_trait)),
Some(quote!(#instance_generic: #instance_trait #optional_equal_instance_default)),
)
} else {
(None, None, None)
};
let (optional_instance, optional_instance_bound, optional_instance_bound_optional_default) =
if let Some(instance) = def.module_instance.as_ref() {
let instance_generic = &instance.instance_generic;
let instance_trait = &instance.instance_trait;
let optional_equal_instance_default =
instance.instance_default.as_ref().map(|d| quote!( = #d ));
(
Some(quote!(#instance_generic)),
Some(quote!(#instance_generic: #instance_trait)),
Some(
quote!(#instance_generic: #instance_trait #optional_equal_instance_default),
),
)
} else {
(None, None, None)
};
let module_runtime_generic = &def.module_runtime_generic;
let module_runtime_trait = &def.module_runtime_trait;
@@ -255,22 +258,20 @@ impl StorageLineDefExt {
hidden_crate: &proc_macro2::TokenStream,
) -> Self {
let is_generic = match &storage_def.storage_type {
StorageLineTypeDef::Simple(value) => {
ext::type_contains_ident(&value, &def.module_runtime_generic)
},
StorageLineTypeDef::Map(map) => {
ext::type_contains_ident(&map.key, &def.module_runtime_generic)
|| ext::type_contains_ident(&map.value, &def.module_runtime_generic)
}
StorageLineTypeDef::DoubleMap(map) => {
ext::type_contains_ident(&map.key1, &def.module_runtime_generic)
|| ext::type_contains_ident(&map.key2, &def.module_runtime_generic)
|| ext::type_contains_ident(&map.value, &def.module_runtime_generic)
}
StorageLineTypeDef::NMap(map) => {
map.keys.iter().any(|key| ext::type_contains_ident(key, &def.module_runtime_generic))
|| ext::type_contains_ident(&map.value, &def.module_runtime_generic)
}
StorageLineTypeDef::Simple(value) =>
ext::type_contains_ident(&value, &def.module_runtime_generic),
StorageLineTypeDef::Map(map) =>
ext::type_contains_ident(&map.key, &def.module_runtime_generic) ||
ext::type_contains_ident(&map.value, &def.module_runtime_generic),
StorageLineTypeDef::DoubleMap(map) =>
ext::type_contains_ident(&map.key1, &def.module_runtime_generic) ||
ext::type_contains_ident(&map.key2, &def.module_runtime_generic) ||
ext::type_contains_ident(&map.value, &def.module_runtime_generic),
StorageLineTypeDef::NMap(map) =>
map.keys
.iter()
.any(|key| ext::type_contains_ident(key, &def.module_runtime_generic)) ||
ext::type_contains_ident(&map.value, &def.module_runtime_generic),
};
let query_type = match &storage_def.storage_type {
@@ -280,15 +281,13 @@ impl StorageLineDefExt {
StorageLineTypeDef::NMap(map) => map.value.clone(),
};
let is_option = ext::extract_type_option(&query_type).is_some();
let value_type = ext::extract_type_option(&query_type).unwrap_or_else(|| query_type.clone());
let value_type =
ext::extract_type_option(&query_type).unwrap_or_else(|| query_type.clone());
let module_runtime_generic = &def.module_runtime_generic;
let module_runtime_trait = &def.module_runtime_trait;
let optional_storage_runtime_comma = if is_generic {
Some(quote!( #module_runtime_generic, ))
} else {
None
};
let optional_storage_runtime_comma =
if is_generic { Some(quote!( #module_runtime_generic, )) } else { None };
let optional_storage_runtime_bound_comma = if is_generic {
Some(quote!( #module_runtime_generic: #module_runtime_trait, ))
} else {
@@ -304,11 +303,8 @@ impl StorageLineDefExt {
#storage_name<#optional_storage_runtime_comma #optional_instance_generic>
);
let optional_storage_where_clause = if is_generic {
def.where_clause.as_ref().map(|w| quote!( #w ))
} else {
None
};
let optional_storage_where_clause =
if is_generic { def.where_clause.as_ref().map(|w| quote!( #w )) } else { None };
let storage_trait_truncated = match &storage_def.storage_type {
StorageLineTypeDef::Simple(_) => {
@@ -326,13 +322,15 @@ impl StorageLineDefExt {
StorageLineTypeDef::NMap(map) => {
let keygen = map.to_keygen_struct(hidden_crate);
quote!( StorageNMap<#keygen, #value_type> )
}
},
};
let storage_trait = quote!( storage::#storage_trait_truncated );
let storage_generator_trait = quote!( storage::generator::#storage_trait_truncated );
let doc_attrs = storage_def.attrs.iter()
let doc_attrs = storage_def
.attrs
.iter()
.filter_map(|a| a.parse_meta().ok())
.filter(|m| m.path().is_ident("doc"))
.collect();
@@ -396,27 +394,28 @@ impl NMapDef {
if self.keys.len() == 1 {
let hasher = &self.hashers[0].to_storage_hasher_struct();
let key = &self.keys[0];
return quote!( #scrate::storage::types::Key<#scrate::#hasher, #key> );
return quote!( #scrate::storage::types::Key<#scrate::#hasher, #key> )
}
let key_hasher = self.keys.iter().zip(&self.hashers).map(|(key, hasher)| {
let hasher = hasher.to_storage_hasher_struct();
quote!( #scrate::storage::types::Key<#scrate::#hasher, #key> )
})
.collect::<Vec<_>>();
let key_hasher = self
.keys
.iter()
.zip(&self.hashers)
.map(|(key, hasher)| {
let hasher = hasher.to_storage_hasher_struct();
quote!( #scrate::storage::types::Key<#scrate::#hasher, #key> )
})
.collect::<Vec<_>>();
quote!(( #(#key_hasher,)* ))
}
fn to_key_tuple(&self) -> proc_macro2::TokenStream {
if self.keys.len() == 1 {
let key = &self.keys[0];
return quote!(#key);
return quote!(#key)
}
let tuple = self.keys.iter().map(|key| {
quote!(#key)
})
.collect::<Vec<_>>();
let tuple = self.keys.iter().map(|key| quote!(#key)).collect::<Vec<_>>();
quote!(( #(#tuple,)* ))
}
}
@@ -442,25 +441,25 @@ pub enum HasherKind {
impl HasherKind {
fn to_storage_hasher_struct(&self) -> proc_macro2::TokenStream {
match self {
HasherKind::Blake2_256 => quote!( Blake2_256 ),
HasherKind::Blake2_128 => quote!( Blake2_128 ),
HasherKind::Blake2_128Concat => quote!( Blake2_128Concat ),
HasherKind::Twox256 => quote!( Twox256 ),
HasherKind::Twox128 => quote!( Twox128 ),
HasherKind::Twox64Concat => quote!( Twox64Concat ),
HasherKind::Identity => quote!( Identity ),
HasherKind::Blake2_256 => quote!(Blake2_256),
HasherKind::Blake2_128 => quote!(Blake2_128),
HasherKind::Blake2_128Concat => quote!(Blake2_128Concat),
HasherKind::Twox256 => quote!(Twox256),
HasherKind::Twox128 => quote!(Twox128),
HasherKind::Twox64Concat => quote!(Twox64Concat),
HasherKind::Identity => quote!(Identity),
}
}
fn into_metadata(&self) -> proc_macro2::TokenStream {
match self {
HasherKind::Blake2_256 => quote!( StorageHasher::Blake2_256 ),
HasherKind::Blake2_128 => quote!( StorageHasher::Blake2_128 ),
HasherKind::Blake2_128Concat => quote!( StorageHasher::Blake2_128Concat ),
HasherKind::Twox256 => quote!( StorageHasher::Twox256 ),
HasherKind::Twox128 => quote!( StorageHasher::Twox128 ),
HasherKind::Twox64Concat => quote!( StorageHasher::Twox64Concat ),
HasherKind::Identity => quote!( StorageHasher::Identity ),
HasherKind::Blake2_256 => quote!(StorageHasher::Blake2_256),
HasherKind::Blake2_128 => quote!(StorageHasher::Blake2_128),
HasherKind::Blake2_128Concat => quote!(StorageHasher::Blake2_128Concat),
HasherKind::Twox256 => quote!(StorageHasher::Twox256),
HasherKind::Twox128 => quote!(StorageHasher::Twox128),
HasherKind::Twox64Concat => quote!(StorageHasher::Twox64Concat),
HasherKind::Identity => quote!(StorageHasher::Identity),
}
}
}
@@ -502,5 +501,6 @@ pub fn decl_storage_impl(input: proc_macro::TokenStream) -> proc_macro::TokenStr
#genesis_config
#storage_struct
#storage_info
).into()
)
.into()
}