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

Commit

Permalink
Clippyfy (#6341)
Browse files Browse the repository at this point in the history
* Add clippy config and remove .cargo from gitignore

* first fixes

* Clippyfied

* Add clippy CI job

* comment out rusty-cachier

* minor

* fix ci

* remove DAG from check-dependent-project

* add DAG to clippy

Co-authored-by: alvicsam <alvicsam@gmail.com>
  • Loading branch information
alexgparity and alvicsam authored Nov 30, 2022
1 parent 7821614 commit 71a0fad
Show file tree
Hide file tree
Showing 67 changed files with 338 additions and 351 deletions.
32 changes: 32 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# An auto defined `clippy` feature was introduced,
# but it was found to clash with user defined features,
# so was renamed to `cargo-clippy`.
#
# If you want standard clippy run:
# RUSTFLAGS= cargo clippy
[target.'cfg(feature = "cargo-clippy")']
rustflags = [
"-Aclippy::all",
"-Dclippy::correctness",
"-Aclippy::if-same-then-else",
"-Aclippy::clone-double-ref",
"-Dclippy::complexity",
"-Aclippy::zero-prefixed-literal", # 00_1000_000
"-Aclippy::type_complexity", # raison d'etre
"-Aclippy::nonminimal-bool", # maybe
"-Aclippy::borrowed-box", # Reasonable to fix this one
"-Aclippy::too-many-arguments", # (Turning this on would lead to)
"-Aclippy::unnecessary_cast", # Types may change
"-Aclippy::identity-op", # One case where we do 0 +
"-Aclippy::useless_conversion", # Types may change
"-Aclippy::unit_arg", # styalistic.
"-Aclippy::option-map-unit-fn", # styalistic
"-Aclippy::bind_instead_of_map", # styalistic
"-Aclippy::erasing_op", # E.g. 0 * DOLLARS
"-Aclippy::eq_op", # In tests we test equality.
"-Aclippy::while_immutable_condition", # false positives
"-Aclippy::needless_option_as_deref", # false positives
"-Aclippy::derivable_impls", # false positives
"-Aclippy::stable_sort_primitive", # prefer stable sort
]
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ polkadot.*
!polkadot.service
!.rpm/*
.DS_Store
.cargo
.env
12 changes: 6 additions & 6 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,27 +591,27 @@ pub fn run() -> Result<()> {

#[cfg(feature = "kusama-native")]
if chain_spec.is_kusama() {
return Ok(runner.sync_run(|config| {
return runner.sync_run(|config| {
cmd.run::<service::kusama_runtime::Block, service::KusamaExecutorDispatch>(config)
.map_err(|e| Error::SubstrateCli(e))
})?)
})
}

#[cfg(feature = "westend-native")]
if chain_spec.is_westend() {
return Ok(runner.sync_run(|config| {
return runner.sync_run(|config| {
cmd.run::<service::westend_runtime::Block, service::WestendExecutorDispatch>(config)
.map_err(|e| Error::SubstrateCli(e))
})?)
})
}

// else we assume it is polkadot.
#[cfg(feature = "polkadot-native")]
{
return Ok(runner.sync_run(|config| {
return runner.sync_run(|config| {
cmd.run::<service::polkadot_runtime::Block, service::PolkadotExecutorDispatch>(config)
.map_err(|e| Error::SubstrateCli(e))
})?)
})
}

#[cfg(not(feature = "polkadot-native"))]
Expand Down
2 changes: 1 addition & 1 deletion erasure-coding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub struct Branches<'a, I> {
impl<'a, I: AsRef<[u8]>> Branches<'a, I> {
/// Get the trie root.
pub fn root(&self) -> H256 {
self.root.clone()
self.root
}
}

Expand Down
8 changes: 4 additions & 4 deletions node/client/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl BenchmarkCallSigner<polkadot_runtime::RuntimeCall, sp_core::sr25519::Pair>
(),
runtime::VERSION.spec_version,
runtime::VERSION.transaction_version,
genesis.clone(),
genesis,
genesis,
(),
(),
Expand Down Expand Up @@ -220,7 +220,7 @@ impl BenchmarkCallSigner<westend_runtime::RuntimeCall, sp_core::sr25519::Pair>
(),
runtime::VERSION.spec_version,
runtime::VERSION.transaction_version,
genesis.clone(),
genesis,
genesis,
(),
(),
Expand Down Expand Up @@ -274,7 +274,7 @@ impl BenchmarkCallSigner<kusama_runtime::RuntimeCall, sp_core::sr25519::Pair>
(),
runtime::VERSION.spec_version,
runtime::VERSION.transaction_version,
genesis.clone(),
genesis,
genesis,
(),
(),
Expand Down Expand Up @@ -328,7 +328,7 @@ impl BenchmarkCallSigner<rococo_runtime::RuntimeCall, sp_core::sr25519::Pair>
(),
runtime::VERSION.spec_version,
runtime::VERSION.transaction_version,
genesis.clone(),
genesis,
genesis,
(),
(),
Expand Down
4 changes: 2 additions & 2 deletions node/core/approval-voting/src/approval_checking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ impl State {

/// Constructs an infinite iterator from an array of `TrancheEntry` values. Any missing tranches
/// are filled with empty assignments, as they are needed to compute the approved tranches.
fn filled_tranche_iterator<'a>(
tranches: &'a [TrancheEntry],
fn filled_tranche_iterator(
tranches: &[TrancheEntry],
) -> impl Iterator<Item = (DelayTranche, &[(ValidatorIndex, Tick)])> {
let mut gap_end = None;

Expand Down
8 changes: 4 additions & 4 deletions node/core/approval-voting/src/criteria.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ impl<'a> From<&'a SessionInfo> for Config {
Config {
assignment_keys: s.assignment_keys.clone(),
validator_groups: s.validator_groups.clone(),
n_cores: s.n_cores.clone(),
zeroth_delay_tranche_width: s.zeroth_delay_tranche_width.clone(),
relay_vrf_modulo_samples: s.relay_vrf_modulo_samples.clone(),
n_delay_tranches: s.n_delay_tranches.clone(),
n_cores: s.n_cores,
zeroth_delay_tranche_width: s.zeroth_delay_tranche_width,
relay_vrf_modulo_samples: s.relay_vrf_modulo_samples,
n_delay_tranches: s.n_delay_tranches,
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions node/core/approval-voting/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,8 @@ pub(crate) async fn handle_new_head<Context, B: Backend>(
Err(error) => {
// It's possible that we've lost a race with finality.
let (tx, rx) = oneshot::channel();
ctx.send_message(ChainApiMessage::FinalizedBlockHash(
block_header.number.clone(),
tx,
))
.await;
ctx.send_message(ChainApiMessage::FinalizedBlockHash(block_header.number, tx))
.await;

let lost_to_finality = match rx.await {
Ok(Ok(Some(h))) if h != block_hash => true,
Expand Down
11 changes: 4 additions & 7 deletions node/core/approval-voting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,10 +621,7 @@ impl CurrentlyCheckingSet {
.candidate_hash_map
.remove(&approval_state.candidate_hash)
.unwrap_or_default();
approvals_cache.put(
approval_state.candidate_hash.clone(),
approval_state.approval_outcome.clone(),
);
approvals_cache.put(approval_state.candidate_hash, approval_state.approval_outcome);
return (out, approval_state)
}
}
Expand Down Expand Up @@ -768,7 +765,7 @@ async fn run<B, Context>(
where
B: Backend,
{
if let Err(err) = db_sanity_check(subsystem.db.clone(), subsystem.db_config.clone()) {
if let Err(err) = db_sanity_check(subsystem.db.clone(), subsystem.db_config) {
gum::warn!(target: LOG_TARGET, ?err, "Could not run approval vote DB sanity check");
}

Expand Down Expand Up @@ -1278,7 +1275,7 @@ async fn get_approval_signatures_for_candidate<Context>(
Some(e) => e,
};

let relay_hashes = entry.block_assignments.iter().map(|(relay_hash, _)| relay_hash);
let relay_hashes = entry.block_assignments.keys();

let mut candidate_indices = HashSet::new();
// Retrieve `CoreIndices`/`CandidateIndices` as required by approval-distribution:
Expand Down Expand Up @@ -2502,7 +2499,7 @@ async fn issue_approval<Context>(
};

let candidate_hash = match block_entry.candidate(candidate_index as usize) {
Some((_, h)) => h.clone(),
Some((_, h)) => *h,
None => {
gum::warn!(
target: LOG_TARGET,
Expand Down
2 changes: 1 addition & 1 deletion node/core/av-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const PRUNE_BY_TIME_PREFIX: &[u8; 13] = b"prune_by_time";

// We have some keys we want to map to empty values because existence of the key is enough. We use this because
// rocksdb doesn't support empty values.
const TOMBSTONE_VALUE: &[u8] = &*b" ";
const TOMBSTONE_VALUE: &[u8] = b" ";

/// Unavailable blocks are kept for 1 hour.
const KEEP_UNAVAILABLE_FOR: Duration = Duration::from_secs(60 * 60);
Expand Down
6 changes: 2 additions & 4 deletions node/core/backing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,7 @@ impl TableContextTrait for TableContext {
}

fn is_member_of(&self, authority: &ValidatorIndex, group: &ParaId) -> bool {
self.groups
.get(group)
.map_or(false, |g| g.iter().position(|a| a == authority).is_some())
self.groups.get(group).map_or(false, |g| g.iter().any(|a| a == authority))
}

fn requisite_votes(&self, group: &ParaId) -> usize {
Expand All @@ -499,7 +497,7 @@ struct InvalidErasureRoot;
fn primitive_statement_to_table(s: &SignedFullStatement) -> TableSignedStatement {
let statement = match s.payload() {
Statement::Seconded(c) => TableStatement::Seconded(c.clone()),
Statement::Valid(h) => TableStatement::Valid(h.clone()),
Statement::Valid(h) => TableStatement::Valid(*h),
};

TableSignedStatement {
Expand Down
4 changes: 2 additions & 2 deletions node/core/candidate-validation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ async fn validate_candidate_exhaustive(
let _timer = metrics.time_validate_candidate_exhaustive();

let validation_code_hash = validation_code.hash();
let para_id = candidate_receipt.descriptor.para_id.clone();
let para_id = candidate_receipt.descriptor.para_id;
gum::debug!(
target: LOG_TARGET,
?validation_code_hash,
Expand All @@ -513,7 +513,7 @@ async fn validate_candidate_exhaustive(
if let Err(e) = perform_basic_checks(
&candidate_receipt.descriptor,
persisted_validation_data.max_pov_size,
&*pov,
&pov,
&validation_code_hash,
) {
gum::info!(target: LOG_TARGET, ?para_id, "Invalid candidate (basic checks)");
Expand Down
1 change: 1 addition & 0 deletions node/core/chain-selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ async fn run<Context, B>(
) where
B: Backend,
{
#![allow(clippy::all)]
loop {
let res = run_until_error(
&mut ctx,
Expand Down
2 changes: 1 addition & 1 deletion node/core/dispute-coordinator/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl CandidateVoteState<CandidateVotes> {
}

/// Create a new `CandidateVoteState` from already existing votes.
pub fn new<'a>(votes: CandidateVotes, env: &CandidateEnvironment<'a>, now: Timestamp) -> Self {
pub fn new(votes: CandidateVotes, env: &CandidateEnvironment, now: Timestamp) -> Self {
let own_vote = OwnVoteState::new(&votes, env);

let n_validators = env.validators().len();
Expand Down
60 changes: 32 additions & 28 deletions node/core/dispute-coordinator/src/initialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,20 +713,22 @@ impl Initialized {
return Ok(ImportStatementsResult::InvalidImport)
}

let env =
match CandidateEnvironment::new(&*self.keystore, &self.rolling_session_window, session)
{
None => {
gum::warn!(
target: LOG_TARGET,
session,
"We are lacking a `SessionInfo` for handling import of statements."
);
let env = match CandidateEnvironment::new(
&self.keystore,
&self.rolling_session_window,
session,
) {
None => {
gum::warn!(
target: LOG_TARGET,
session,
"We are lacking a `SessionInfo` for handling import of statements."
);

return Ok(ImportStatementsResult::InvalidImport)
},
Some(env) => env,
};
return Ok(ImportStatementsResult::InvalidImport)
},
Some(env) => env,
};

let candidate_hash = candidate_receipt.hash();

Expand Down Expand Up @@ -1075,20 +1077,22 @@ impl Initialized {
"Issuing local statement for candidate!"
);
// Load environment:
let env =
match CandidateEnvironment::new(&*self.keystore, &self.rolling_session_window, session)
{
None => {
gum::warn!(
target: LOG_TARGET,
session,
"Missing info for session which has an active dispute",
);
let env = match CandidateEnvironment::new(
&self.keystore,
&self.rolling_session_window,
session,
) {
None => {
gum::warn!(
target: LOG_TARGET,
session,
"Missing info for session which has an active dispute",
);

return Ok(())
},
Some(env) => env,
};
return Ok(())
},
Some(env) => env,
};

let votes = overlay_db
.load_candidate_votes(session, &candidate_hash)?
Expand Down Expand Up @@ -1257,7 +1261,7 @@ fn make_dispute_message(
votes.invalid.iter().next().ok_or(DisputeMessageCreationError::NoOppositeVote)?;
let other_vote = SignedDisputeStatement::new_checked(
DisputeStatement::Invalid(*statement_kind),
our_vote.candidate_hash().clone(),
*our_vote.candidate_hash(),
our_vote.session_index(),
validators
.get(*validator_index)
Expand All @@ -1272,7 +1276,7 @@ fn make_dispute_message(
votes.valid.iter().next().ok_or(DisputeMessageCreationError::NoOppositeVote)?;
let other_vote = SignedDisputeStatement::new_checked(
DisputeStatement::Valid(*statement_kind),
our_vote.candidate_hash().clone(),
*our_vote.candidate_hash(),
our_vote.session_index(),
validators
.get(*validator_index)
Expand Down
2 changes: 1 addition & 1 deletion node/core/dispute-coordinator/src/participation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl Participation {
req: ParticipationRequest,
recent_head: Hash,
) -> FatalResult<()> {
if self.running_participations.insert(req.candidate_hash().clone()) {
if self.running_participations.insert(*req.candidate_hash()) {
let sender = ctx.sender().clone();
ctx.spawn(
"participation-worker",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl Queues {
// Once https://github.com/rust-lang/rust/issues/62924 is there, we can use a simple:
// target.pop_first().
if let Some((comparator, _)) = target.iter().next() {
let comparator = comparator.clone();
let comparator = *comparator;
target
.remove(&comparator)
.map(|participation_request| (comparator, participation_request))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ where
);

// Fetch the onchain disputes. We'll do a prioritization based on them.
let onchain = match get_onchain_disputes(sender, leaf.hash.clone()).await {
let onchain = match get_onchain_disputes(sender, leaf.hash).await {
Ok(r) => r,
Err(GetOnchainDisputesError::NotSupported(runtime_api_err, relay_parent)) => {
// Runtime version is checked before calling this method, so the error below should never happen!
Expand Down
4 changes: 2 additions & 2 deletions node/core/provisioner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ async fn send_inherent_data(

let disputes = match has_required_runtime(
from_job,
leaf.hash.clone(),
leaf.hash,
PRIORITIZED_SELECTION_RUNTIME_VERSION_REQUIREMENT,
)
.await
Expand Down Expand Up @@ -506,7 +506,7 @@ fn select_availability_bitfields(
bitfields.len()
);

selected.into_iter().map(|(_, b)| b).collect()
selected.into_values().collect()
}

/// Determine which cores are free, and then to the degree possible, pick a candidate appropriate to each free core.
Expand Down
Loading

0 comments on commit 71a0fad

Please sign in to comment.