Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
Fix `clippy::derivable_impls` and `clippy::needless_borrow`. The warning
`clippy::derive_hash_xor_eq` is not a thing anymore.
  • Loading branch information
hrxi committed Mar 10, 2023
1 parent 0f27b59 commit f7b956c
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 35 deletions.
2 changes: 1 addition & 1 deletion bls/src/types/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl Signature {
/// validator's signature by its number of slots.
#[must_use]
pub fn multiply(&self, x: u16) -> Self {
let signature = self.signature.mul(&[x as u64]);
let signature = self.signature.mul([x as u64]);
Signature {
signature,
compressed: CompressedSignature::from(signature),
Expand Down
1 change: 0 additions & 1 deletion keys/src/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ impl SerializeContent for PublicKey {

impl Hash for PublicKey {}

#[allow(clippy::derive_hash_xor_eq)]
impl std::hash::Hash for PublicKey {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
std::hash::Hash::hash(self.as_bytes(), state);
Expand Down
17 changes: 4 additions & 13 deletions lib/src/config/config_file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,22 +169,18 @@ pub struct ConsensusSettings {
pub min_peers: Option<usize>,
}

#[derive(Deserialize, Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Clone, Copy, Deserialize, Debug, Default, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
/// Synchronization mode used by the client based upon its client type
pub enum SyncMode {
#[default]
/// Synchronization mode used by History nodes (full transaction history is maintained)
History,
/// Full Nodes. They use LightMacroSync + State Sync to reach consensus
Full,
/// Light nodes use LightMacroSync + BlockLiveSync to reach consensus
Light,
}
impl Default for SyncMode {
fn default() -> Self {
SyncMode::History
}
}

#[derive(Debug, Error)]
#[error("Invalid sync mode: {0}")]
Expand Down Expand Up @@ -213,24 +209,19 @@ impl From<SyncMode> for config::SyncMode {
}
}

#[derive(Deserialize, Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq)]
#[serde(rename_all = "kebab-case")]
// TODO: I think we can directly use `NetworkId` here
pub enum Network {
Main,
Test,
Dev,
TestAlbatross,
#[default]
DevAlbatross,
UnitAlbatross,
}

impl Default for Network {
fn default() -> Self {
Network::DevAlbatross
}
}

impl FromStr for Network {
type Err = ();

Expand Down
1 change: 0 additions & 1 deletion primitives/account/src/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ impl SerializeContent for Receipt {
}
}

#[allow(clippy::derive_hash_xor_eq)] // TODO: Shouldn't be necessary
impl Hash for Receipt {
fn hash<H: HashOutput>(&self) -> H {
let h = H::Builder::default();
Expand Down
2 changes: 0 additions & 2 deletions primitives/block/src/macro_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ impl Message for MacroHeader {
const PREFIX: u8 = PREFIX_TENDERMINT_PROPOSAL;
}

#[allow(clippy::derive_hash_xor_eq)] // TODO: Shouldn't be necessary
impl Hash for MacroHeader {}

impl fmt::Display for MacroHeader {
Expand Down Expand Up @@ -278,7 +277,6 @@ impl MacroBody {
}
}

#[allow(clippy::derive_hash_xor_eq)] // TODO: Shouldn't be necessary
impl Hash for MacroBody {}

#[derive(Error, Debug)]
Expand Down
9 changes: 2 additions & 7 deletions primitives/subscription/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use nimiq_keys::Address;
use nimiq_primitives::coin::Coin;
use nimiq_transaction::Transaction;

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[repr(u8)]
pub enum Subscription {
#[beserial(discriminant = 0)]
#[default]
None,
#[beserial(discriminant = 1)]
Any,
Expand All @@ -18,12 +19,6 @@ pub enum Subscription {
MinFee(Coin), // Fee per byte
}

impl Default for Subscription {
fn default() -> Self {
Subscription::None
}
}

impl Subscription {
pub fn matches_block(&self) -> bool {
!matches!(self, Subscription::None)
Expand Down
15 changes: 6 additions & 9 deletions primitives/transaction/src/account/htlc_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,18 @@ impl AccountTransactionVerification for HashedTimeLockedContractVerifier {
}
}

#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Serialize, Deserialize, Display)]
#[derive(
Clone, Copy, Debug, Default, Deserialize, Display, Eq, Ord, PartialEq, PartialOrd, Serialize,
)]
#[repr(u8)]
#[cfg_attr(feature = "serde-derive", derive(serde::Serialize, serde::Deserialize))]
pub enum HashAlgorithm {
#[default]
Blake2b = 1,
Sha256 = 3,
}

impl Default for HashAlgorithm {
fn default() -> Self {
HashAlgorithm::Blake2b
}
}

#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
#[repr(u8)]
pub enum ProofType {
RegularTransfer = 1,
Expand All @@ -192,7 +189,7 @@ impl AnyHash {
}
}

#[derive(Default, Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(feature = "serde-derive", derive(serde::Serialize, serde::Deserialize))]
pub struct CreationTransactionData {
pub sender: Address,
Expand Down
2 changes: 1 addition & 1 deletion spammer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ async fn spam(
SpamType::Vesting,
];

let dist = WeightedIndex::new(&config.weights).unwrap();
let dist = WeightedIndex::new(config.weights).unwrap();
let mut rng = thread_rng();
let new_count;

Expand Down

0 comments on commit f7b956c

Please sign in to comment.