Skip to content

Commit

Permalink
Fix Rust 1.84 clippy lints (#1705)
Browse files Browse the repository at this point in the history
* Fix Rust 1.84 clippy lints

* Fix unexpected_cfg clippy

* Fix shm clippy

* Fix unix-pipe clippy

* Fix shm examples clippy
  • Loading branch information
Mallets authored Jan 10, 2025
1 parent 5764ab5 commit 32eab2e
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion commons/zenoh-keyexpr/src/key_expr/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ impl<'s, Storage: IKeFormatStorage<'s>> core::fmt::Debug for KeFormatter<'s, Sto
let sharp = if id.contains('}')
|| pattern.contains('}')
|| value.map_or_else(
|| spec.default().map_or(false, |v| v.contains('}')),
|| spec.default().is_some_and(|v| v.contains('}')),
|v| v.contains('}'),
) {
"#"
Expand Down
2 changes: 1 addition & 1 deletion commons/zenoh-keyexpr/src/key_expr/format/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ fn do_parse<'a>(
}
}
pattern.is_double_wild()
&& prefix.map_or(false, |prefix| prefix.intersects(target))
&& prefix.is_some_and(|prefix| prefix.intersects(target))
&& do_parse(None, segments, results)
}
_ => unreachable!(),
Expand Down
2 changes: 1 addition & 1 deletion commons/zenoh-protocol/src/core/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ impl EndPoint {
let m: &str = metadata.as_ref();
let c: &str = config.as_ref();

let len = p.as_bytes().len() + a.as_bytes().len() + m.as_bytes().len();
let len = p.len() + a.len() + m.len();
if len > u8::MAX as usize {
bail!("Endpoint too big: {} bytes. Max: {} bytes. ", len, u8::MAX);
}
Expand Down
10 changes: 5 additions & 5 deletions commons/zenoh-shm/src/posix_shm/segment_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub(crate) mod unix {

impl Drop for ShmLock {
fn drop(&mut self) {
if self.0._tempfile.try_lock(FileLockMode::Exclusive).is_ok() {
if AdvisoryFileLock::try_lock(&self.0._tempfile, FileLockMode::Exclusive).is_ok() {
let _ = std::fs::remove_file(self.0.path.clone());
}
}
Expand All @@ -48,7 +48,7 @@ pub(crate) mod unix {
.open(path.clone())?;

// lock tempfile with shared lock to indicate that file is managed
tempfile.try_lock(FileLockMode::Shared)?;
AdvisoryFileLock::try_lock(&tempfile, FileLockMode::Shared)?;

Ok(Self(LockInner {
path,
Expand All @@ -67,7 +67,7 @@ pub(crate) mod unix {
let tempfile = OpenOptions::new().read(true).open(path.clone())?;

// lock tempfile with shared lock to indicate that file is managed
tempfile.try_lock(FileLockMode::Shared)?;
AdvisoryFileLock::try_lock(&tempfile, FileLockMode::Shared)?;

Ok(Self(LockInner {
path,
Expand Down Expand Up @@ -95,7 +95,7 @@ pub(crate) mod unix {
.open(path.clone())?;

// lock tempfile with exclusive lock to guarantee that the file is unmanaged
tempfile.try_lock(FileLockMode::Exclusive)?;
AdvisoryFileLock::try_lock(&tempfile, FileLockMode::Exclusive)?;

Ok(Self(LockInner {
path,
Expand All @@ -114,7 +114,7 @@ pub(crate) mod unix {
type Error = ();

fn try_from(value: ShmLock) -> Result<Self, Self::Error> {
if value.0._tempfile.try_lock(FileLockMode::Exclusive).is_ok() {
if AdvisoryFileLock::try_lock(&value.0._tempfile, FileLockMode::Exclusive).is_ok() {
return Ok(unsafe { core::mem::transmute::<ShmLock, ExclusiveShmLock>(value) });
}
Err(())
Expand Down
4 changes: 2 additions & 2 deletions examples/examples/z_pub_shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ async fn main() -> zenoh::Result<()> {
// We reserve a small space at the beginning of the buffer to include the iteration index
// of the write. This is simply to have the same format as zn_pub.
let prefix = format!("[{idx:4}] ");
let prefix_len = prefix.as_bytes().len();
let slice_len = prefix_len + payload.as_bytes().len();
let prefix_len = prefix.len();
let slice_len = prefix_len + payload.len();

sbuf[0..prefix_len].copy_from_slice(prefix.as_bytes());
sbuf[prefix_len..slice_len].copy_from_slice(payload.as_bytes());
Expand Down
6 changes: 3 additions & 3 deletions io/zenoh-links/zenoh-link-unixpipe/src/unix/unicast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl PipeR {
.open(path)?;

#[cfg(not(target_os = "macos"))]
read.try_lock(FileLockMode::Exclusive)?;
AdvisoryFileLock::try_lock(&read, FileLockMode::Exclusive)?;
Ok(read)
}
}
Expand Down Expand Up @@ -228,8 +228,8 @@ impl PipeW {
let write = open_write(path)?;
// the file must be already locked at the other side...
#[cfg(not(target_os = "macos"))]
if write.try_lock(FileLockMode::Exclusive).is_ok() {
let _ = write.unlock();
if AdvisoryFileLock::try_lock(&write, FileLockMode::Exclusive).is_ok() {
let _ = AdvisoryFileLock::unlock(&write);
bail!("no listener...")
}
Ok(write)
Expand Down
3 changes: 3 additions & 0 deletions plugins/zenoh-plugin-trait/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ license = { workspace = true }
categories = { workspace = true }
description = { workspace = true }

[features]
default = []

[lib]
name = "zenoh_plugin_trait"

Expand Down
4 changes: 2 additions & 2 deletions zenoh/src/api/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1916,13 +1916,13 @@ impl SessionInner {
MatchingStatusType::Queryables(false) => state.queryables.values().any(|q| {
state
.local_wireexpr_to_expr(&q.key_expr)
.map_or(false, |ke| ke.intersects(key_expr))
.is_ok_and(|ke| ke.intersects(key_expr))
}),
MatchingStatusType::Queryables(true) => state.queryables.values().any(|q| {
q.complete
&& state
.local_wireexpr_to_expr(&q.key_expr)
.map_or(false, |ke| ke.includes(key_expr))
.is_ok_and(|ke| ke.includes(key_expr))
}),
};
MatchingStatus { matching }
Expand Down
4 changes: 2 additions & 2 deletions zenoh/src/net/routing/hat/client/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ impl HatQueriesTrait for HatCode {
qbl.session_ctxs
.get(&face.id)
.and_then(|sc| sc.qabl)
.map_or(false, |q| q.complete)
.is_some_and(|q| q.complete)
&& KeyExpr::keyexpr_include(qbl.expr(), key_expr)
}
false => KeyExpr::keyexpr_intersect(qbl.expr(), key_expr),
Expand All @@ -493,7 +493,7 @@ impl HatQueriesTrait for HatCode {
for (sid, context) in &mres.session_ctxs {
if context.face.whatami == WhatAmI::Client
&& match complete {
true => context.qabl.map_or(false, |q| q.complete),
true => context.qabl.is_some_and(|q| q.complete),
false => context.qabl.is_some(),
}
{
Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/net/routing/hat/linkstate_peer/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ impl HatQueriesTrait for HatCode {

for (sid, context) in &mres.session_ctxs {
if match complete {
true => context.qabl.map_or(false, |q| q.complete),
true => context.qabl.is_some_and(|q| q.complete),
false => context.qabl.is_some(),
} {
matching_queryables
Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/net/routing/hat/p2p_peer/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ impl HatQueriesTrait for HatCode {
}
for (sid, context) in &mres.session_ctxs {
if match complete {
true => context.qabl.map_or(false, |q| q.complete),
true => context.qabl.is_some_and(|q| q.complete),
false => context.qabl.is_some(),
} {
matching_queryables
Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/net/routing/hat/router/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,7 @@ impl HatQueriesTrait for HatCode {
if master {
for (sid, context) in &mres.session_ctxs {
if match complete {
true => context.qabl.map_or(false, |q| q.complete),
true => context.qabl.is_some_and(|q| q.complete),
false => context.qabl.is_some(),
} && context.face.whatami != WhatAmI::Router
{
Expand Down

0 comments on commit 32eab2e

Please sign in to comment.