mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 05:17:58 +00:00
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:
@@ -15,9 +15,9 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use quote::quote;
|
||||
use proc_macro2::TokenStream;
|
||||
use syn::{Data, DeriveInput, parse_quote};
|
||||
use quote::quote;
|
||||
use syn::{parse_quote, Data, DeriveInput};
|
||||
|
||||
pub fn debug_derive(ast: DeriveInput) -> proc_macro::TokenStream {
|
||||
let name_str = ast.ident.to_string();
|
||||
@@ -28,11 +28,11 @@ pub fn debug_derive(ast: DeriveInput) -> proc_macro::TokenStream {
|
||||
let wh = generics.make_where_clause();
|
||||
for t in ast.generics.type_params() {
|
||||
let name = &t.ident;
|
||||
wh.predicates.push(parse_quote!{ #name : core::fmt::Debug });
|
||||
wh.predicates.push(parse_quote! { #name : core::fmt::Debug });
|
||||
}
|
||||
generics.split_for_impl()
|
||||
};
|
||||
let gen = quote!{
|
||||
let gen = quote! {
|
||||
impl #impl_generics core::fmt::Debug for #name #ty_generics #where_clause {
|
||||
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
#implementation
|
||||
@@ -62,32 +62,26 @@ mod implementation {
|
||||
mod implementation {
|
||||
use super::*;
|
||||
use proc_macro2::Span;
|
||||
use syn::{Ident, Index, token::SelfValue};
|
||||
use syn::{token::SelfValue, Ident, Index};
|
||||
|
||||
/// Derive the inner implementation of `Debug::fmt` function.
|
||||
pub fn derive(name_str: &str, data: &Data) -> TokenStream {
|
||||
match *data {
|
||||
Data::Struct(ref s) => derive_struct(&name_str, &s.fields),
|
||||
Data::Union(ref u) => derive_fields(&name_str, Fields::new(u.fields.named.iter(), None)),
|
||||
Data::Union(ref u) =>
|
||||
derive_fields(&name_str, Fields::new(u.fields.named.iter(), None)),
|
||||
Data::Enum(ref e) => derive_enum(&name_str, &e),
|
||||
}
|
||||
}
|
||||
|
||||
enum Fields {
|
||||
Indexed {
|
||||
indices: Vec<Index>,
|
||||
},
|
||||
Unnamed {
|
||||
vars: Vec<Ident>,
|
||||
},
|
||||
Named {
|
||||
names: Vec<Ident>,
|
||||
this: Option<SelfValue>,
|
||||
},
|
||||
Indexed { indices: Vec<Index> },
|
||||
Unnamed { vars: Vec<Ident> },
|
||||
Named { names: Vec<Ident>, this: Option<SelfValue> },
|
||||
}
|
||||
|
||||
impl Fields {
|
||||
fn new<'a>(fields: impl Iterator<Item=&'a syn::Field>, this: Option<SelfValue>) -> Self {
|
||||
fn new<'a>(fields: impl Iterator<Item = &'a syn::Field>, this: Option<SelfValue>) -> Self {
|
||||
let mut indices = vec![];
|
||||
let mut names = vec![];
|
||||
|
||||
@@ -100,27 +94,17 @@ mod implementation {
|
||||
}
|
||||
|
||||
if names.is_empty() {
|
||||
Self::Indexed {
|
||||
indices,
|
||||
}
|
||||
Self::Indexed { indices }
|
||||
} else {
|
||||
Self::Named {
|
||||
names,
|
||||
this,
|
||||
}
|
||||
Self::Named { names, this }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn derive_fields<'a>(
|
||||
name_str: &str,
|
||||
fields: Fields,
|
||||
) -> TokenStream {
|
||||
fn derive_fields<'a>(name_str: &str, fields: Fields) -> TokenStream {
|
||||
match fields {
|
||||
Fields::Named { names, this } => {
|
||||
let names_str: Vec<_> = names.iter()
|
||||
.map(|x| x.to_string())
|
||||
.collect();
|
||||
let names_str: Vec<_> = names.iter().map(|x| x.to_string()).collect();
|
||||
|
||||
let fields = match this {
|
||||
None => quote! { #( .field(#names_str, #names) )* },
|
||||
@@ -132,16 +116,15 @@ mod implementation {
|
||||
#fields
|
||||
.finish()
|
||||
}
|
||||
|
||||
},
|
||||
Fields::Indexed { indices } => {
|
||||
Fields::Indexed { indices } => {
|
||||
quote! {
|
||||
fmt.debug_tuple(#name_str)
|
||||
#( .field(&self.#indices) )*
|
||||
.finish()
|
||||
}
|
||||
},
|
||||
Fields::Unnamed { vars } => {
|
||||
Fields::Unnamed { vars } => {
|
||||
quote! {
|
||||
fmt.debug_tuple(#name_str)
|
||||
#( .field(#vars) )*
|
||||
@@ -151,38 +134,33 @@ mod implementation {
|
||||
}
|
||||
}
|
||||
|
||||
fn derive_enum(
|
||||
name: &str,
|
||||
e: &syn::DataEnum,
|
||||
) -> TokenStream {
|
||||
let v = e.variants
|
||||
.iter()
|
||||
.map(|v| {
|
||||
let name = format!("{}::{}", name, v.ident);
|
||||
let ident = &v.ident;
|
||||
match v.fields {
|
||||
syn::Fields::Named(ref f) => {
|
||||
let names: Vec<_> = f.named.iter().flat_map(|f| f.ident.clone()).collect();
|
||||
let fields_impl = derive_fields(&name, Fields::Named {
|
||||
names: names.clone(),
|
||||
this: None,
|
||||
});
|
||||
(ident, (quote!{ { #( ref #names ),* } }, fields_impl))
|
||||
},
|
||||
syn::Fields::Unnamed(ref f) => {
|
||||
let names = f.unnamed.iter()
|
||||
.enumerate()
|
||||
.map(|(id, _)| Ident::new(&format!("a{}", id), Span::call_site()))
|
||||
.collect::<Vec<_>>();
|
||||
let fields_impl = derive_fields(&name, Fields::Unnamed { vars: names.clone() });
|
||||
(ident, (quote! { ( #( ref #names ),* ) }, fields_impl))
|
||||
},
|
||||
syn::Fields::Unit => {
|
||||
let fields_impl = derive_fields(&name, Fields::Indexed { indices: vec![] });
|
||||
(ident, (quote! { }, fields_impl))
|
||||
},
|
||||
}
|
||||
});
|
||||
fn derive_enum(name: &str, e: &syn::DataEnum) -> TokenStream {
|
||||
let v = e.variants.iter().map(|v| {
|
||||
let name = format!("{}::{}", name, v.ident);
|
||||
let ident = &v.ident;
|
||||
match v.fields {
|
||||
syn::Fields::Named(ref f) => {
|
||||
let names: Vec<_> = f.named.iter().flat_map(|f| f.ident.clone()).collect();
|
||||
let fields_impl =
|
||||
derive_fields(&name, Fields::Named { names: names.clone(), this: None });
|
||||
(ident, (quote! { { #( ref #names ),* } }, fields_impl))
|
||||
},
|
||||
syn::Fields::Unnamed(ref f) => {
|
||||
let names = f
|
||||
.unnamed
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(id, _)| Ident::new(&format!("a{}", id), Span::call_site()))
|
||||
.collect::<Vec<_>>();
|
||||
let fields_impl = derive_fields(&name, Fields::Unnamed { vars: names.clone() });
|
||||
(ident, (quote! { ( #( ref #names ),* ) }, fields_impl))
|
||||
},
|
||||
syn::Fields::Unit => {
|
||||
let fields_impl = derive_fields(&name, Fields::Indexed { indices: vec![] });
|
||||
(ident, (quote! {}, fields_impl))
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
type Vecs<A, B> = (Vec<A>, Vec<B>);
|
||||
let (variants, others): Vecs<_, _> = v.unzip();
|
||||
@@ -196,23 +174,15 @@ mod implementation {
|
||||
}
|
||||
}
|
||||
|
||||
fn derive_struct(
|
||||
name_str: &str,
|
||||
fields: &syn::Fields,
|
||||
) -> TokenStream {
|
||||
fn derive_struct(name_str: &str, fields: &syn::Fields) -> TokenStream {
|
||||
match *fields {
|
||||
syn::Fields::Named(ref f) => derive_fields(
|
||||
name_str,
|
||||
Fields::new(f.named.iter(), Some(syn::Token!(self)(Span::call_site()))),
|
||||
),
|
||||
syn::Fields::Unnamed(ref f) => derive_fields(
|
||||
name_str,
|
||||
Fields::new(f.unnamed.iter(), None),
|
||||
),
|
||||
syn::Fields::Unit => derive_fields(
|
||||
name_str,
|
||||
Fields::Indexed { indices: vec![] },
|
||||
),
|
||||
syn::Fields::Unnamed(ref f) =>
|
||||
derive_fields(name_str, Fields::new(f.unnamed.iter(), None)),
|
||||
syn::Fields::Unit => derive_fields(name_str, Fields::Indexed { indices: vec![] }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,5 @@ use proc_macro::TokenStream;
|
||||
|
||||
#[proc_macro_derive(RuntimeDebug)]
|
||||
pub fn debug_derive(input: TokenStream) -> TokenStream {
|
||||
impls::debug_derive(syn::parse_macro_input!(input))
|
||||
impls::debug_derive(syn::parse_macro_input!(input))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user