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
@@ -30,16 +30,16 @@ pub fn expand_outer_dispatch(
let mut query_call_part_macros = Vec::new();
let mut pallet_names = Vec::new();
let pallets_with_call = pallet_decls
.iter()
.filter(|decl| decl.exists_part("Call"));
let pallets_with_call = pallet_decls.iter().filter(|decl| decl.exists_part("Call"));
for pallet_declaration in pallets_with_call {
let name = &pallet_declaration.name;
let path = &pallet_declaration.path;
let index = pallet_declaration.index;
variant_defs.extend(quote!(#[codec(index = #index)] #name( #scrate::dispatch::CallableCallFor<#name, #runtime> ),));
variant_defs.extend(
quote!(#[codec(index = #index)] #name( #scrate::dispatch::CallableCallFor<#name, #runtime> ),),
);
variant_patterns.push(quote!(Call::#name(call)));
pallet_names.push(name);
query_call_part_macros.push(quote! {
@@ -18,7 +18,7 @@
use crate::construct_runtime::Pallet;
use inflector::Inflector;
use proc_macro2::TokenStream;
use quote::{ToTokens, format_ident, quote};
use quote::{format_ident, quote, ToTokens};
use syn::Ident;
pub fn expand_outer_config(
@@ -37,15 +37,18 @@ pub fn expand_outer_config(
let pallet_name = &decl.name;
let path_str = path.into_token_stream().to_string();
let config = format_ident!("{}Config", pallet_name);
let field_name = &Ident::new(
&pallet_name.to_string().to_snake_case(),
decl.name.span(),
);
let field_name =
&Ident::new(&pallet_name.to_string().to_snake_case(), decl.name.span());
let part_is_generic = !pallet_entry.generics.params.is_empty();
types.extend(expand_config_types(runtime, decl, &config, part_is_generic));
fields.extend(quote!(pub #field_name: #config,));
build_storage_calls.extend(expand_config_build_storage_call(scrate, runtime, decl, &field_name));
build_storage_calls.extend(expand_config_build_storage_call(
scrate,
runtime,
decl,
&field_name,
));
query_genesis_config_part_macros.push(quote! {
#path::__substrate_genesis_config_check::is_genesis_config_defined!(#pallet_name);
#[cfg(feature = "std")]
@@ -97,15 +100,15 @@ fn expand_config_types(
let path = &decl.path;
match (decl.instance.as_ref(), part_is_generic) {
(Some(inst), true) => quote!{
(Some(inst), true) => quote! {
#[cfg(any(feature = "std", test))]
pub type #config = #path::GenesisConfig<#runtime, #path::#inst>;
},
(None, true) => quote!{
(None, true) => quote! {
#[cfg(any(feature = "std", test))]
pub type #config = #path::GenesisConfig<#runtime>;
},
(_, false) => quote!{
(_, false) => quote! {
#[cfg(any(feature = "std", test))]
pub type #config = #path::GenesisConfig;
},
@@ -125,7 +128,7 @@ fn expand_config_build_storage_call(
quote!(#path::__InherentHiddenInstance)
};
quote!{
quote! {
#scrate::sp_runtime::BuildModuleGenesisStorage::
<#runtime, #instance>::build_module_genesis_storage(&self.#field_name, storage)?;
}
@@ -43,7 +43,7 @@ pub fn expand_outer_event(
be constructed: pallet `{}` must have generic `Event`",
pallet_name,
);
return Err(syn::Error::new(pallet_name.span(), msg));
return Err(syn::Error::new(pallet_name.span(), msg))
}
let part_is_generic = !generics.params.is_empty();
@@ -54,7 +54,13 @@ pub fn expand_outer_event(
(None, false) => quote!(#path::Event),
};
event_variants.extend(expand_event_variant(runtime, pallet_decl, index, instance, generics));
event_variants.extend(expand_event_variant(
runtime,
pallet_decl,
index,
instance,
generics,
));
event_conversions.extend(expand_event_conversion(scrate, pallet_decl, &pallet_event));
query_event_part_macros.push(quote! {
#path::__substrate_event_check::is_event_part_defined!(#pallet_name);
@@ -94,16 +100,16 @@ fn expand_event_variant(
match instance {
Some(inst) if part_is_generic => {
quote!(#[codec(index = #index)] #variant_name(#path::Event<#runtime, #path::#inst>),)
}
},
Some(inst) => {
quote!(#[codec(index = #index)] #variant_name(#path::Event<#path::#inst>),)
}
},
None if part_is_generic => {
quote!(#[codec(index = #index)] #variant_name(#path::Event<#runtime>),)
}
},
None => {
quote!(#[codec(index = #index)] #variant_name(#path::Event),)
}
},
}
}
@@ -114,7 +120,7 @@ fn expand_event_conversion(
) -> TokenStream {
let variant_name = &pallet.name;
quote!{
quote! {
impl From<#pallet_event> for Event {
fn from(x: #pallet_event) -> Self {
Event::#variant_name(x)
@@ -15,10 +15,10 @@
// See the License for the specific language governing permissions and
// limitations under the License
use proc_macro2::TokenStream;
use crate::construct_runtime::Pallet;
use syn::{Ident, TypePath};
use proc_macro2::TokenStream;
use quote::quote;
use syn::{Ident, TypePath};
pub fn expand_runtime_metadata(
runtime: &Ident,
@@ -48,7 +48,7 @@ pub fn expand_runtime_metadata(
let constants = expand_pallet_metadata_constants(runtime, scrate, decl);
let errors = expand_pallet_metadata_errors(runtime, scrate, decl);
quote!{
quote! {
#scrate::metadata::ModuleMetadata {
name: #scrate::metadata::DecodeDifferent::Encode(stringify!(#name)),
index: #index,
@@ -62,7 +62,7 @@ pub fn expand_runtime_metadata(
})
.collect::<Vec<_>>();
quote!{
quote! {
impl #runtime {
pub fn metadata() -> #scrate::metadata::RuntimeMetadataPrefixed {
#scrate::metadata::RuntimeMetadataLastVersion {
@@ -94,7 +94,7 @@ fn expand_pallet_metadata_storage(
let instance = decl.instance.as_ref().into_iter();
let path = &decl.path;
quote!{
quote! {
Some(#scrate::metadata::DecodeDifferent::Encode(
#scrate::metadata::FnEncode(
#path::Pallet::<#runtime #(, #path::#instance)*>::storage_metadata
@@ -116,7 +116,7 @@ fn expand_pallet_metadata_calls(
let instance = decl.instance.as_ref().into_iter();
let path = &decl.path;
quote!{
quote! {
Some(#scrate::metadata::DecodeDifferent::Encode(
#scrate::metadata::FnEncode(
#path::Pallet::<#runtime #(, #path::#instance)*>::call_functions
@@ -136,8 +136,12 @@ fn expand_pallet_metadata_events(
) -> TokenStream {
if filtered_names.contains(&"Event") {
let path = &decl.path;
let part_is_generic =
!decl.find_part("Event").expect("Event part exists; qed").generics.params.is_empty();
let part_is_generic = !decl
.find_part("Event")
.expect("Event part exists; qed")
.generics
.params
.is_empty();
let pallet_event = match (decl.instance.as_ref(), part_is_generic) {
(Some(inst), true) => quote!(#path::Event::<#runtime, #path::#inst>),
(Some(inst), false) => quote!(#path::Event::<#path::#inst>),
@@ -145,7 +149,7 @@ fn expand_pallet_metadata_events(
(None, false) => quote!(#path::Event),
};
quote!{
quote! {
Some(#scrate::metadata::DecodeDifferent::Encode(
#scrate::metadata::FnEncode(#pallet_event::metadata)
))
@@ -163,7 +167,7 @@ fn expand_pallet_metadata_constants(
let path = &decl.path;
let instance = decl.instance.as_ref().into_iter();
quote!{
quote! {
#scrate::metadata::DecodeDifferent::Encode(
#scrate::metadata::FnEncode(
#path::Pallet::<#runtime #(, #path::#instance)*>::module_constants_metadata
@@ -180,7 +184,7 @@ fn expand_pallet_metadata_errors(
let path = &decl.path;
let instance = decl.instance.as_ref().into_iter();
quote!{
quote! {
#scrate::metadata::DecodeDifferent::Encode(
#scrate::metadata::FnEncode(
<#path::Pallet::<#runtime #(, #path::#instance)*> as #scrate::metadata::ModuleErrorMetadata>::metadata
@@ -18,7 +18,7 @@
use crate::construct_runtime::{Pallet, SYSTEM_PALLET_NAME};
use proc_macro2::TokenStream;
use quote::quote;
use syn::{token, Ident, Generics};
use syn::{token, Generics, Ident};
pub fn expand_outer_origin(
runtime: &Ident,
@@ -26,13 +26,14 @@ pub fn expand_outer_origin(
pallets_token: token::Brace,
scrate: &TokenStream,
) -> syn::Result<TokenStream> {
let system_pallet = pallets.iter()
.find(|decl| decl.name == SYSTEM_PALLET_NAME)
.ok_or_else(|| syn::Error::new(
pallets_token.span,
"`System` pallet declaration is missing. \
let system_pallet =
pallets.iter().find(|decl| decl.name == SYSTEM_PALLET_NAME).ok_or_else(|| {
syn::Error::new(
pallets_token.span,
"`System` pallet declaration is missing. \
Please add this line: `System: frame_system::{Pallet, Call, Storage, Config, Event<T>},`",
))?;
)
})?;
let mut caller_variants = TokenStream::new();
let mut pallet_conversions = TokenStream::new();
@@ -52,15 +53,23 @@ pub fn expand_outer_origin(
be constructed: pallet `{}` must have generic `Origin`",
name
);
return Err(syn::Error::new(name.span(), msg));
return Err(syn::Error::new(name.span(), msg))
}
caller_variants.extend(
expand_origin_caller_variant(runtime, pallet_decl, index, instance, generics),
);
pallet_conversions.extend(
expand_origin_pallet_conversions(scrate, runtime, pallet_decl, instance, generics),
);
caller_variants.extend(expand_origin_caller_variant(
runtime,
pallet_decl,
index,
instance,
generics,
));
pallet_conversions.extend(expand_origin_pallet_conversions(
scrate,
runtime,
pallet_decl,
instance,
generics,
));
query_origin_part_macros.push(quote! {
#path::__substrate_origin_check::is_origin_part_defined!(#name);
});
@@ -270,16 +279,16 @@ fn expand_origin_caller_variant(
match instance {
Some(inst) if part_is_generic => {
quote!(#[codec(index = #index)] #variant_name(#path::Origin<#runtime, #path::#inst>),)
}
},
Some(inst) => {
quote!(#[codec(index = #index)] #variant_name(#path::Origin<#path::#inst>),)
}
},
None if part_is_generic => {
quote!(#[codec(index = #index)] #variant_name(#path::Origin<#runtime>),)
}
},
None => {
quote!(#[codec(index = #index)] #variant_name(#path::Origin),)
}
},
}
}
@@ -301,7 +310,7 @@ fn expand_origin_pallet_conversions(
None => quote!(#path::Origin),
};
quote!{
quote! {
impl From<#pallet_origin> for OriginCaller {
fn from(x: #pallet_origin) -> Self {
OriginCaller::#variant_name(x)