diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f87077b516..51efbf1fd8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,14 +47,14 @@ jobs: run: cargo fmt --check - name: Clippy - run: cargo clippy --all-targets -- --deny warnings + run: cargo +stable clippy --all-targets -- --deny warnings - name: Clippy unstable targets - run: cargo clippy --all-targets --features unstable -- --deny warnings + run: cargo +stable clippy --all-targets --features unstable -- --deny warnings - name: Clippy all features if: ${{ matrix.os == 'ubuntu-latest' || matrix.os == 'macOS-latest' }} - run: cargo clippy --all-targets --all-features -- --deny warnings + run: cargo +stable clippy --all-targets --all-features -- --deny warnings - name: Install generic no_std target # Generic no_std target architecture is x86_64-unknown-none diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d8bd218ae8..982a474956 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -72,13 +72,13 @@ jobs: CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse - name: Clippy check - run: cargo clippy --all-targets --features=${{ github.event.inputs.features}} -- --deny warnings + run: cargo +stable clippy --all-targets --features=${{ github.event.inputs.features}} -- --deny warnings - name: Clippy unstable check - run: cargo clippy --all-targets -- --deny warnings + run: cargo +stable clippy --all-targets -- --deny warnings - name: Clippy all features - run: cargo clippy --all-targets --all-features -- --deny warnings + run: cargo +stable clippy --all-targets --all-features -- --deny warnings - name: Environment setup id: env diff --git a/commons/zenoh-core/src/lib.rs b/commons/zenoh-core/src/lib.rs index 1380680260..f3ba5fd499 100644 --- a/commons/zenoh-core/src/lib.rs +++ b/commons/zenoh-core/src/lib.rs @@ -19,7 +19,7 @@ //! [Click here for Zenoh's documentation](../zenoh/index.html) pub use lazy_static::lazy_static; pub mod macros; -pub use macros::*; + use std::future::{Future, Ready}; // Re-exports after moving ZError/ZResult to zenoh-result 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/commons/zenoh-protocol/src/core/endpoint.rs b/commons/zenoh-protocol/src/core/endpoint.rs index e596b78bde..5e921345e4 100644 --- a/commons/zenoh-protocol/src/core/endpoint.rs +++ b/commons/zenoh-protocol/src/core/endpoint.rs @@ -85,7 +85,7 @@ impl Parameters { } } - pub fn iter(s: &str) -> impl Iterator + DoubleEndedIterator { + pub fn iter(s: &str) -> impl DoubleEndedIterator { s.split(LIST_SEPARATOR).filter_map(|prop| { if prop.is_empty() { None @@ -99,7 +99,7 @@ impl Parameters { Self::iter(s).find(|x| x.0 == k).map(|x| x.1) } - pub fn values<'s>(s: &'s str, k: &str) -> impl Iterator + DoubleEndedIterator { + pub fn values<'s>(s: &'s str, k: &str) -> impl DoubleEndedIterator { match Self::get(s, k) { Some(v) => v.split(VALUE_SEPARATOR), None => { @@ -277,7 +277,7 @@ impl<'a> Metadata<'a> { self.as_str().is_empty() } - pub fn iter(&'a self) -> impl Iterator + DoubleEndedIterator { + pub fn iter(&'a self) -> impl DoubleEndedIterator { Parameters::iter(self.0) } @@ -285,7 +285,7 @@ impl<'a> Metadata<'a> { Parameters::get(self.0, k) } - pub fn values(&'a self, k: &str) -> impl Iterator + DoubleEndedIterator { + pub fn values(&'a self, k: &str) -> impl DoubleEndedIterator { Parameters::values(self.0, k) } } @@ -394,7 +394,7 @@ impl<'a> Config<'a> { self.as_str().is_empty() } - pub fn iter(&'a self) -> impl Iterator + DoubleEndedIterator { + pub fn iter(&'a self) -> impl DoubleEndedIterator { Parameters::iter(self.0) } @@ -402,7 +402,7 @@ impl<'a> Config<'a> { Parameters::get(self.0, k) } - pub fn values(&'a self, k: &str) -> impl Iterator + DoubleEndedIterator { + pub fn values(&'a self, k: &str) -> impl DoubleEndedIterator { Parameters::values(self.0, k) } } diff --git a/commons/zenoh-protocol/src/core/resolution.rs b/commons/zenoh-protocol/src/core/resolution.rs index a174ecdc9d..093fd33bb4 100644 --- a/commons/zenoh-protocol/src/core/resolution.rs +++ b/commons/zenoh-protocol/src/core/resolution.rs @@ -27,10 +27,10 @@ pub enum Bits { } impl Bits { - const S8: &str = "8bit"; - const S16: &str = "16bit"; - const S32: &str = "32bit"; - const S64: &str = "64bit"; + const S8: &'static str = "8bit"; + const S16: &'static str = "16bit"; + const S32: &'static str = "32bit"; + const S64: &'static str = "64bit"; pub const fn bits(&self) -> u32 { match self { diff --git a/commons/zenoh-protocol/src/core/whatami.rs b/commons/zenoh-protocol/src/core/whatami.rs index faeb4712e0..6aacb0d356 100644 --- a/commons/zenoh-protocol/src/core/whatami.rs +++ b/commons/zenoh-protocol/src/core/whatami.rs @@ -25,9 +25,9 @@ pub enum WhatAmI { } impl WhatAmI { - const STR_R: &str = "router"; - const STR_P: &str = "peer"; - const STR_C: &str = "client"; + const STR_R: &'static str = "router"; + const STR_P: &'static str = "peer"; + const STR_C: &'static str = "client"; const U8_R: u8 = Self::Router as u8; const U8_P: u8 = Self::Peer as u8; diff --git a/io/zenoh-links/zenoh-link-udp/src/multicast.rs b/io/zenoh-links/zenoh-link-udp/src/multicast.rs index 838bb8acd5..497120ed0d 100644 --- a/io/zenoh-links/zenoh-link-udp/src/multicast.rs +++ b/io/zenoh-links/zenoh-link-udp/src/multicast.rs @@ -174,7 +174,7 @@ impl LinkManagerMulticastUdp { }) .take(1) .collect::>() - .get(0) + .first() .copied(), }; } @@ -194,7 +194,7 @@ impl LinkManagerMulticastUdp { }) .take(1) .collect::>() - .get(0) + .first() .copied(); match iface { 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 dbcfa420b3..d3ddbd43cc 100644 --- a/plugins/zenoh-backend-traits/src/config.rs +++ b/plugins/zenoh-backend-traits/src/config.rs @@ -200,11 +200,11 @@ impl + AsRef, V: AsObject> TryFrom<(S, &V)> for PluginConfi storages, rest: value .into_iter() - .filter_map(|(k, v)| { - (!["__required__", "backend_search_dirs", "volumes", "storages"] - .contains(&k.as_str())) - .then(|| (k.clone(), v.clone())) + .filter(|&(k, _v)| { + !["__required__", "backend_search_dirs", "volumes", "storages"] + .contains(&k.as_str()) }) + .map(|(k, v)| (k.clone(), v.clone())) .collect(), }) } @@ -313,10 +313,8 @@ impl VolumeConfig { required, rest: config .iter() - .filter_map(|(k, v)| { - (!["__path__", "__required__"].contains(&k.as_str())) - .then(|| (k.clone(), v.clone())) - }) + .filter(|&(k, _v)| (!["__path__", "__required__"].contains(&k.as_str()))) + .map(|(k, v)| (k.clone(), v.clone())) .collect(), }) } diff --git a/plugins/zenoh-plugin-storage-manager/src/replica/mod.rs b/plugins/zenoh-plugin-storage-manager/src/replica/mod.rs index 1dc9df9262..b743a70451 100644 --- a/plugins/zenoh-plugin-storage-manager/src/replica/mod.rs +++ b/plugins/zenoh-plugin-storage-manager/src/replica/mod.rs @@ -40,7 +40,7 @@ pub mod storage; pub use align_queryable::AlignQueryable; pub use aligner::Aligner; pub use digest::{Digest, DigestConfig, EraType, LogEntry}; -pub use snapshotter::{ReplicationInfo, Snapshotter}; +pub use snapshotter::Snapshotter; pub use storage::{ReplicationService, StorageService}; const ERA: &str = "era"; diff --git a/zenoh/src/net/routing/hat/linkstate_peer/network.rs b/zenoh/src/net/routing/hat/linkstate_peer/network.rs index ac610a808b..ecd535eb86 100644 --- a/zenoh/src/net/routing/hat/linkstate_peer/network.rs +++ b/zenoh/src/net/routing/hat/linkstate_peer/network.rs @@ -773,26 +773,26 @@ impl Network { let idxs = self .graph .node_indices() - .filter_map(|idx| { - (self.full_linkstate + .filter(|&idx| { + 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)) - .then(|| { - ( - idx, - Details { - zid: true, - locators: self.propagate_locators(idx), - links: self.full_linkstate - || (self.router_peers_failover_brokering - && idx == self.idx - && whatami == WhatAmI::Router), - }, - ) - }) + && whatami == WhatAmI::Router) + }) + .map(|idx| { + ( + idx, + Details { + zid: true, + locators: self.propagate_locators(idx), + links: self.full_linkstate + || (self.router_peers_failover_brokering + && idx == self.idx + && whatami == WhatAmI::Router), + }, + ) }) .collect(); self.send_on_link(idxs, &transport); diff --git a/zenoh/src/net/routing/hat/p2p_peer/gossip.rs b/zenoh/src/net/routing/hat/p2p_peer/gossip.rs index ae3fda51a7..c413107f85 100644 --- a/zenoh/src/net/routing/hat/p2p_peer/gossip.rs +++ b/zenoh/src/net/routing/hat/p2p_peer/gossip.rs @@ -509,24 +509,24 @@ impl Network { let idxs = self .graph .node_indices() - .filter_map(|idx| { - (self.gossip_multihop + .filter(|&idx| { + self.gossip_multihop || self.links.values().any(|link| link.zid == zid) || (self.router_peers_failover_brokering && idx == self.idx - && whatami == WhatAmI::Router)) - .then(|| { - ( - idx, - Details { - zid: true, - locators: self.propagate_locators(idx), - links: (self.router_peers_failover_brokering - && idx == self.idx - && whatami == WhatAmI::Router), - }, - ) - }) + && whatami == WhatAmI::Router) + }) + .map(|idx| { + ( + idx, + Details { + zid: true, + locators: self.propagate_locators(idx), + links: (self.router_peers_failover_brokering + && idx == self.idx + && whatami == WhatAmI::Router), + }, + ) }) .collect(); self.send_on_link(idxs, &transport); diff --git a/zenoh/src/net/routing/hat/router/network.rs b/zenoh/src/net/routing/hat/router/network.rs index ccc8a55850..aa1209b7ed 100644 --- a/zenoh/src/net/routing/hat/router/network.rs +++ b/zenoh/src/net/routing/hat/router/network.rs @@ -778,26 +778,26 @@ impl Network { let idxs = self .graph .node_indices() - .filter_map(|idx| { - (self.full_linkstate + .filter(|&idx| { + 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)) - .then(|| { - ( - idx, - Details { - zid: true, - locators: self.propagate_locators(idx), - links: self.full_linkstate - || (self.router_peers_failover_brokering - && idx == self.idx - && whatami == WhatAmI::Router), - }, - ) - }) + && whatami == WhatAmI::Router) + }) + .map(|idx| { + ( + idx, + Details { + zid: true, + locators: self.propagate_locators(idx), + links: self.full_linkstate + || (self.router_peers_failover_brokering + && idx == self.idx + && whatami == WhatAmI::Router), + }, + ) }) .collect(); self.send_on_link(idxs, &transport); diff --git a/zenoh/src/session.rs b/zenoh/src/session.rs index 374320bde9..7900a3add8 100644 --- a/zenoh/src/session.rs +++ b/zenoh/src/session.rs @@ -799,7 +799,7 @@ impl Session { } #[allow(clippy::new_ret_no_self)] - pub(super) fn new(config: Config) -> impl Resolve> + Send { + pub(super) fn new(config: Config) -> impl Resolve> { ResolveFuture::new(async move { log::debug!("Config: {:?}", &config); let aggregated_subscribers = config.aggregation().subscribers().clone(); @@ -827,10 +827,7 @@ impl Session { }) } - pub(crate) fn declare_prefix<'a>( - &'a self, - prefix: &'a str, - ) -> impl Resolve + Send + 'a { + pub(crate) fn declare_prefix<'a>(&'a self, prefix: &'a str) -> impl Resolve + 'a { ResolveClosure::new(move || { trace!("declare_prefix({:?})", prefix); let mut state = zwrite!(self.state); @@ -888,7 +885,7 @@ impl Session { pub(crate) fn declare_publication_intent<'a>( &'a self, _key_expr: KeyExpr<'a>, - ) -> impl Resolve> + Send + 'a { + ) -> impl Resolve> + 'a { ResolveClosure::new(move || { // log::trace!("declare_publication({:?})", key_expr); // let mut state = zwrite!(self.state); diff --git a/zenoh/tests/matching.rs b/zenoh/tests/matching.rs index 92c4deba57..f36bf5481b 100644 --- a/zenoh/tests/matching.rs +++ b/zenoh/tests/matching.rs @@ -35,7 +35,7 @@ async fn create_session_pair(locator: &str) -> (Session, Session) { config.scouting.multicast.set_enabled(Some(false)).unwrap(); config .listen - .set_endpoints(vec![locator.clone().parse().unwrap()]) + .set_endpoints(vec![locator.parse().unwrap()]) .unwrap(); config };