mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-06 02:08:02 +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:
@@ -23,14 +23,14 @@
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::Span;
|
||||
use syn::parse_macro_input;
|
||||
use quote::quote;
|
||||
use syn::parse_macro_input;
|
||||
|
||||
pub(crate) fn fields_idents(
|
||||
fields: impl Iterator<Item = syn::Field>,
|
||||
) -> impl Iterator<Item = proc_macro2::TokenStream> {
|
||||
fields.enumerate().map(|(ix, field)| {
|
||||
field.ident.map(|i| quote!{#i}).unwrap_or_else(|| {
|
||||
field.ident.map(|i| quote! {#i}).unwrap_or_else(|| {
|
||||
let f_ix: syn::Ident = syn::Ident::new(&format!("f_{}", ix), Span::call_site());
|
||||
quote!( #f_ix )
|
||||
})
|
||||
@@ -42,10 +42,7 @@ pub(crate) fn fields_access(
|
||||
) -> impl Iterator<Item = proc_macro2::TokenStream> {
|
||||
fields.enumerate().map(|(ix, field)| {
|
||||
field.ident.map(|i| quote!( #i )).unwrap_or_else(|| {
|
||||
let f_ix: syn::Index = syn::Index {
|
||||
index: ix as u32,
|
||||
span: Span::call_site(),
|
||||
};
|
||||
let f_ix: syn::Index = syn::Index { index: ix as u32, span: Span::call_site() };
|
||||
quote!( #f_ix )
|
||||
})
|
||||
})
|
||||
@@ -64,15 +61,10 @@ pub fn derive_parse(input: TokenStream) -> TokenStream {
|
||||
}
|
||||
|
||||
fn derive_parse_struct(input: syn::ItemStruct) -> TokenStream {
|
||||
let syn::ItemStruct {
|
||||
ident,
|
||||
generics,
|
||||
fields,
|
||||
..
|
||||
} = input;
|
||||
let syn::ItemStruct { ident, generics, fields, .. } = input;
|
||||
let field_names = {
|
||||
let name = fields_idents(fields.iter().map(Clone::clone));
|
||||
quote!{
|
||||
quote! {
|
||||
#(
|
||||
#name,
|
||||
)*
|
||||
@@ -110,12 +102,7 @@ pub fn derive_totokens(input: TokenStream) -> TokenStream {
|
||||
}
|
||||
|
||||
fn derive_totokens_struct(input: syn::ItemStruct) -> TokenStream {
|
||||
let syn::ItemStruct {
|
||||
ident,
|
||||
generics,
|
||||
fields,
|
||||
..
|
||||
} = input;
|
||||
let syn::ItemStruct { ident, generics, fields, .. } = input;
|
||||
|
||||
let fields = fields_access(fields.iter().map(Clone::clone));
|
||||
let tokens = quote! {
|
||||
@@ -133,12 +120,7 @@ fn derive_totokens_struct(input: syn::ItemStruct) -> TokenStream {
|
||||
}
|
||||
|
||||
fn derive_totokens_enum(input: syn::ItemEnum) -> TokenStream {
|
||||
let syn::ItemEnum {
|
||||
ident,
|
||||
generics,
|
||||
variants,
|
||||
..
|
||||
} = input;
|
||||
let syn::ItemEnum { ident, generics, variants, .. } = input;
|
||||
let variants = variants.iter().map(|v| {
|
||||
let v_ident = v.ident.clone();
|
||||
let fields_build = if v.fields.iter().count() > 0 {
|
||||
|
||||
@@ -23,13 +23,13 @@
|
||||
pub use frame_support_procedural_tools_derive::*;
|
||||
|
||||
use proc_macro_crate::{crate_name, FoundCrate};
|
||||
use syn::parse::Error;
|
||||
use quote::quote;
|
||||
use syn::parse::Error;
|
||||
|
||||
pub mod syn_ext;
|
||||
|
||||
// FIXME #1569, remove the following functions, which are copied from sp-api-macros
|
||||
use proc_macro2::{TokenStream, Span};
|
||||
use proc_macro2::{Span, TokenStream};
|
||||
use syn::Ident;
|
||||
|
||||
fn generate_hidden_includes_mod_name(unique_id: &str) -> Ident {
|
||||
@@ -39,7 +39,7 @@ fn generate_hidden_includes_mod_name(unique_id: &str) -> Ident {
|
||||
/// Generates the access to the `frame-support` crate.
|
||||
pub fn generate_crate_access(unique_id: &str, def_crate: &str) -> TokenStream {
|
||||
if std::env::var("CARGO_PKG_NAME").unwrap() == def_crate {
|
||||
quote::quote!( frame_support )
|
||||
quote::quote!(frame_support)
|
||||
} else {
|
||||
let mod_name = generate_hidden_includes_mod_name(unique_id);
|
||||
quote::quote!( self::#mod_name::hidden_include )
|
||||
@@ -55,12 +55,8 @@ pub fn generate_crate_access_2018(def_crate: &str) -> Result<syn::Ident, Error>
|
||||
let name = def_crate.to_string().replace("-", "_");
|
||||
Ok(syn::Ident::new(&name, Span::call_site()))
|
||||
},
|
||||
Ok(FoundCrate::Name(name)) => {
|
||||
Ok(Ident::new(&name, Span::call_site()))
|
||||
},
|
||||
Err(e) => {
|
||||
Err(Error::new(Span::call_site(), e))
|
||||
}
|
||||
Ok(FoundCrate::Name(name)) => Ok(Ident::new(&name, Span::call_site())),
|
||||
Err(e) => Err(Error::new(Span::call_site(), e)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +78,7 @@ pub fn generate_hidden_includes(unique_id: &str, def_crate: &str) -> TokenStream
|
||||
Err(e) => {
|
||||
let err = Error::new(Span::call_site(), e).to_compile_error();
|
||||
quote!( #err )
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,15 @@
|
||||
//! Extension to syn types, mainly for parsing
|
||||
// end::description[]
|
||||
|
||||
use syn::{visit::{Visit, self}, parse::{Parse, ParseStream, Result}, Ident};
|
||||
use frame_support_procedural_tools_derive::{Parse, ToTokens};
|
||||
use proc_macro2::{TokenStream, TokenTree};
|
||||
use quote::ToTokens;
|
||||
use std::iter::once;
|
||||
use frame_support_procedural_tools_derive::{ToTokens, Parse};
|
||||
use syn::{
|
||||
parse::{Parse, ParseStream, Result},
|
||||
visit::{self, Visit},
|
||||
Ident,
|
||||
};
|
||||
|
||||
/// stop parsing here getting remaining token as content
|
||||
/// Warn duplicate stream (part of)
|
||||
@@ -35,7 +39,6 @@ pub struct StopParse {
|
||||
// inner macro really dependant on syn naming convention, do not export
|
||||
macro_rules! groups_impl {
|
||||
($name:ident, $tok:ident, $deli:ident, $parse:ident) => {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct $name<P> {
|
||||
pub token: syn::token::$tok,
|
||||
@@ -46,7 +49,7 @@ macro_rules! groups_impl {
|
||||
fn parse(input: ParseStream) -> Result<Self> {
|
||||
let syn::group::$name { token, content } = syn::group::$parse(input)?;
|
||||
let content = content.parse()?;
|
||||
Ok($name { token, content, })
|
||||
Ok($name { token, content })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,12 +63,12 @@ macro_rules! groups_impl {
|
||||
}
|
||||
}
|
||||
|
||||
impl <P: Clone> Clone for $name<P> {
|
||||
impl<P: Clone> Clone for $name<P> {
|
||||
fn clone(&self) -> Self {
|
||||
Self { token: self.token.clone(), content: self.content.clone() }
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
groups_impl!(Braces, Brace, Brace, parse_braces);
|
||||
@@ -73,23 +76,22 @@ groups_impl!(Brackets, Bracket, Bracket, parse_brackets);
|
||||
groups_impl!(Parens, Paren, Parenthesis, parse_parens);
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PunctuatedInner<P,T,V> {
|
||||
pub inner: syn::punctuated::Punctuated<P,T>,
|
||||
pub struct PunctuatedInner<P, T, V> {
|
||||
pub inner: syn::punctuated::Punctuated<P, T>,
|
||||
pub variant: V,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct NoTrailing;
|
||||
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Trailing;
|
||||
|
||||
pub type Punctuated<P,T> = PunctuatedInner<P,T,NoTrailing>;
|
||||
pub type Punctuated<P, T> = PunctuatedInner<P, T, NoTrailing>;
|
||||
|
||||
pub type PunctuatedTrailing<P,T> = PunctuatedInner<P,T,Trailing>;
|
||||
pub type PunctuatedTrailing<P, T> = PunctuatedInner<P, T, Trailing>;
|
||||
|
||||
impl<P: Parse, T: Parse + syn::token::Token> Parse for PunctuatedInner<P,T,Trailing> {
|
||||
impl<P: Parse, T: Parse + syn::token::Token> Parse for PunctuatedInner<P, T, Trailing> {
|
||||
fn parse(input: ParseStream) -> Result<Self> {
|
||||
Ok(PunctuatedInner {
|
||||
inner: syn::punctuated::Punctuated::parse_separated_nonempty(input)?,
|
||||
@@ -98,7 +100,7 @@ impl<P: Parse, T: Parse + syn::token::Token> Parse for PunctuatedInner<P,T,Trail
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: Parse, T: Parse> Parse for PunctuatedInner<P,T,NoTrailing> {
|
||||
impl<P: Parse, T: Parse> Parse for PunctuatedInner<P, T, NoTrailing> {
|
||||
fn parse(input: ParseStream) -> Result<Self> {
|
||||
Ok(PunctuatedInner {
|
||||
inner: syn::punctuated::Punctuated::parse_terminated(input)?,
|
||||
@@ -107,13 +109,13 @@ impl<P: Parse, T: Parse> Parse for PunctuatedInner<P,T,NoTrailing> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: ToTokens, T: ToTokens, V> ToTokens for PunctuatedInner<P,T,V> {
|
||||
impl<P: ToTokens, T: ToTokens, V> ToTokens for PunctuatedInner<P, T, V> {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||
self.inner.to_tokens(tokens)
|
||||
}
|
||||
}
|
||||
|
||||
impl <P: Clone, T: Clone, V: Clone> Clone for PunctuatedInner<P, T, V> {
|
||||
impl<P: Clone, T: Clone, V: Clone> Clone for PunctuatedInner<P, T, V> {
|
||||
fn clone(&self) -> Self {
|
||||
Self { inner: self.inner.clone(), variant: self.variant.clone() }
|
||||
}
|
||||
@@ -127,9 +129,7 @@ pub struct Meta {
|
||||
|
||||
impl Parse for Meta {
|
||||
fn parse(input: ParseStream) -> Result<Self> {
|
||||
Ok(Meta {
|
||||
inner: syn::Meta::parse(input)?,
|
||||
})
|
||||
Ok(Meta { inner: syn::Meta::parse(input)? })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,9 +151,7 @@ pub struct OuterAttributes {
|
||||
impl Parse for OuterAttributes {
|
||||
fn parse(input: ParseStream) -> Result<Self> {
|
||||
let inner = syn::Attribute::parse_outer(input)?;
|
||||
Ok(OuterAttributes {
|
||||
inner,
|
||||
})
|
||||
Ok(OuterAttributes { inner })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,13 +187,11 @@ struct ContainsIdent<'a> {
|
||||
|
||||
impl<'ast> ContainsIdent<'ast> {
|
||||
fn visit_tokenstream(&mut self, stream: TokenStream) {
|
||||
stream.into_iter().for_each(|tt|
|
||||
match tt {
|
||||
TokenTree::Ident(id) => self.visit_ident(&id),
|
||||
TokenTree::Group(ref group) => self.visit_tokenstream(group.stream()),
|
||||
_ => {}
|
||||
}
|
||||
)
|
||||
stream.into_iter().for_each(|tt| match tt {
|
||||
TokenTree::Ident(id) => self.visit_ident(&id),
|
||||
TokenTree::Group(ref group) => self.visit_tokenstream(group.stream()),
|
||||
_ => {},
|
||||
})
|
||||
}
|
||||
|
||||
fn visit_ident(&mut self, ident: &Ident) {
|
||||
@@ -218,10 +214,7 @@ impl<'ast> Visit<'ast> for ContainsIdent<'ast> {
|
||||
|
||||
/// Check if a `Type` contains the given `Ident`.
|
||||
pub fn type_contains_ident(typ: &syn::Type, ident: &Ident) -> bool {
|
||||
let mut visit = ContainsIdent {
|
||||
result: false,
|
||||
ident,
|
||||
};
|
||||
let mut visit = ContainsIdent { result: false, ident };
|
||||
|
||||
visit::visit_type(&mut visit, typ);
|
||||
visit.result
|
||||
@@ -229,10 +222,7 @@ pub fn type_contains_ident(typ: &syn::Type, ident: &Ident) -> bool {
|
||||
|
||||
/// Check if a `Expr` contains the given `Ident`.
|
||||
pub fn expr_contains_ident(expr: &syn::Expr, ident: &Ident) -> bool {
|
||||
let mut visit = ContainsIdent {
|
||||
result: false,
|
||||
ident,
|
||||
};
|
||||
let mut visit = ContainsIdent { result: false, ident };
|
||||
|
||||
visit::visit_expr(&mut visit, expr);
|
||||
visit.result
|
||||
|
||||
Reference in New Issue
Block a user