Skip to content

Commit 20183c1

Browse files
*: Fix clippy warnings (libp2p#2139)
* Fix needless question mark operator * Don't convert from u64 to u64 LocalStreamId is already a u64, no need to convert. * Don't use `.into()` to convert to the same type * Don't specify lifetime if it can be inferred * Use `vec!` macro if we immediately push to it This creates the vector with the appropriate capacity. * Don't index array when taking a reference is enough Co-authored-by: Max Inden <[email protected]>
1 parent e1646a5 commit 20183c1

File tree

8 files changed

+15
-16
lines changed

8 files changed

+15
-16
lines changed

core/src/peer_id.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ impl PeerId {
6868

6969
/// Parses a `PeerId` from bytes.
7070
pub fn from_bytes(data: &[u8]) -> Result<PeerId, Error> {
71-
Ok(PeerId::from_multihash(Multihash::from_bytes(&data)?)
72-
.map_err(|mh| Error::UnsupportedCode(mh.code()))?)
71+
PeerId::from_multihash(Multihash::from_bytes(&data)?)
72+
.map_err(|mh| Error::UnsupportedCode(mh.code()))
7373
}
7474

7575
/// Tries to turn a `Multihash` into a `PeerId`.

muxers/mplex/src/codec.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,25 +244,25 @@ impl Encoder for Codec {
244244
fn encode(&mut self, item: Self::Item, dst: &mut BytesMut) -> Result<(), Self::Error> {
245245
let (header, data) = match item {
246246
Frame::Open { stream_id } => {
247-
(u64::from(stream_id.num) << 3, Bytes::new())
247+
(stream_id.num << 3, Bytes::new())
248248
},
249249
Frame::Data { stream_id: LocalStreamId { num, role: Endpoint::Listener }, data } => {
250-
(u64::from(num) << 3 | 1, data)
250+
(num << 3 | 1, data)
251251
},
252252
Frame::Data { stream_id: LocalStreamId { num, role: Endpoint::Dialer }, data } => {
253-
(u64::from(num) << 3 | 2, data)
253+
(num << 3 | 2, data)
254254
},
255255
Frame::Close { stream_id: LocalStreamId { num, role: Endpoint::Listener } } => {
256-
(u64::from(num) << 3 | 3, Bytes::new())
256+
(num << 3 | 3, Bytes::new())
257257
},
258258
Frame::Close { stream_id: LocalStreamId { num, role: Endpoint::Dialer } } => {
259-
(u64::from(num) << 3 | 4, Bytes::new())
259+
(num << 3 | 4, Bytes::new())
260260
},
261261
Frame::Reset { stream_id: LocalStreamId { num, role: Endpoint::Listener } } => {
262-
(u64::from(num) << 3 | 5, Bytes::new())
262+
(num << 3 | 5, Bytes::new())
263263
},
264264
Frame::Reset { stream_id: LocalStreamId { num, role: Endpoint::Dialer } } => {
265-
(u64::from(num) << 3 | 6, Bytes::new())
265+
(num << 3 | 6, Bytes::new())
266266
},
267267
};
268268

protocols/identify/src/handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl ProtocolsHandler for IdentifyHandler {
211211
};
212212
Poll::Ready(ev)
213213
}
214-
Poll::Ready(Err(err)) => Poll::Ready(ProtocolsHandlerEvent::Close(err.into()))
214+
Poll::Ready(Err(err)) => Poll::Ready(ProtocolsHandlerEvent::Close(err))
215215
}
216216
}
217217
}

protocols/identify/src/protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ where
207207
Ok(v) => v,
208208
Err(err) => {
209209
debug!("Invalid message: {:?}", err);
210-
return Err(err.into())
210+
return Err(err)
211211
}
212212
};
213213

protocols/kad/src/kbucket.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ where
186186
///
187187
/// The buckets are ordered by proximity to the `local_key`, i.e. the first
188188
/// bucket is the closest bucket (containing at most one key).
189-
pub fn iter<'a>(&'a mut self) -> impl Iterator<Item = KBucketRef<'a, TKey, TVal>> + 'a {
189+
pub fn iter(&mut self) -> impl Iterator<Item = KBucketRef<'_, TKey, TVal>> + '_ {
190190
let applied_pending = &mut self.applied_pending;
191191
self.buckets.iter_mut().enumerate().map(move |(i, b)| {
192192
if let Some(applied) = b.apply_pending() {

protocols/mdns/src/dns.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,7 @@ fn append_txt_record(
371371
if value.len() > MAX_TXT_VALUE_LENGTH {
372372
return Err(MdnsResponseError::TxtRecordTooLong);
373373
}
374-
let mut buffer = Vec::new();
375-
buffer.push(value.len() as u8);
374+
let mut buffer = vec![value.len() as u8];
376375
append_character_string(&mut buffer, value)?;
377376

378377
append_u16(out, buffer.len() as u16);

transports/noise/src/protocol/x25519.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl snow::types::Dh for Keypair<X25519> {
235235

236236
fn set(&mut self, sk: &[u8]) {
237237
let mut secret = [0u8; 32];
238-
secret.copy_from_slice(&sk[..]);
238+
secret.copy_from_slice(&sk);
239239
self.secret = SecretKey(X25519(secret)); // Copy
240240
self.public = PublicKey(X25519(x25519(secret, X25519_BASEPOINT_BYTES)));
241241
secret.zeroize();

transports/noise/src/protocol/x25519_spec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl snow::types::Dh for Keypair<X25519Spec> {
146146

147147
fn set(&mut self, sk: &[u8]) {
148148
let mut secret = [0u8; 32];
149-
secret.copy_from_slice(&sk[..]);
149+
secret.copy_from_slice(&sk);
150150
self.secret = SecretKey(X25519Spec(secret)); // Copy
151151
self.public = PublicKey(X25519Spec(x25519(secret, X25519_BASEPOINT_BYTES)));
152152
secret.zeroize();

0 commit comments

Comments
 (0)