chore: Implement latest clippy warnings (#3220)

As I do frequently, I corrected for the latest clippy warnings. This will make sure the CI won't complain in the future. We could automate this btw and maybe run the nightly version of clippy.
This commit is contained in:
Hannes
2022-12-14 16:45:04 +01:00
committed by GitHub
parent be3ec6c62b
commit d79c93abdb
72 changed files with 244 additions and 307 deletions

View File

@ -218,7 +218,7 @@ impl fmt::Debug for PublicKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("PublicKey(asn.1 uncompressed): ")?;
for byte in &self.encode_der() {
write!(f, "{:x}", byte)?;
write!(f, "{byte:x}")?;
}
Ok(())
}

View File

@ -122,7 +122,7 @@ impl fmt::Debug for PublicKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("PublicKey(compressed): ")?;
for byte in self.0.as_bytes() {
write!(f, "{:x}", byte)?;
write!(f, "{byte:x}")?;
}
Ok(())
}

View File

@ -120,7 +120,7 @@ impl fmt::Debug for PublicKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("PublicKey(PKCS1): ")?;
for byte in &self.0 {
write!(f, "{:x}", byte)?;
write!(f, "{byte:x}")?;
}
Ok(())
}

View File

@ -158,7 +158,7 @@ impl fmt::Debug for PublicKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("PublicKey(compressed): ")?;
for byte in &self.encode() {
write!(f, "{:x}", byte)?;
write!(f, "{byte:x}")?;
}
Ok(())
}

View File

@ -168,8 +168,7 @@ impl fmt::Display for ReadPayloadError {
Self::InvalidSignature => write!(f, "Invalid signature"),
Self::UnexpectedPayloadType { expected, got } => write!(
f,
"Unexpected payload type, expected {:?} but got {:?}",
expected, got
"Unexpected payload type, expected {expected:?} but got {got:?}"
),
}
}

View File

@ -541,7 +541,7 @@ where
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TransportError::MultiaddrNotSupported(addr) => {
write!(f, "Multiaddr is not supported: {}", addr)
write!(f, "Multiaddr is not supported: {addr}")
}
TransportError::Other(_) => Ok(()),
}

View File

@ -500,7 +500,7 @@ mod tests {
#[test]
fn stop_listening() {
let rand_port = rand::random::<u64>().saturating_add(1);
let addr: Multiaddr = format!("/memory/{}", rand_port).parse().unwrap();
let addr: Multiaddr = format!("/memory/{rand_port}").parse().unwrap();
let mut transport = MemoryTransport::default().boxed();
futures::executor::block_on(async {
@ -520,7 +520,7 @@ mod tests {
assert_eq!(id, listener_id);
assert!(reason.is_ok())
}
other => panic!("Unexpected transport event: {:?}", other),
other => panic!("Unexpected transport event: {other:?}"),
}
assert!(!transport.remove_listener(listener_id));
})
@ -533,7 +533,7 @@ mod tests {
// Setup listener.
let rand_port = rand::random::<u64>().saturating_add(1);
let t1_addr: Multiaddr = format!("/memory/{}", rand_port).parse().unwrap();
let t1_addr: Multiaddr = format!("/memory/{rand_port}").parse().unwrap();
let cloned_t1_addr = t1_addr.clone();
let mut t1 = MemoryTransport::default().boxed();

View File

@ -198,8 +198,8 @@ where
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TransportTimeoutError::Timeout => write!(f, "Timeout has been reached"),
TransportTimeoutError::TimerError(err) => write!(f, "Error in the timer: {}", err),
TransportTimeoutError::Other(err) => write!(f, "{}", err),
TransportTimeoutError::TimerError(err) => write!(f, "Error in the timer: {err}"),
TransportTimeoutError::Other(err) => write!(f, "{err}"),
}
}
}

View File

@ -471,8 +471,8 @@ where
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TransportUpgradeError::Transport(e) => write!(f, "Transport error: {}", e),
TransportUpgradeError::Upgrade(e) => write!(f, "Upgrade error: {}", e),
TransportUpgradeError::Transport(e) => write!(f, "Transport error: {e}"),
TransportUpgradeError::Upgrade(e) => write!(f, "Upgrade error: {e}"),
}
}
}

View File

@ -113,10 +113,7 @@ pub async fn read_length_prefixed(
if len > max_size {
return Err(io::Error::new(
io::ErrorKind::InvalidData,
format!(
"Received data size ({} bytes) exceeds maximum ({} bytes)",
len, max_size
),
format!("Received data size ({len} bytes) exceeds maximum ({max_size} bytes)"),
));
}