From dbeae5b81cf1327c676305d84d425d3b369d3929 Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Tue, 27 Feb 2024 12:12:10 +0100 Subject: [PATCH] chore: Apply Clippy lints from Rust 1.76 (manual) --- .../zenoh-keyexpr/src/key_expr/format/mod.rs | 5 +++-- commons/zenoh-keyexpr/src/key_expr/include.rs | 6 +++--- io/zenoh-transport/src/multicast/mod.rs | 19 ++++++++++++------- io/zenoh-transport/src/multicast/transport.rs | 4 ++-- plugins/zenoh-backend-traits/src/config.rs | 4 ++-- .../net/routing/hat/linkstate_peer/network.rs | 4 ++-- zenoh/src/net/routing/hat/p2p_peer/gossip.rs | 4 ++-- zenoh/src/net/routing/hat/router/network.rs | 4 ++-- 8 files changed, 28 insertions(+), 22 deletions(-) diff --git a/commons/zenoh-keyexpr/src/key_expr/format/mod.rs b/commons/zenoh-keyexpr/src/key_expr/format/mod.rs index 9a39fbeee1..3a03d8a515 100644 --- a/commons/zenoh-keyexpr/src/key_expr/format/mod.rs +++ b/commons/zenoh-keyexpr/src/key_expr/format/mod.rs @@ -509,7 +509,7 @@ impl<'s, Storage: IKeFormatStorage<'s>> KeFormatter<'s, Storage> { let pattern = segments[i].spec.pattern(); let start = self.buffer.len(); write!(&mut self.buffer, "{value}").unwrap(); // Writing on `&mut String` should be infallible. - match (|| { + let mut set_value = || { let end = self.buffer.len(); if start == end { if !pattern.is_double_wild() { @@ -529,7 +529,8 @@ impl<'s, Storage: IKeFormatStorage<'s>> KeFormatter<'s, Storage> { NonMaxU32::new(end.try_into().map_err(|_| ())?).ok_or(())?, )); Ok(()) - })() { + }; + match set_value() { Ok(()) => Ok(self), Err(()) => { self.buffer.truncate(start); diff --git a/commons/zenoh-keyexpr/src/key_expr/include.rs b/commons/zenoh-keyexpr/src/key_expr/include.rs index f58d5b6e0e..ca9efaee2d 100644 --- a/commons/zenoh-keyexpr/src/key_expr/include.rs +++ b/commons/zenoh-keyexpr/src/key_expr/include.rs @@ -35,7 +35,7 @@ pub struct LTRIncluder; impl Includer<&[u8], &[u8]> for LTRIncluder { fn includes(&self, mut left: &[u8], mut right: &[u8]) -> bool { loop { - let (lchunk, lrest) = left.split_once(&DELIMITER); + let (lchunk, lrest) = Split::split_once(left, &DELIMITER); let lempty = lrest.is_empty(); if lchunk == DOUBLE_WILD { if (lempty && !right.has_verbatim()) || (!lempty && self.includes(lrest, right)) { @@ -44,12 +44,12 @@ impl Includer<&[u8], &[u8]> for LTRIncluder { if unsafe { right.has_direct_verbatim_non_empty() } { return false; } - right = right.split_once(&DELIMITER).1; + right = Split::split_once(right, &DELIMITER).1; if right.is_empty() { return false; } } else { - let (rchunk, rrest) = right.split_once(&DELIMITER); + let (rchunk, rrest) = Split::split_once(right, &DELIMITER); if rchunk.is_empty() || rchunk == DOUBLE_WILD || !self.non_double_wild_chunk_includes(lchunk, rchunk) diff --git a/io/zenoh-transport/src/multicast/mod.rs b/io/zenoh-transport/src/multicast/mod.rs index 3ce0856df3..daf9b069ff 100644 --- a/io/zenoh-transport/src/multicast/mod.rs +++ b/io/zenoh-transport/src/multicast/mod.rs @@ -28,7 +28,7 @@ pub use manager::{ TransportManagerParamsMulticast, }; use std::{ - fmt, + fmt::{self, Write}, sync::{Arc, Weak}, }; use transport::TransportMulticastInner; @@ -147,12 +147,17 @@ impl fmt::Debug for TransportMulticast { match self.get_transport() { Ok(transport) => { let is_shm = zcondfeat!("shared-memory", transport.is_shm(), false); - let peers: String = zread!(transport.peers) - .iter() - .map(|(l, p)| { - format!("(locator: {}, zid: {}, whatami: {})", l, p.zid, p.whatami) - }) - .collect(); + let peers: String = + zread!(transport.peers) + .iter() + .fold(String::new(), |mut output, (l, p)| { + let _ = write!( + output, + "(locator: {}, zid: {}, whatami: {})", + l, p.zid, p.whatami + ); + output + }); f.debug_struct("Transport Multicast") .field("sn_resolution", &transport.get_sn_resolution()) diff --git a/io/zenoh-transport/src/multicast/transport.rs b/io/zenoh-transport/src/multicast/transport.rs index d5a1da14d4..b8aa41b253 100644 --- a/io/zenoh-transport/src/multicast/transport.rs +++ b/io/zenoh-transport/src/multicast/transport.rs @@ -115,7 +115,7 @@ impl TransportMulticastInner { ) -> ZResult { let mut priority_tx = vec![]; if (config.initial_sns.len() != 1) != (config.initial_sns.len() != Priority::NUM) { - for (_, sn) in config.initial_sns.iter().enumerate() { + for sn in config.initial_sns.iter() { let tct = TransportPriorityTx::make(config.sn_resolution)?; tct.sync(*sn)?; priority_tx.push(tct); @@ -359,7 +359,7 @@ impl TransportMulticastInner { .into_boxed_slice(); let mut priority_rx = Vec::with_capacity(next_sns.len()); - for (_, sn) in next_sns.iter().enumerate() { + for sn in next_sns.iter() { let tprx = TransportPriorityRx::make( join.resolution.get(Field::FrameSN), self.manager.config.defrag_buff_size, diff --git a/plugins/zenoh-backend-traits/src/config.rs b/plugins/zenoh-backend-traits/src/config.rs index e3fe484e5d..d3ddbd43cc 100644 --- a/plugins/zenoh-backend-traits/src/config.rs +++ b/plugins/zenoh-backend-traits/src/config.rs @@ -201,8 +201,8 @@ impl + AsRef, V: AsObject> TryFrom<(S, &V)> for PluginConfi rest: value .into_iter() .filter(|&(k, _v)| { - (!["__required__", "backend_search_dirs", "volumes", "storages"] - .contains(&k.as_str())) + !["__required__", "backend_search_dirs", "volumes", "storages"] + .contains(&k.as_str()) }) .map(|(k, v)| (k.clone(), v.clone())) .collect(), diff --git a/zenoh/src/net/routing/hat/linkstate_peer/network.rs b/zenoh/src/net/routing/hat/linkstate_peer/network.rs index 77bef7706d..ecd535eb86 100644 --- a/zenoh/src/net/routing/hat/linkstate_peer/network.rs +++ b/zenoh/src/net/routing/hat/linkstate_peer/network.rs @@ -774,12 +774,12 @@ impl Network { .graph .node_indices() .filter(|&idx| { - (self.full_linkstate + self.full_linkstate || self.gossip_multihop || self.links.values().any(|link| link.zid == zid) || (self.router_peers_failover_brokering && idx == self.idx - && whatami == WhatAmI::Router)) + && whatami == WhatAmI::Router) }) .map(|idx| { ( diff --git a/zenoh/src/net/routing/hat/p2p_peer/gossip.rs b/zenoh/src/net/routing/hat/p2p_peer/gossip.rs index 96dc57613a..c413107f85 100644 --- a/zenoh/src/net/routing/hat/p2p_peer/gossip.rs +++ b/zenoh/src/net/routing/hat/p2p_peer/gossip.rs @@ -510,11 +510,11 @@ impl Network { .graph .node_indices() .filter(|&idx| { - (self.gossip_multihop + self.gossip_multihop || self.links.values().any(|link| link.zid == zid) || (self.router_peers_failover_brokering && idx == self.idx - && whatami == WhatAmI::Router)) + && whatami == WhatAmI::Router) }) .map(|idx| { ( diff --git a/zenoh/src/net/routing/hat/router/network.rs b/zenoh/src/net/routing/hat/router/network.rs index 71ec8c0dcc..aa1209b7ed 100644 --- a/zenoh/src/net/routing/hat/router/network.rs +++ b/zenoh/src/net/routing/hat/router/network.rs @@ -779,12 +779,12 @@ impl Network { .graph .node_indices() .filter(|&idx| { - (self.full_linkstate + self.full_linkstate || self.gossip_multihop || self.links.values().any(|link| link.zid == zid) || (self.router_peers_failover_brokering && idx == self.idx - && whatami == WhatAmI::Router)) + && whatami == WhatAmI::Router) }) .map(|idx| { (