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
@@ -188,7 +188,7 @@ fn generate_native_call_generators(decl: &ItemTrait) -> Result<TokenStream> {
// Generate a native call generator for each function of the given trait.
for fn_ in fns {
let params = extract_parameter_names_types_and_borrows(&fn_, AllowSelfRefInParameters::No)?;
let params = extract_parameter_names_types_and_borrows(fn_, AllowSelfRefInParameters::No)?;
let trait_fn_name = &fn_.ident;
let function_name_str = fn_.ident.to_string();
let fn_name = generate_native_call_generator_fn_name(&fn_.ident);
@@ -336,7 +336,7 @@ fn generate_call_api_at_calls(decl: &ItemTrait) -> Result<TokenStream> {
// Generate a native call generator for each function of the given trait.
for (attrs, fn_) in fns {
let trait_name = &decl.ident;
let trait_fn_name = prefix_function_with_trait(&trait_name, &fn_.ident);
let trait_fn_name = prefix_function_with_trait(trait_name, &fn_.ident);
let fn_name = generate_call_api_at_fn_name(&fn_.ident);
let attrs = remove_supported_attributes(&mut attrs.clone());
@@ -360,7 +360,7 @@ fn generate_call_api_at_calls(decl: &ItemTrait) -> Result<TokenStream> {
let mut renames = Vec::new();
if let Some((_, a)) = attrs.iter().find(|a| a.0 == &RENAMED_ATTRIBUTE) {
let (old_name, version) = parse_renamed_attribute(a)?;
renames.push((version, prefix_function_with_trait(&trait_name, &old_name)));
renames.push((version, prefix_function_with_trait(trait_name, &old_name)));
}
renames.sort_by(|l, r| r.cmp(l));
@@ -582,7 +582,7 @@ impl<'a> ToClientSideDecl<'a> {
Vec::new()
},
};
let name = generate_method_runtime_api_impl_name(&self.trait_, &method.sig.ident);
let name = generate_method_runtime_api_impl_name(self.trait_, &method.sig.ident);
let block_id = self.block_id;
let crate_ = self.crate_;
@@ -619,9 +619,9 @@ impl<'a> ToClientSideDecl<'a> {
let params2 = params.clone();
let ret_type = return_type_extract_type(&method.sig.output);
fold_fn_decl_for_client_side(&mut method.sig, &self.block_id, &self.crate_);
fold_fn_decl_for_client_side(&mut method.sig, self.block_id, self.crate_);
let name_impl = generate_method_runtime_api_impl_name(&self.trait_, &method.sig.ident);
let name_impl = generate_method_runtime_api_impl_name(self.trait_, &method.sig.ident);
let crate_ = self.crate_;
let found_attributes = remove_supported_attributes(&mut method.attrs);
@@ -630,7 +630,7 @@ impl<'a> ToClientSideDecl<'a> {
let (native_handling, param_tuple) = match get_changed_in(&found_attributes) {
Ok(Some(version)) => {
// Make sure that the `changed_in` version is at least the current `api_version`.
if get_api_version(&self.found_attributes).ok() < Some(version) {
if get_api_version(self.found_attributes).ok() < Some(version) {
self.errors.push(
Error::new(
method.span(),
@@ -972,7 +972,7 @@ pub fn decl_runtime_apis_impl(input: proc_macro::TokenStream) -> proc_macro::Tok
}
fn decl_runtime_apis_impl_inner(api_decls: &[ItemTrait]) -> Result<TokenStream> {
check_trait_decls(&api_decls)?;
check_trait_decls(api_decls)?;
let hidden_includes = generate_hidden_includes(HIDDEN_INCLUDES_ID);
let runtime_decls = generate_runtime_decls(api_decls)?;
@@ -491,7 +491,7 @@ impl<'a> Fold for ApiRuntimeImplToApiRuntimeApiImpl<'a> {
};
input.sig.ident =
generate_method_runtime_api_impl_name(&self.impl_trait, &input.sig.ident);
generate_method_runtime_api_impl_name(self.impl_trait, &input.sig.ident);
let ret_type = return_type_extract_type(&input.sig.output);
// Generate the correct return type.
@@ -593,7 +593,7 @@ fn generate_api_impl_for_runtime_api(impls: &[ItemImpl]) -> Result<TokenStream>
let mut result = Vec::with_capacity(impls.len());
for impl_ in impls {
let impl_trait_path = extract_impl_trait(&impl_, RequireQualifiedTraitPath::Yes)?;
let impl_trait_path = extract_impl_trait(impl_, RequireQualifiedTraitPath::Yes)?;
let impl_trait = &impl_trait_path
.segments
.last()
@@ -634,7 +634,7 @@ fn generate_runtime_api_versions(impls: &[ItemImpl]) -> Result<TokenStream> {
for impl_ in impls {
let mut path = extend_with_runtime_decl_path(
extract_impl_trait(&impl_, RequireQualifiedTraitPath::Yes)?.clone(),
extract_impl_trait(impl_, RequireQualifiedTraitPath::Yes)?.clone(),
);
// Remove the trait
let trait_ = path
@@ -723,7 +723,7 @@ fn impl_runtime_apis_impl_inner(api_impls: &[ItemImpl]) -> Result<TokenStream> {
// Filters all attributes except the cfg ones.
fn filter_cfg_attrs(attrs: &[Attribute]) -> Vec<Attribute> {
attrs.into_iter().filter(|a| a.path.is_ident("cfg")).cloned().collect()
attrs.iter().filter(|a| a.path.is_ident("cfg")).cloned().collect()
}
#[cfg(test)]
@@ -283,7 +283,7 @@ impl<'a> Fold for FoldRuntimeApiImpl<'a> {
};
input.sig.ident =
generate_method_runtime_api_impl_name(&self.impl_trait, &input.sig.ident);
generate_method_runtime_api_impl_name(self.impl_trait, &input.sig.ident);
// When using advanced, the user needs to declare the correct return type on its own,
// otherwise do it for the user.
@@ -350,7 +350,7 @@ fn generate_runtime_api_impls(impls: &[ItemImpl]) -> Result<GeneratedRuntimeApiI
let mut self_ty: Option<Box<Type>> = None;
for impl_ in impls {
let impl_trait_path = extract_impl_trait(&impl_, RequireQualifiedTraitPath::No)?;
let impl_trait_path = extract_impl_trait(impl_, RequireQualifiedTraitPath::No)?;
let impl_trait = &impl_trait_path
.segments
.last()
@@ -61,12 +61,11 @@ pub fn generate_crate_access(unique_id: &'static str) -> TokenStream {
let mod_name = generate_hidden_includes_mod_name(unique_id);
quote!( self::#mod_name::sp_api )
}
.into()
}
/// Generates the name of the module that contains the trait declaration for the runtime.
pub fn generate_runtime_mod_name_for_trait(trait_: &Ident) -> Ident {
Ident::new(&format!("runtime_decl_for_{}", trait_.to_string()), Span::call_site())
Ident::new(&format!("runtime_decl_for_{}", trait_), Span::call_site())
}
/// Generates a name for a method that needs to be implemented in the runtime for the client side.
@@ -169,17 +168,17 @@ pub fn extract_parameter_names_types_and_borrows(
/// Generates the name for the native call generator function.
pub fn generate_native_call_generator_fn_name(fn_name: &Ident) -> Ident {
Ident::new(&format!("{}_native_call_generator", fn_name.to_string()), Span::call_site())
Ident::new(&format!("{}_native_call_generator", fn_name), Span::call_site())
}
/// Generates the name for the call api at function.
pub fn generate_call_api_at_fn_name(fn_name: &Ident) -> Ident {
Ident::new(&format!("{}_call_api_at", fn_name.to_string()), Span::call_site())
Ident::new(&format!("{}_call_api_at", fn_name), Span::call_site())
}
/// Prefix the given function with the trait name.
pub fn prefix_function_with_trait<F: ToString>(trait_: &Ident, function: &F) -> String {
format!("{}_{}", trait_.to_string(), function.to_string())
format!("{}_{}", trait_, function.to_string())
}
/// Extract all types that appear in signatures in the given `ImplItem`'s.
@@ -250,10 +249,7 @@ pub enum RequireQualifiedTraitPath {
}
/// Extract the trait that is implemented by the given `ItemImpl`.
pub fn extract_impl_trait<'a>(
impl_: &'a ItemImpl,
require: RequireQualifiedTraitPath,
) -> Result<&'a Path> {
pub fn extract_impl_trait(impl_: &ItemImpl, require: RequireQualifiedTraitPath) -> Result<&Path> {
impl_
.trait_
.as_ref()