Skip to content

Commit 9c712d3

Browse files
authored
chore: address clippy lints for cargo 1.87.0-beta / clippy 0.1.87
Pull-Request: libp2p#5974.
1 parent 1206fef commit 9c712d3

File tree

38 files changed

+71
-122
lines changed

38 files changed

+71
-122
lines changed

core/src/muxing/boxed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn into_io_error<E>(err: E) -> io::Error
8585
where
8686
E: Error + Send + Sync + 'static,
8787
{
88-
io::Error::new(io::ErrorKind::Other, err)
88+
io::Error::other(err)
8989
}
9090

9191
impl StreamMuxerBox {

core/src/transport/boxed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,5 +171,5 @@ impl<O> FusedStream for Boxed<O> {
171171
}
172172

173173
fn box_err<E: Error + Send + Sync + 'static>(e: E) -> io::Error {
174-
io::Error::new(io::ErrorKind::Other, e)
174+
io::Error::other(e)
175175
}

examples/browser-webrtc/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,5 @@ impl Body {
104104
}
105105

106106
fn js_error(msg: &str) -> JsError {
107-
io::Error::new(io::ErrorKind::Other, msg).into()
107+
io::Error::other(msg).into()
108108
}

examples/chat/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
7272
// signing)
7373
.message_id_fn(message_id_fn) // content-address messages. No two messages of the same content will be propagated.
7474
.build()
75-
.map_err(|msg| io::Error::new(io::ErrorKind::Other, msg))?; // Temporary hack because `build` does not return a proper `std::error::Error`.
75+
.map_err(io::Error::other)?; // Temporary hack because `build` does not return a proper `std::error::Error`.
7676

7777
// build a gossipsub network behaviour
7878
let gossipsub = gossipsub::Behaviour::new(

examples/ipfs-private/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
138138
let gossipsub_config = gossipsub::ConfigBuilder::default()
139139
.max_transmit_size(262144)
140140
.build()
141-
.map_err(|msg| io::Error::new(io::ErrorKind::Other, msg))?; // Temporary hack because `build` does not return a proper `std::error::Error`.
141+
.map_err(io::Error::other)?; // Temporary hack because `build` does not return a proper `std::error::Error`.
142142
Ok(MyBehaviour {
143143
gossipsub: gossipsub::Behaviour::new(
144144
gossipsub::MessageAuthenticity::Signed(key.clone()),

examples/stream/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ async fn send(mut stream: Stream) -> io::Result<()> {
148148
stream.read_exact(&mut buf).await?;
149149

150150
if bytes != buf {
151-
return Err(io::Error::new(io::ErrorKind::Other, "incorrect echo"));
151+
return Err(io::Error::other("incorrect echo"));
152152
}
153153

154154
stream.close().await?;

hole-punching-tests/src/main.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,7 @@ impl FromStr for TransportProtocol {
333333
match mode {
334334
"tcp" => Ok(TransportProtocol::Tcp),
335335
"quic" => Ok(TransportProtocol::Quic),
336-
_ => Err(io::Error::new(
337-
io::ErrorKind::Other,
338-
"Expected either 'tcp' or 'quic'",
339-
)),
336+
_ => Err(io::Error::other("Expected either 'tcp' or 'quic'")),
340337
}
341338
}
342339
}
@@ -353,10 +350,7 @@ impl FromStr for Mode {
353350
match mode {
354351
"dial" => Ok(Mode::Dial),
355352
"listen" => Ok(Mode::Listen),
356-
_ => Err(io::Error::new(
357-
io::ErrorKind::Other,
358-
"Expected either 'dial' or 'listen'",
359-
)),
353+
_ => Err(io::Error::other("Expected either 'dial' or 'listen'")),
360354
}
361355
}
362356
}

misc/connection-limits/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,7 @@ mod tests {
692692
_local_addr: &Multiaddr,
693693
_remote_addr: &Multiaddr,
694694
) -> Result<THandler<Self>, ConnectionDenied> {
695-
Err(ConnectionDenied::new(std::io::Error::new(
696-
std::io::ErrorKind::Other,
695+
Err(ConnectionDenied::new(std::io::Error::other(
697696
"ConnectionDenier",
698697
)))
699698
}
@@ -706,8 +705,7 @@ mod tests {
706705
_role_override: Endpoint,
707706
_port_use: PortUse,
708707
) -> Result<THandler<Self>, ConnectionDenied> {
709-
Err(ConnectionDenied::new(std::io::Error::new(
710-
std::io::ErrorKind::Other,
708+
Err(ConnectionDenied::new(std::io::Error::other(
711709
"ConnectionDenier",
712710
)))
713711
}

misc/multistream-select/src/negotiated.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ impl From<NegotiationError> for io::Error {
368368
if let NegotiationError::ProtocolError(e) = err {
369369
return e.into();
370370
}
371-
io::Error::new(io::ErrorKind::Other, err)
371+
io::Error::other(err)
372372
}
373373
}
374374

misc/quick-protobuf-codec/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ fn write_length(message: &impl MessageWrite, dst: &mut BytesMut) {
5959
/// Write the message itself to `dst`.
6060
fn write_message(item: &impl MessageWrite, dst: &mut BytesMut) -> io::Result<()> {
6161
let mut writer = Writer::new(BytesMutWriterBackend::new(dst));
62-
item.write_message(&mut writer)
63-
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
62+
item.write_message(&mut writer).map_err(io::Error::other)?;
6463

6564
Ok(())
6665
}

misc/server/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
141141
..
142142
} = e
143143
{
144-
if protocols.iter().any(|p| *p == kad::PROTOCOL_NAME) {
144+
if protocols.contains(&kad::PROTOCOL_NAME) {
145145
for addr in listen_addrs {
146146
swarm
147147
.behaviour_mut()

misc/webrtc-utils/src/stream/state.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,7 @@ impl State {
264264
write_closed: false,
265265
..
266266
} => {
267-
return Err(io::Error::new(
268-
io::ErrorKind::Other,
267+
return Err(io::Error::other(
269268
"cannot close read half while closing write half",
270269
))
271270
}
@@ -308,8 +307,7 @@ impl State {
308307
State::ClosingWrite {
309308
read_closed: false, ..
310309
} => {
311-
return Err(io::Error::new(
312-
io::ErrorKind::Other,
310+
return Err(io::Error::other(
313311
"cannot close write half while closing read half",
314312
))
315313
}

muxers/mplex/src/io.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,7 @@ where
713713
substream=%id,
714714
"Received unexpected `Open` frame for open substream",
715715
);
716-
return self.on_error(io::Error::new(
717-
io::ErrorKind::Other,
716+
return self.on_error(io::Error::other(
718717
"Protocol error: Received `Open` frame for open substream.",
719718
));
720719
}
@@ -890,7 +889,7 @@ where
890889
/// i.e. is not closed and did not encounter a fatal error.
891890
fn guard_open(&self) -> io::Result<()> {
892891
match &self.status {
893-
Status::Closed => Err(io::Error::new(io::ErrorKind::Other, "Connection is closed")),
892+
Status::Closed => Err(io::Error::other("Connection is closed")),
894893
Status::Err(e) => Err(io::Error::new(e.kind(), e.to_string())),
895894
Status::Open => Ok(()),
896895
}
@@ -900,10 +899,7 @@ where
900899
/// has not been reached.
901900
fn check_max_pending_frames(&mut self) -> io::Result<()> {
902901
if self.pending_frames.len() >= self.config.max_substreams + EXTRA_PENDING_FRAMES {
903-
return self.on_error(io::Error::new(
904-
io::ErrorKind::Other,
905-
"Too many pending frames.",
906-
));
902+
return self.on_error(io::Error::other("Too many pending frames."));
907903
}
908904
Ok(())
909905
}

muxers/yamux/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,11 @@ impl From<Error> for io::Error {
437437
match err.0 {
438438
Either::Left(err) => match err {
439439
yamux012::ConnectionError::Io(e) => e,
440-
e => io::Error::new(io::ErrorKind::Other, e),
440+
e => io::Error::other(e),
441441
},
442442
Either::Right(err) => match err {
443443
yamux013::ConnectionError::Io(e) => e,
444-
e => io::Error::new(io::ErrorKind::Other, e),
444+
e => io::Error::other(e),
445445
},
446446
}
447447
}

protocols/autonat/src/v2/client/handler/dial_request.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -265,20 +265,13 @@ async fn start_stream_handle(
265265

266266
match res.status {
267267
ResponseStatus::E_REQUEST_REJECTED => {
268-
return Err(Error::Io(io::Error::new(
269-
io::ErrorKind::Other,
270-
"server rejected request",
271-
)))
268+
return Err(Error::Io(io::Error::other("server rejected request")))
272269
}
273270
ResponseStatus::E_DIAL_REFUSED => {
274-
return Err(Error::Io(io::Error::new(
275-
io::ErrorKind::Other,
276-
"server refused dial",
277-
)))
271+
return Err(Error::Io(io::Error::other("server refused dial")))
278272
}
279273
ResponseStatus::E_INTERNAL_ERROR => {
280-
return Err(Error::Io(io::Error::new(
281-
io::ErrorKind::Other,
274+
return Err(Error::Io(io::Error::other(
282275
"server encountered internal error",
283276
)))
284277
}

protocols/autonat/src/v2/protocol.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,7 @@ pub(crate) async fn dial_back(stream: impl AsyncWrite + Unpin, nonce: Nonce) ->
252252
let msg = proto::DialBack { nonce };
253253
let mut framed = FramedWrite::new(stream, Codec::<proto::DialBack>::new(DIAL_BACK_MAX_SIZE));
254254

255-
framed
256-
.send(msg)
257-
.await
258-
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
255+
framed.send(msg).await.map_err(io::Error::other)?;
259256

260257
Ok(())
261258
}
@@ -277,10 +274,7 @@ pub(crate) async fn dial_back_response(stream: impl AsyncWrite + Unpin) -> io::R
277274
stream,
278275
Codec::<proto::DialBackResponse>::new(DIAL_BACK_MAX_SIZE),
279276
);
280-
framed
281-
.send(msg)
282-
.await
283-
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
277+
framed.send(msg).await.map_err(io::Error::other)?;
284278

285279
Ok(())
286280
}

protocols/autonat/src/v2/server/handler/dial_back.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,6 @@ async fn perform_dial_back(
127127
};
128128
back_channel
129129
.send(res)
130-
.map_err(|_| io::Error::new(io::ErrorKind::Other, "send error"))?;
130+
.map_err(|_| io::Error::other("send error"))?;
131131
Ok(())
132132
}

protocols/autonat/src/v2/server/handler/dial_request.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,7 @@ async fn handle_request(
214214
tested_addr: observed_multiaddr,
215215
client,
216216
data_amount,
217-
result: Err(io::Error::new(
218-
io::ErrorKind::Other,
217+
result: Err(io::Error::other(
219218
"client is not conformint to protocol. the tested address is not the observed address",
220219
)),
221220
};

protocols/gossipsub/src/behaviour.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,6 +1819,10 @@ where
18191819
self.mcache.put(&msg_id, raw_message.clone());
18201820

18211821
// Dispatch the message to the user if we are subscribed to any of the topics
1822+
#[allow(
1823+
clippy::map_entry,
1824+
reason = "False positive, see rust-lang/rust-clippy#14449."
1825+
)]
18221826
if self.mesh.contains_key(&message.topic) {
18231827
tracing::debug!("Sending received message to user");
18241828
self.events

protocols/gossipsub/src/handler.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ impl EnabledHandler {
246246

247247
// process outbound stream
248248
loop {
249-
match std::mem::replace(
250-
&mut self.outbound_substream,
251-
Some(OutboundSubstreamState::Poisoned),
252-
) {
249+
match self
250+
.outbound_substream
251+
.replace(OutboundSubstreamState::Poisoned)
252+
{
253253
// outbound idle state
254254
Some(OutboundSubstreamState::WaitingOutput(substream)) => {
255255
if let Poll::Ready(Some(mut message)) = self.send_queue.poll_next_unpin(cx) {
@@ -344,10 +344,10 @@ impl EnabledHandler {
344344

345345
// Handle inbound messages.
346346
loop {
347-
match std::mem::replace(
348-
&mut self.inbound_substream,
349-
Some(InboundSubstreamState::Poisoned),
350-
) {
347+
match self
348+
.inbound_substream
349+
.replace(InboundSubstreamState::Poisoned)
350+
{
351351
// inbound idle state
352352
Some(InboundSubstreamState::WaitingInput(mut substream)) => {
353353
match substream.poll_next_unpin(cx) {

protocols/gossipsub/src/peer_score.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ impl PeerStats {
110110
topic_hash: TopicHash,
111111
params: &PeerScoreParams,
112112
) -> Option<&mut TopicStats> {
113+
#[allow(
114+
clippy::map_entry,
115+
reason = "False positive, see rust-lang/rust-clippy#14449."
116+
)]
113117
if params.topics.contains_key(&topic_hash) {
114118
Some(self.topics.entry(topic_hash).or_default())
115119
} else {

protocols/kad/src/behaviour.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2915,6 +2915,7 @@ pub type GetRecordResult = Result<GetRecordOk, GetRecordError>;
29152915

29162916
/// The successful result of [`Behaviour::get_record`].
29172917
#[derive(Debug, Clone)]
2918+
#[allow(clippy::large_enum_variant)]
29182919
pub enum GetRecordOk {
29192920
FoundRecord(PeerRecord),
29202921
FinishedWithNoAdditionalRecord {

protocols/kad/src/handler.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ enum InboundSubstreamState {
129129
}
130130

131131
impl InboundSubstreamState {
132+
#[allow(clippy::result_large_err)]
132133
fn try_answer_with(
133134
&mut self,
134135
id: RequestId,

protocols/relay/src/copy_future.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ where
7676

7777
loop {
7878
if this.max_circuit_bytes > 0 && this.bytes_sent > this.max_circuit_bytes {
79-
return Poll::Ready(Err(io::Error::new(
80-
io::ErrorKind::Other,
81-
"Max circuit bytes reached.",
82-
)));
79+
return Poll::Ready(Err(io::Error::other("Max circuit bytes reached.")));
8380
}
8481

8582
enum Status {

protocols/relay/src/priv_client.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(crate) mod transport;
2626
use std::{
2727
collections::{hash_map, HashMap, VecDeque},
2828
convert::Infallible,
29-
io::{Error, ErrorKind, IoSlice},
29+
io::{Error, IoSlice},
3030
pin::Pin,
3131
task::{Context, Poll},
3232
};
@@ -409,10 +409,7 @@ impl ConnectionState {
409409
pub(crate) fn new_inbound(circuit: inbound_stop::Circuit) -> Self {
410410
ConnectionState::InboundAccepting {
411411
accept: async {
412-
let (substream, read_buffer) = circuit
413-
.accept()
414-
.await
415-
.map_err(|e| Error::new(ErrorKind::Other, e))?;
412+
let (substream, read_buffer) = circuit.accept().await.map_err(Error::other)?;
416413
Ok(ConnectionState::Operational {
417414
read_buffer,
418415
substream,

protocols/request-response/src/cbor.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,24 +179,20 @@ pub mod codec {
179179

180180
fn decode_into_io_error(err: cbor4ii::serde::DecodeError<Infallible>) -> io::Error {
181181
match err {
182-
cbor4ii::serde::DecodeError::Core(DecodeError::Read(e)) => {
183-
io::Error::new(io::ErrorKind::Other, e)
184-
}
182+
cbor4ii::serde::DecodeError::Core(DecodeError::Read(e)) => io::Error::other(e),
185183
cbor4ii::serde::DecodeError::Core(e @ DecodeError::Unsupported { .. }) => {
186184
io::Error::new(io::ErrorKind::Unsupported, e)
187185
}
188186
cbor4ii::serde::DecodeError::Core(e @ DecodeError::Eof { .. }) => {
189187
io::Error::new(io::ErrorKind::UnexpectedEof, e)
190188
}
191189
cbor4ii::serde::DecodeError::Core(e) => io::Error::new(io::ErrorKind::InvalidData, e),
192-
cbor4ii::serde::DecodeError::Custom(e) => {
193-
io::Error::new(io::ErrorKind::Other, e.to_string())
194-
}
190+
cbor4ii::serde::DecodeError::Custom(e) => io::Error::other(e.to_string()),
195191
}
196192
}
197193

198194
fn encode_into_io_error(err: cbor4ii::serde::EncodeError<TryReserveError>) -> io::Error {
199-
io::Error::new(io::ErrorKind::Other, err)
195+
io::Error::other(err)
200196
}
201197
}
202198

protocols/request-response/src/handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ where
205205
{
206206
self.pending_events.push_back(Event::OutboundStreamFailed {
207207
request_id: message.request_id,
208-
error: io::Error::new(io::ErrorKind::Other, "max sub-streams reached"),
208+
error: io::Error::other("max sub-streams reached"),
209209
});
210210
}
211211
}

0 commit comments

Comments
 (0)