Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Apply some clippy lints #11154

Merged
merged 37 commits into from
Apr 30, 2022

Conversation

hirschenberger
Copy link
Contributor

@hirschenberger hirschenberger commented Apr 2, 2022

fixes #11054

Summary

The intention of this PR is not to enable/enforce a set of clippy rules to CI. It is making it easier to do so by fixing a lot of clippy remarks so that maybe @gilescope can integrate more clippy lints step by step without giant changesets.

This PR involved a huge amount of yak-shaving activity (TBH. I underestimated the amount and I would not do it again). I tried to evaluate each change (or kind of change) and hope I found a good compromise. I know that others would have drawn the line somewhere else.

Unfortunately it was not feasable to create an extra commit for all different lints, as it would have increased the amount of work drastically. So I hope you can live with it and review the PR as a whole. Sorry for the reviewers. I'll sure change your suggestions and remarks.

I tried to keep an eye on API-compatibility. The only thing I changed on function signatures is removing lifetime-annotations that can be elided.

I created a list of lints that fall into three categories:

  • Nearly always applied
  • Applied sometimes depending on the code-context
  • Never applied

You can lookup these lints and what they do here: Clippy Lints

Nearly always applied

  • clone_on_copy: very frequent, maybe not really necessary performance-wise but reduces a lot of line-noise
  • needless_lifetimes: the compiler got smarter over the years
  • mem_replace_with_default
  • unwrap_or_else_default
  • redundant_pattern_matching
  • redundant_static_lifetimes
  • collapsible_else_if
  • single_match
  • manual_saturating_arithmetic
  • needless_borrow: a lot of them, changed them for type clarity
  • redundant_closure: also many of them, I hope it reduces codesize a bit and speeds up compilaton a bit
  • map_collect_result_unit
  • try_err
  • iter_cloned_collect
  • unnecessary_lazy_evaluations
  • mem_replace_option_with_none
  • match_ref_pats
  • into_iter_on_ref
  • field_reassign_with_default

Applied sometimes depending on the code-context

  • len_zero: I only applied it in the empty case: if map.is_empty() { not in the not empty case: if !map.is_empty() { for readability. In my opinion if map.len() > 0 { is easier to grasp.
  • needless_return: Sometimes an explicit return makes the code more clear
  • collapsible_if
  • option_map_unit_fn
  • vec_init_then_push
  • comparison_chain: Subsituting an if-elseif-else chain with a match makes the code less readable when no real matching but if condittions are involved.
  • or_fun_call Sometimes the fun is really trivial and maybe const like Zero::zero() and should be inlined nevertheless
  • let_and_return There was some false alarms where clippy could not resolve a macro between let and return.
  • match_like_matches_macro
  • nonminimal_bool

Never applied

  • result_unit_err
  • wrong_self_convention API
  • len_without_is_empty API
  • new_without_default API
  • unit_arg
  • eval_order_dependence false alarm due to macros
  • should_implement_trait API
  • from_over_into API
  • borrowed_box API
  • unused_unit API
  • enum_variant_names API
  • module_inception API

polkadot address: 1ZApdbwrNnT1Hey4xeTAH6SZPDgbA9ZVftNuu9jTRbkc2Bg

@hirschenberger hirschenberger changed the title Issue 11054 Apply some clippy lints Apr 2, 2022
Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not yet review all changes.

client/cli/src/commands/generate.rs Outdated Show resolved Hide resolved
client/cli/src/commands/inspect_key.rs Outdated Show resolved Hide resolved
client/cli/src/commands/vanity.rs Outdated Show resolved Hide resolved
client/db/src/bench.rs Show resolved Hide resolved
client/db/src/bench.rs Show resolved Hide resolved
client/service/src/client/block_rules.rs Outdated Show resolved Hide resolved
client/service/src/client/block_rules.rs Outdated Show resolved Hide resolved
client/peerset/src/peersstate.rs Outdated Show resolved Hide resolved
client/network/src/transactions.rs Outdated Show resolved Hide resolved
client/network/src/protocol.rs Outdated Show resolved Hide resolved
hirschenberger and others added 12 commits April 3, 2022 00:21
Co-authored-by: Bastian Köcher <[email protected]>
Co-authored-by: Bastian Köcher <[email protected]>
# Conflicts:
#	client/service/src/client/wasm_override.rs
#	primitives/state-machine/src/trie_backend_essence.rs
#	utils/fork-tree/src/lib.rs
#	utils/frame/benchmarking-cli/src/pallet/command.rs
#	utils/frame/remote-externalities/src/lib.rs
@hirschenberger
Copy link
Contributor Author

I'll try to keep this PR in sync with master, but I suspect it to conflict frequently due to it's sheer size.

@gilescope gilescope added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit labels Apr 14, 2022
@gilescope
Copy link
Contributor

@bkchr any concerns or is all good?

@bkchr
Copy link
Member

bkchr commented Apr 28, 2022

@bkchr any concerns or is all good?

I hope to finish the review tomorrow.

Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay @hirschenberger

Looks good and ty for your work :)

utils/frame/benchmarking-cli/src/shared/stats.rs Outdated Show resolved Hide resolved
utils/frame/benchmarking-cli/src/pallet/command.rs Outdated Show resolved Hide resolved
utils/frame/benchmarking-cli/src/pallet/command.rs Outdated Show resolved Hide resolved
@bkchr
Copy link
Member

bkchr commented Apr 30, 2022

/tip small

1 similar comment
@bkchr
Copy link
Member

bkchr commented Apr 30, 2022

/tip small

@substrate-tip-bot
Copy link

Please fix the following problems before calling the tip bot again:

  • Contributor did not properly post their Polkadot or Kusama address.

Make sure the pull request description has: "{network} address: {address}".

hirschenberger and others added 4 commits April 30, 2022 11:59
# Conflicts:
#	client/network/src/protocol/notifications/behaviour.rs
#	client/network/src/service.rs
@shawntabrizi
Copy link
Member

@hirschenberger if you would like a treasury tip, please include your address information above

@hirschenberger
Copy link
Contributor Author

@hirschenberger if you would like a treasury tip, please include your address information above

Ok, thanks

@bkchr
Copy link
Member

bkchr commented Apr 30, 2022

/tip small

@bkchr
Copy link
Member

bkchr commented Apr 30, 2022

bot merge

@paritytech-processbot paritytech-processbot bot merged commit 0ba251c into paritytech:master Apr 30, 2022
@hirschenberger
Copy link
Contributor Author

/tip small

@bkchr The tip-bot seems to be sleeping...

@shawntabrizi
Copy link
Member

/tip small

@substrate-tip-bot
Copy link

A small tip was successfully submitted for hirschenberger (1ZApdbwrNnT1Hey4xeTAH6SZPDgbA9ZVftNuu9jTRbkc2Bg on polkadot).

https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frpc.polkadot.io#/treasury/tips

godcodehunter pushed a commit to sensoriumxr/substrate that referenced this pull request Jun 22, 2022
* Apply some clippy hints

* Revert clippy ci changes

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

Co-authored-by: Bastian Köcher <[email protected]>

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

Co-authored-by: Bastian Köcher <[email protected]>

* Update client/db/src/bench.rs

Co-authored-by: Bastian Köcher <[email protected]>

* Update client/db/src/bench.rs

Co-authored-by: Bastian Köcher <[email protected]>

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

Co-authored-by: Bastian Köcher <[email protected]>

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

Co-authored-by: Bastian Köcher <[email protected]>

* Update client/network/src/transactions.rs

Co-authored-by: Bastian Köcher <[email protected]>

* Update client/network/src/protocol.rs

Co-authored-by: Bastian Köcher <[email protected]>

* 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 <[email protected]>

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

Co-authored-by: Bastian Köcher <[email protected]>

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

remove leftovers!

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

Co-authored-by: Bastian Köcher <[email protected]>

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

Co-authored-by: Bastian Köcher <[email protected]>

* 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 <[email protected]>

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

Co-authored-by: Bastian Köcher <[email protected]>

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

Co-authored-by: Bastian Köcher <[email protected]>

Co-authored-by: Bastian Köcher <[email protected]>
Co-authored-by: Giles Cope <[email protected]>
This was referenced Aug 15, 2022
DaviRain-Su pushed a commit to octopus-network/substrate that referenced this pull request Aug 23, 2022
* Apply some clippy hints

* Revert clippy ci changes

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

Co-authored-by: Bastian Köcher <[email protected]>

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

Co-authored-by: Bastian Köcher <[email protected]>

* Update client/db/src/bench.rs

Co-authored-by: Bastian Köcher <[email protected]>

* Update client/db/src/bench.rs

Co-authored-by: Bastian Köcher <[email protected]>

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

Co-authored-by: Bastian Köcher <[email protected]>

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

Co-authored-by: Bastian Köcher <[email protected]>

* Update client/network/src/transactions.rs

Co-authored-by: Bastian Köcher <[email protected]>

* Update client/network/src/protocol.rs

Co-authored-by: Bastian Köcher <[email protected]>

* 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 <[email protected]>

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

Co-authored-by: Bastian Köcher <[email protected]>

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

remove leftovers!

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

Co-authored-by: Bastian Köcher <[email protected]>

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

Co-authored-by: Bastian Köcher <[email protected]>

* 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 <[email protected]>

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

Co-authored-by: Bastian Köcher <[email protected]>

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

Co-authored-by: Bastian Köcher <[email protected]>

Co-authored-by: Bastian Köcher <[email protected]>
Co-authored-by: Giles Cope <[email protected]>
@shawntabrizi
Copy link
Member

shawntabrizi commented Oct 9, 2022

This PR changed sort to sort_unstable which is something we want to actively avoid.

See: #6754

This is how we had a consensus problem on Kusama.

cc @gilescope can you make sure that such linting in the future does not do this?

ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
* Apply some clippy hints

* Revert clippy ci changes

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

Co-authored-by: Bastian Köcher <[email protected]>

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

Co-authored-by: Bastian Köcher <[email protected]>

* Update client/db/src/bench.rs

Co-authored-by: Bastian Köcher <[email protected]>

* Update client/db/src/bench.rs

Co-authored-by: Bastian Köcher <[email protected]>

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

Co-authored-by: Bastian Köcher <[email protected]>

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

Co-authored-by: Bastian Köcher <[email protected]>

* Update client/network/src/transactions.rs

Co-authored-by: Bastian Köcher <[email protected]>

* Update client/network/src/protocol.rs

Co-authored-by: Bastian Köcher <[email protected]>

* 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 <[email protected]>

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

Co-authored-by: Bastian Köcher <[email protected]>

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

remove leftovers!

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

Co-authored-by: Bastian Köcher <[email protected]>

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

Co-authored-by: Bastian Köcher <[email protected]>

* 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 <[email protected]>

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

Co-authored-by: Bastian Köcher <[email protected]>

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

Co-authored-by: Bastian Köcher <[email protected]>

Co-authored-by: Bastian Köcher <[email protected]>
Co-authored-by: Giles Cope <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Address some clippy remarks
4 participants