Fixed nightly clippy warnings (#572)

* Fixed nightly clippy warnings

* Using string literal in panic message
This commit is contained in:
Jędrzej Stuczyński
2021-04-14 16:41:47 +01:00
committed by GitHub
parent dca9c7079c
commit 4e339f1788
11 changed files with 20 additions and 22 deletions
@@ -165,7 +165,7 @@ impl ReceivedMessagesBuffer {
// while we're at it, also empty the buffer if we happened to receive anything while
// no sender was connected
let stored_messages = std::mem::replace(&mut guard.messages, Vec::new());
let stored_messages = std::mem::take(&mut guard.messages);
if !stored_messages.is_empty() {
if let Err(err) = sender.unbounded_send(stored_messages) {
error!(
@@ -15,6 +15,8 @@
// all variable size data is always prefixed with u64 length
// tags are u8
#![allow(unknown_lints)] // due to using `clippy::branches_sharing_code` which does not exist on `stable` just yet
use crate::error::{self, ErrorKind};
use crate::text::ServerResponseText;
use nymsphinx::addressing::clients::Recipient;
@@ -96,6 +98,8 @@ impl ServerResponse {
}
};
// this is a false positive as even though the code is the same, it refers to different things
#[allow(clippy::branches_sharing_code)]
if with_reply_surb {
let reply_surb_len =
u64::from_be_bytes(b[2..2 + size_of::<u64>()].as_ref().try_into().unwrap());
+1 -1
View File
@@ -246,7 +246,7 @@ impl NymClient {
let validator_client = validator_client::Client::new(validator_client_config);
match validator_client.get_active_topology().await {
Err(err) => panic!(err),
Err(err) => panic!("{}", err),
Ok(topology) => {
let nym_topology: NymTopology = topology.into();
let version = env!("CARGO_PKG_VERSION");
@@ -107,7 +107,7 @@ impl PemStorableKeyPair for KeyPair {
pub struct PublicKey(x25519_dalek::PublicKey);
impl PublicKey {
pub fn to_bytes(&self) -> [u8; PUBLIC_KEY_SIZE] {
pub fn to_bytes(self) -> [u8; PUBLIC_KEY_SIZE] {
*self.0.as_bytes()
}
@@ -120,8 +120,8 @@ impl PublicKey {
Ok(Self(x25519_dalek::PublicKey::from(bytes)))
}
pub fn to_base58_string(&self) -> String {
bs58::encode(&self.to_bytes()).into_string()
pub fn to_base58_string(self) -> String {
bs58::encode(self.to_bytes()).into_string()
}
pub fn from_base58_string<S: Into<String>>(val: S) -> Result<Self, KeyRecoveryError> {
@@ -138,7 +138,7 @@ impl PemStorableKey for PublicKey {
}
fn to_bytes(&self) -> Vec<u8> {
self.to_bytes().to_vec()
(*self).to_bytes().to_vec()
}
fn from_bytes(bytes: &[u8]) -> Result<Self, Self::Error> {
@@ -209,7 +209,7 @@ impl From<PublicKey> for nymsphinx_types::PublicKey {
impl<'a> From<&'a PublicKey> for nymsphinx_types::PublicKey {
fn from(key: &'a PublicKey) -> Self {
nymsphinx_types::PublicKey::from(key.to_bytes())
nymsphinx_types::PublicKey::from((*key).to_bytes())
}
}
+4 -4
View File
@@ -116,7 +116,7 @@ impl PublicKey {
}
/// Convert this public key to a byte array.
pub fn to_bytes(&self) -> [u8; PUBLIC_KEY_LENGTH] {
pub fn to_bytes(self) -> [u8; PUBLIC_KEY_LENGTH] {
self.0.to_bytes()
}
@@ -124,8 +124,8 @@ impl PublicKey {
Ok(PublicKey(ed25519_dalek::PublicKey::from_bytes(b)?))
}
pub fn to_base58_string(&self) -> String {
bs58::encode(&self.to_bytes()).into_string()
pub fn to_base58_string(self) -> String {
bs58::encode(self.to_bytes()).into_string()
}
pub fn from_base58_string<S: Into<String>>(val: S) -> Result<Self, KeyRecoveryError> {
@@ -146,7 +146,7 @@ impl PemStorableKey for PublicKey {
}
fn to_bytes(&self) -> Vec<u8> {
self.to_bytes().to_vec()
(*self).to_bytes().to_vec()
}
fn from_bytes(bytes: &[u8]) -> Result<Self, Self::Error> {
@@ -1,9 +1,6 @@
// Copyright 2020 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
#![allow(renamed_and_removed_lints)]
#![allow(unknown_lints)] // beta-nightly
#![allow(clippy::unknown_clippy_lints)] // `clippy::upper_case_acronyms` does not exist on stable just yet
use cipher::stream::{Nonce, StreamCipher, SyncStreamCipher};
use generic_array::{typenum::Unsigned, GenericArray};
use rand::{CryptoRng, RngCore};
+1 -1
View File
@@ -154,7 +154,7 @@ impl Recipient {
&self.gateway
}
pub fn to_bytes(&self) -> [u8; Self::LEN] {
pub fn to_bytes(self) -> [u8; Self::LEN] {
let mut out = [0u8; Self::LEN];
out[..CLIENT_IDENTITY_SIZE].copy_from_slice(&self.client_identity.to_bytes());
out[CLIENT_IDENTITY_SIZE..CLIENT_IDENTITY_SIZE + CLIENT_ENCRYPTION_KEY_SIZE]
@@ -48,7 +48,7 @@ impl EncryptedAddressBytes {
EncryptedAddressBytes(bytes)
}
pub fn to_bytes(&self) -> [u8; ENCRYPTED_ADDRESS_SIZE] {
pub fn to_bytes(self) -> [u8; ENCRYPTED_ADDRESS_SIZE] {
self.0
}
@@ -73,7 +73,7 @@ impl EncryptedAddressBytes {
Ok(EncryptedAddressBytes(enc_address))
}
pub fn to_base58_string(&self) -> String {
pub fn to_base58_string(self) -> String {
bs58::encode(self.0).into_string()
}
}
@@ -1,9 +1,6 @@
// Copyright 2020 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: Apache-2.0
#![allow(renamed_and_removed_lints)]
#![allow(unknown_lints)] // beta-nightly
#![allow(clippy::unknown_clippy_lints)] // `clippy::upper_case_acronyms` does not exist on stable just yet
use crypto::generic_array::{typenum::Unsigned, GenericArray};
use crypto::symmetric::stream_cipher::{random_iv, NewStreamCipher, IV};
use nymsphinx::params::GatewayEncryptionAlgorithm;
+1 -1
View File
@@ -59,7 +59,7 @@ impl MixMetrics {
let mut unlocked = self.inner.sent.lock().await;
let received = self.inner.received.swap(0, Ordering::SeqCst);
let sent = std::mem::replace(unlocked.deref_mut(), HashMap::new());
let sent = std::mem::take(unlocked.deref_mut());
(received, sent)
}
+1 -1
View File
@@ -121,7 +121,7 @@ impl TestPacket {
self.pub_key.to_base58_string()
}
pub(crate) fn to_bytes(&self) -> Vec<u8> {
pub(crate) fn to_bytes(self) -> Vec<u8> {
self.nonce
.to_be_bytes()
.iter()