Skip to content

Commit

Permalink
Fix clippy warnings (#939)
Browse files Browse the repository at this point in the history
* Fix clippy warnings

* run apt-get update for Cross compile on ubuntu-latest (#938)

* build: Sync  with eclipse-zenoh/zenoh@f421407 from 2025-03-03 (#934)

Co-authored-by: eclipse-zenoh-bot <[email protected]>

* cargo fmt

* Replace async-std with ZRuntime and tokio (#937)

* Replace async-std with ZRuntime and tokio

* Improve error handling in z_scout

* Fix clippy warnings

* cargo fmt

---------

Co-authored-by: DenisBiryukov91 <[email protected]>
Co-authored-by: eclipse-zenoh-bot <[email protected]>
Co-authored-by: eclipse-zenoh-bot <[email protected]>
  • Loading branch information
4 people authored Mar 5, 2025
1 parent 2479fec commit c8df586
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 23 deletions.
16 changes: 8 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ fn configure() {
.unwrap();
}
}
file.unlock().unwrap();
fs2::FileExt::unlock(&file).unwrap();
}

fn text_replace<'a>(files: impl Iterator<Item = &'a str>) {
Expand All @@ -353,7 +353,7 @@ fn text_replace<'a>(files: impl Iterator<Item = &'a str>) {
file.lock_exclusive().unwrap();
let mut buf = String::new();
file.read_to_string(&mut buf).unwrap();
file.unlock().unwrap();
fs2::FileExt::unlock(&file).unwrap();

// Remove _T_ from enum variant name
let buf = buf.replace("_T_", "_");
Expand All @@ -374,7 +374,7 @@ fn text_replace<'a>(files: impl Iterator<Item = &'a str>) {
.unwrap();
file.lock_exclusive().unwrap();
file.write_all(buf.as_bytes()).unwrap();
file.unlock().unwrap();
fs2::FileExt::unlock(&file).unwrap();
}
}

Expand Down Expand Up @@ -424,7 +424,7 @@ fn split_bindings(split_guide: &SplitGuide) -> Result<(), String> {
record.is_used()?;
}
for (_, file) in files {
file.into_inner().unwrap().unlock().unwrap();
fs2::FileExt::unlock(&file.into_inner().unwrap()).unwrap();
}
std::fs::remove_file(GENERATION_PATH).unwrap();
Ok(())
Expand Down Expand Up @@ -628,7 +628,7 @@ impl<'a> Record<'a> {
}

// Print all comments first, skip whitespaces
impl<'a> std::fmt::Display for Record<'a> {
impl std::fmt::Display for Record<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.tokens
.iter()
Expand Down Expand Up @@ -666,7 +666,7 @@ struct Token<'a> {
id: &'a str,
span: Cow<'a, str>,
}
impl<'a> std::fmt::Display for Token<'a> {
impl std::fmt::Display for Token<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// f.write_str(format!("{:?} [", self.tt).as_str())?;
f.write_str(&self.span)?;
Expand Down Expand Up @@ -1411,14 +1411,14 @@ pub fn find_closure_constructors(path_in: &str) -> Vec<FunctionSignature> {
.unwrap();
let mut res = Vec::<FunctionSignature>::new();

let multiple_spaces = Regex::new(r"\s\s+").unwrap();
for (
_,
[return_type, prefix, suffix, closure_type, closure_name, call_signature_raw, drop_signature],
) in re.captures_iter(&bindings).map(|c| c.extract())
{
let mut call_signature: String = call_signature_raw.to_string().replace("struct ", "");
call_signature = call_signature.replace("enum ", "");
let multiple_spaces = Regex::new(r"\s\s+").unwrap();
call_signature = multiple_spaces
.replace_all(&call_signature, " ")
.to_string();
Expand Down Expand Up @@ -1887,7 +1887,7 @@ pub fn process_feature_defines(input_path: &str) -> Result<String, Box<dyn std::
let mut out = String::new();
let mut skip = false;
let mut nest_level: usize = 0;
for line in lines.flatten() {
for line in lines.map_while(Result::ok) {
if line.starts_with("#ifdef") && skip {
nest_level += 1;
} else if line.starts_with("#endif") && skip {
Expand Down
9 changes: 9 additions & 0 deletions include/zenoh_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -1842,6 +1842,7 @@ ZENOHC_API void z_close_options_default(struct z_close_options_t *this_);
* - `call` will never be called once `drop` has started.
* - `drop` will only be called **once**, and **after every** `call` has ended.
* - The two previous guarantees imply that `call` and `drop` are never called concurrently.
*
* @param this_: uninitialized memory location where new closure will be constructed.
* @param call: a closure body.
* @param drop: an optional function to be called once on closure drop.
Expand Down Expand Up @@ -1881,6 +1882,7 @@ struct z_loaned_closure_hello_t *z_closure_hello_loan_mut(struct z_owned_closure
* - `call` will never be called once `drop` has started.
* - `drop` will only be called **once**, and **after every** `call` has ended.
* - The two previous guarantees imply that `call` and `drop` are never called concurrently.
*
* @brief Constructs closure.
* @param this_: uninitialized memory location where new closure will be constructed.
* @param call: a closure body.
Expand Down Expand Up @@ -1929,6 +1931,7 @@ const struct z_loaned_closure_matching_status_t *z_closure_matching_status_loan(
* - `call` will never be called once `drop` has started.
* - `drop` will only be called **once**, and **after every** `call` has ended.
* - The two previous guarantees imply that `call` and `drop` are never called concurrently.
*
* @param this_: uninitialized memory location where new closure will be constructed.
* @param call: a closure body.
* @param drop: an optional function to be called once on closure drop.
Expand Down Expand Up @@ -1968,6 +1971,7 @@ struct z_loaned_closure_query_t *z_closure_query_loan_mut(struct z_owned_closure
* - `call` will never be called once `drop` has started.
* - `drop` will only be called **once**, and **after every** `call` has ended.
* - The two previous guarantees imply that `call` and `drop` are never called concurrently.
*
* @param this_: uninitialized memory location where new closure will be constructed.
* @param call: a closure body.
* @param drop: an optional function to be called once on closure drop.
Expand Down Expand Up @@ -2008,6 +2012,7 @@ struct z_loaned_closure_reply_t *z_closure_reply_loan_mut(struct z_owned_closure
* - `call` will never be called once `drop` has started.
* - `drop` will only be called **once**, and **after every** `call` has ended.
* - The two previous guarantees imply that `call` and `drop` are never called concurrently.
*
* @param this_: uninitialized memory location where new closure will be constructed.
* @param call: a closure body.
* @param drop: an optional function to be called once on closure drop.
Expand Down Expand Up @@ -2047,6 +2052,7 @@ struct z_loaned_closure_sample_t *z_closure_sample_loan_mut(struct z_owned_closu
* - `call` will never be called once `drop` has started.
* - `drop` will only be called **once**, and **after every** `call` has ended.
* - The two previous guarantees imply that `call` and `drop` are never called concurrently.
*
* @param this_: uninitialized memory location where new closure will be constructed.
* @param call: a closure body.
* @param drop: an optional function to be called once on closure drop.
Expand Down Expand Up @@ -5315,6 +5321,7 @@ z_result_t z_whatami_to_view_string(enum z_whatami_t whatami,
* There is no ideal signal to trigger this cleanup, so by default, zenoh triggers it in the following moments:
* - first POSIX SHM segment creation
* - process exit via exit() call or return from maint function
*
* It is OK to additionally trigger this function at any time, but be aware that this can be costly.
*
* For non-linux platforms this function currently does nothing
Expand All @@ -5332,6 +5339,7 @@ void zc_cleanup_orphaned_shm_segments(void);
* - `call` will never be called once `drop` has started.
* - `drop` will only be called **once**, and **after every** `call` has ended.
* - The two previous guarantees imply that `call` and `drop` are never called concurrently.
*
* @param this_: uninitialized memory location where new closure will be constructed.
* @param call: a closure body.
* @param drop: an optional function to be called once on closure drop.
Expand Down Expand Up @@ -5865,6 +5873,7 @@ void ze_advanced_subscriber_recovery_options_default(struct ze_advanced_subscrib
* - `call` will never be called once `drop` has started.
* - `drop` will only be called **once**, and **after every** `call` has ended.
* - The two previous guarantees imply that `call` and `drop` are never called concurrently.
*
* @brief Constructs closure.
* @param this_: uninitialized memory location where new closure will be constructed.
* @param call: a closure body.
Expand Down
1 change: 1 addition & 0 deletions src/closures/hello_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ pub extern "C" fn z_closure_hello_loan_mut(
/// - `call` will never be called once `drop` has started.
/// - `drop` will only be called **once**, and **after every** `call` has ended.
/// - The two previous guarantees imply that `call` and `drop` are never called concurrently.
///
/// @param this_: uninitialized memory location where new closure will be constructed.
/// @param call: a closure body.
/// @param drop: an optional function to be called once on closure drop.
Expand Down
1 change: 1 addition & 0 deletions src/closures/log_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ pub extern "C" fn zc_closure_log_loan(
/// - `call` will never be called once `drop` has started.
/// - `drop` will only be called **once**, and **after every** `call` has ended.
/// - The two previous guarantees imply that `call` and `drop` are never called concurrently.
///
/// @param this_: uninitialized memory location where new closure will be constructed.
/// @param call: a closure body.
/// @param drop: an optional function to be called once on closure drop.
Expand Down
1 change: 1 addition & 0 deletions src/closures/matching_status_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ pub extern "C" fn z_closure_matching_status_loan(
/// - `call` will never be called once `drop` has started.
/// - `drop` will only be called **once**, and **after every** `call` has ended.
/// - The two previous guarantees imply that `call` and `drop` are never called concurrently.
///
/// @brief Constructs closure.
/// @param this_: uninitialized memory location where new closure will be constructed.
/// @param call: a closure body.
Expand Down
1 change: 1 addition & 0 deletions src/closures/miss_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ pub extern "C" fn ze_closure_miss_loan(
/// - `call` will never be called once `drop` has started.
/// - `drop` will only be called **once**, and **after every** `call` has ended.
/// - The two previous guarantees imply that `call` and `drop` are never called concurrently.
///
/// @brief Constructs closure.
/// @param this_: uninitialized memory location where new closure will be constructed.
/// @param call: a closure body.
Expand Down
1 change: 1 addition & 0 deletions src/closures/query_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ pub extern "C" fn z_closure_query_loan_mut(
/// - `call` will never be called once `drop` has started.
/// - `drop` will only be called **once**, and **after every** `call` has ended.
/// - The two previous guarantees imply that `call` and `drop` are never called concurrently.
///
/// @param this_: uninitialized memory location where new closure will be constructed.
/// @param call: a closure body.
/// @param drop: an optional function to be called once on closure drop.
Expand Down
1 change: 1 addition & 0 deletions src/closures/reply_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ pub extern "C" fn z_closure_reply_loan_mut(
/// - `call` will never be called once `drop` has started.
/// - `drop` will only be called **once**, and **after every** `call` has ended.
/// - The two previous guarantees imply that `call` and `drop` are never called concurrently.
///
/// @param this_: uninitialized memory location where new closure will be constructed.
/// @param call: a closure body.
/// @param drop: an optional function to be called once on closure drop.
Expand Down
1 change: 1 addition & 0 deletions src/closures/sample_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ pub extern "C" fn z_closure_sample_loan_mut(
/// - `call` will never be called once `drop` has started.
/// - `drop` will only be called **once**, and **after every** `call` has ended.
/// - The two previous guarantees imply that `call` and `drop` are never called concurrently.
///
/// @param this_: uninitialized memory location where new closure will be constructed.
/// @param call: a closure body.
/// @param drop: an optional function to be called once on closure drop.
Expand Down
1 change: 1 addition & 0 deletions src/closures/zenohid_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ pub extern "C" fn z_closure_zid_loan_mut(
/// - `call` will never be called once `drop` has started.
/// - `drop` will only be called **once**, and **after every** `call` has ended.
/// - The two previous guarantees imply that `call` and `drop` are never called concurrently.
///
/// @param this_: uninitialized memory location where new closure will be constructed.
/// @param call: a closure body.
/// @param drop: an optional function to be called once on closure drop.
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ decl_c_type!(

/// Borrows config.
#[no_mangle]
pub extern "C" fn z_config_loan(this_: &'static z_owned_config_t) -> &z_loaned_config_t {
pub extern "C" fn z_config_loan(this_: &'static z_owned_config_t) -> &'static z_loaned_config_t {
let this = this_.as_rust_type_ref();
let this = unsafe { this.as_ref().unwrap_unchecked() };
this.as_loaned_c_type_ref()
Expand Down
2 changes: 1 addition & 1 deletion src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub unsafe extern "C" fn z_encoding_to_string(
out_str: &mut MaybeUninit<z_owned_string_t>,
) {
let s: Cow<'static, str> = this.as_rust_type_ref().into();
z_string_copy_from_substr(out_str, s.as_bytes().as_ptr() as _, s.as_bytes().len());
z_string_copy_from_substr(out_str, s.as_bytes().as_ptr() as _, s.len());
}

/// Returns a loaned default `z_loaned_encoding_t`.
Expand Down
10 changes: 2 additions & 8 deletions src/keyexpr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn keyexpr_create_inner(
if should_auto_canonize {
name.canonize();
}
return keyexpr::new(name).map(|k| k.into());
keyexpr::new(name).map(|k| k.into())
}
}

Expand Down Expand Up @@ -449,13 +449,7 @@ pub unsafe extern "C" fn z_keyexpr_as_view_string(
out_string: &mut MaybeUninit<z_view_string_t>,
) {
let this = this.as_rust_type_ref();
unsafe {
z_view_string_from_substr(
out_string,
this.as_bytes().as_ptr() as _,
this.as_bytes().len(),
)
};
unsafe { z_view_string_from_substr(out_string, this.as_bytes().as_ptr() as _, this.len()) };
}

/// Constructs and declares a key expression on the network. This reduces key key expression to a numerical id,
Expand Down
6 changes: 4 additions & 2 deletions src/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ pub extern "C" fn z_internal_query_check(query: &z_owned_query_t) -> bool {
/// Borrows the query.
#[no_mangle]
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn z_query_loan(this_: &'static z_owned_query_t) -> &z_loaned_query_t {
pub unsafe extern "C" fn z_query_loan(
this_: &'static z_owned_query_t,
) -> &'static z_loaned_query_t {
this_
.as_rust_type_ref()
.as_ref()
Expand All @@ -87,7 +89,7 @@ pub unsafe extern "C" fn z_query_loan(this_: &'static z_owned_query_t) -> &z_loa
#[allow(clippy::missing_safety_doc)]
pub unsafe extern "C" fn z_query_loan_mut(
this_: &'static mut z_owned_query_t,
) -> &mut z_loaned_query_t {
) -> &'static mut z_loaned_query_t {
this_
.as_rust_type_mut()
.as_mut()
Expand Down
1 change: 0 additions & 1 deletion src/querying_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ pub unsafe extern "C" fn ze_querying_subscriber_get(
selector: &z_loaned_keyexpr_t,
options: Option<&mut z_get_options_t>,
) -> result::z_result_t {
unsafe impl Sync for z_get_options_t {}
let sub = this.as_rust_type_ref();
let session = sub.1;
let selector = selector.as_rust_type_ref().clone();
Expand Down
2 changes: 1 addition & 1 deletion src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub extern "C" fn z_open(
_options: Option<&z_open_options_t>,
) -> result::z_result_t {
let this = this.as_rust_type_mut_uninit();
let Some(config) = config.take_rust_type().take() else {
let Some(config) = config.take_rust_type() else {
tracing::error!("Config not provided");
this.write(None);
return result::Z_EINVAL;
Expand Down
2 changes: 1 addition & 1 deletion src/shm/buffer/zshm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub extern "C" fn z_shm_from_mut(
this_: &mut MaybeUninit<z_owned_shm_t>,
that: &mut z_moved_shm_mut_t,
) {
let shm: Option<ZShm> = that.take_rust_type().take().map(|val| val.into());
let shm: Option<ZShm> = that.take_rust_type().map(|val| val.into());
this_.as_rust_type_mut_uninit().write(shm);
}

Expand Down
1 change: 1 addition & 0 deletions src/shm/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use zenoh::shm::cleanup_orphaned_shm_segments;
/// There is no ideal signal to trigger this cleanup, so by default, zenoh triggers it in the following moments:
/// - first POSIX SHM segment creation
/// - process exit via exit() call or return from maint function
///
/// It is OK to additionally trigger this function at any time, but be aware that this can be costly.
///
/// For non-linux platforms this function currently does nothing
Expand Down

0 comments on commit c8df586

Please sign in to comment.