Apply some clippy lints (#11154)

* Apply some clippy hints

* Revert clippy ci changes

* Update client/cli/src/commands/generate.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/cli/src/commands/inspect_key.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/db/src/bench.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/db/src/bench.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/service/src/client/block_rules.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/service/src/client/block_rules.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/network/src/transactions.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/network/src/protocol.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Revert due to missing `or_default` function.

* Fix compilation and simplify code

* Undo change that corrupts benchmark.

* fix clippy

* Update client/service/test/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/state-db/src/noncanonical.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/state-db/src/noncanonical.rs

remove leftovers!

* Update client/tracing/src/logging/directives.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update utils/fork-tree/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* added needed ref

* Update frame/referenda/src/benchmarking.rs

* Simplify byte-vec creation

* let's just not overlap the ranges

* Correction

* cargo fmt

* Update utils/frame/benchmarking-cli/src/shared/stats.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update utils/frame/benchmarking-cli/src/pallet/command.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update utils/frame/benchmarking-cli/src/pallet/command.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Giles Cope <gilescope@gmail.com>
This commit is contained in:
Falco Hirschenberger
2022-04-30 23:28:27 +02:00
committed by GitHub
parent a990473cf9
commit b581604aa7
368 changed files with 1927 additions and 2236 deletions
@@ -133,9 +133,10 @@ impl CallDef {
return Err(syn::Error::new(item.span(), "Invalid pallet::call, expected item impl"))
};
let mut instances = vec![];
instances.push(helper::check_impl_gen(&item.generics, item.impl_token.span())?);
instances.push(helper::check_pallet_struct_usage(&item.self_ty)?);
let instances = vec![
helper::check_impl_gen(&item.generics, item.impl_token.span())?,
helper::check_pallet_struct_usage(&item.self_ty)?,
];
if let Some((_, _, for_)) = item.trait_ {
let msg = "Invalid pallet::call, expected no trait ident as in \
@@ -373,9 +373,10 @@ impl ConfigDef {
let found = if item.supertraits.is_empty() {
"none".to_string()
} else {
let mut found = item.supertraits.iter().fold(String::new(), |acc, s| {
format!("{}`{}`, ", acc, quote::quote!(#s).to_string())
});
let mut found = item
.supertraits
.iter()
.fold(String::new(), |acc, s| format!("{}`{}`, ", acc, quote::quote!(#s)));
found.pop();
found.pop();
found
@@ -62,8 +62,8 @@ impl ErrorDef {
return Err(syn::Error::new(item.span(), msg))
}
let mut instances = vec![];
instances.push(helper::check_type_def_gen_no_bounds(&item.generics, item.ident.span())?);
let instances =
vec![helper::check_type_def_gen_no_bounds(&item.generics, item.ident.span())?];
if item.generics.where_clause.is_some() {
let msg = "Invalid pallet::error, where clause is not allowed on pallet error item";
@@ -87,9 +87,10 @@ impl ExtraConstantsDef {
))
};
let mut instances = vec![];
instances.push(helper::check_impl_gen(&item.generics, item.impl_token.span())?);
instances.push(helper::check_pallet_struct_usage(&item.self_ty)?);
let instances = vec![
helper::check_impl_gen(&item.generics, item.impl_token.span())?,
helper::check_pallet_struct_usage(&item.self_ty)?,
];
if let Some((_, _, for_)) = item.trait_ {
let msg = "Invalid pallet::call, expected no trait ident as in \
@@ -53,8 +53,7 @@ impl GenesisBuildDef {
})?
.1;
let mut instances = vec![];
instances.push(helper::check_genesis_builder_usage(&item_trait)?);
let instances = vec![helper::check_genesis_builder_usage(item_trait)?];
Ok(Self { attr_span, index, instances, where_clause: item.generics.where_clause.clone() })
}
@@ -49,7 +49,7 @@ impl GenesisConfigDef {
let mut instances = vec![];
// NOTE: GenesisConfig is not allowed to be only generic on I because it is not supported
// by construct_runtime.
if let Some(u) = helper::check_type_def_optional_gen(&generics, ident.span())? {
if let Some(u) = helper::check_type_def_optional_gen(generics, ident.span())? {
instances.push(u);
}
@@ -45,9 +45,10 @@ impl HooksDef {
return Err(syn::Error::new(item.span(), msg))
};
let mut instances = vec![];
instances.push(helper::check_pallet_struct_usage(&item.self_ty)?);
instances.push(helper::check_impl_gen(&item.generics, item.impl_token.span())?);
let instances = vec![
helper::check_pallet_struct_usage(&item.self_ty)?,
helper::check_impl_gen(&item.generics, item.impl_token.span())?,
];
let item_trait = &item
.trait_
@@ -50,9 +50,10 @@ impl InherentDef {
return Err(syn::Error::new(item.span(), msg))
}
let mut instances = vec![];
instances.push(helper::check_pallet_struct_usage(&item.self_ty)?);
instances.push(helper::check_impl_gen(&item.generics, item.impl_token.span())?);
let instances = vec![
helper::check_pallet_struct_usage(&item.self_ty)?,
helper::check_impl_gen(&item.generics, item.impl_token.span())?,
];
Ok(InherentDef { index, instances })
}
@@ -50,7 +50,7 @@ impl OriginDef {
let is_generic = !generics.params.is_empty();
let mut instances = vec![];
if let Some(u) = helper::check_type_def_optional_gen(&generics, item.span())? {
if let Some(u) = helper::check_type_def_optional_gen(generics, item.span())? {
instances.push(u);
} else {
// construct_runtime only allow generic event for instantiable pallet.
@@ -155,8 +155,8 @@ impl PalletStructDef {
return Err(syn::Error::new(item.generics.where_clause.span(), msg))
}
let mut instances = vec![];
instances.push(helper::check_type_def_gen_no_bounds(&item.generics, item.ident.span())?);
let instances =
vec![helper::check_type_def_gen_no_bounds(&item.generics, item.ident.span())?];
Ok(Self {
index,
@@ -272,7 +272,7 @@ fn check_generics(
);
e.pop();
e.pop();
e.push_str(".");
e.push('.');
e
};
@@ -550,7 +550,7 @@ fn process_generics(
let args_span = segment.arguments.span();
let args = match &segment.arguments {
syn::PathArguments::AngleBracketed(args) if args.args.len() != 0 => args,
syn::PathArguments::AngleBracketed(args) if !args.args.is_empty() => args,
_ => {
let msg = "Invalid pallet::storage, invalid number of generic generic arguments, \
expect more that 0 generic arguments.";
@@ -646,13 +646,16 @@ impl StorageDef {
self.rename_as
.as_ref()
.map(syn::LitStr::value)
.unwrap_or(self.ident.to_string())
.unwrap_or_else(|| self.ident.to_string())
}
/// Return either the span of the ident or the span of the literal in the
/// #[storage_prefix] attribute
pub fn prefix_span(&self) -> proc_macro2::Span {
self.rename_as.as_ref().map(syn::LitStr::span).unwrap_or(self.ident.span())
self.rename_as
.as_ref()
.map(syn::LitStr::span)
.unwrap_or_else(|| self.ident.span())
}
pub fn try_from(
@@ -672,8 +675,7 @@ impl StorageDef {
let cfg_attrs = helper::get_item_cfg_attrs(&item.attrs);
let mut instances = vec![];
instances.push(helper::check_type_def_gen(&item.generics, item.ident.span())?);
let instances = vec![helper::check_type_def_gen(&item.generics, item.ident.span())?];
let where_clause = item.generics.where_clause.clone();
let docs = get_doc_literals(&item.attrs);
@@ -52,9 +52,10 @@ impl ValidateUnsignedDef {
return Err(syn::Error::new(item.span(), msg))
}
let mut instances = vec![];
instances.push(helper::check_pallet_struct_usage(&item.self_ty)?);
instances.push(helper::check_impl_gen(&item.generics, item.impl_token.span())?);
let instances = vec![
helper::check_pallet_struct_usage(&item.self_ty)?,
helper::check_impl_gen(&item.generics, item.impl_token.span())?,
];
Ok(ValidateUnsignedDef { index, instances })
}