Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Clippy errors from Rust 1.80 #1270

Merged
merged 10 commits into from
Jul 25, 2024
46 changes: 32 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# NOTE: Resources are hashed using their `.suffix` field without using any interior mutable fields.
# See https://github.com/eclipse-zenoh/zenoh/blob/b55c781220d7ea9f7f117570990f6e4e063e58fe/zenoh/src/net/routing/dispatcher/resource.rs#L193
# A corresponding comment is present in the `Hash` implementation of `Resource` as a reminder that this configuration is set.
ignore-interior-mutability = [
"zenoh::net::routing::dispatcher::resource::Resource",
]
2 changes: 1 addition & 1 deletion commons/zenoh-keyexpr/src/keyexpr_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
//! KeTrees come in two flavours:
//! - [`KeBoxTree`] is the easier flavour. Much like a HashMap, it uniquely owns all of its nodes and data.
//! - [`KeArcTree`] allows the shared ownership of nodes, allowing you to store subsections of the tree elsewhere
//! without worrying about lifetimes.
//! without worrying about lifetimes.
//!
//! # Usage
//! KeTrees were designed to maximize code reuse. As such, their core properties are reflected through the [`IKeyExprTree`] and [`IKeyExprTreeMut`] traits.
Expand Down
2 changes: 1 addition & 1 deletion commons/zenoh-keyexpr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
//! - [`keyexpr`] is the equivalent of a [`str`],
//! - [`OwnedKeyExpr`] works like an [`Arc<str>`](std::sync::Arc),
//! - [`KeyExpr`](https://docs.rs/zenoh/latest/zenoh/key_expr/struct.KeyExpr.html) works like a [`Cow<str>`](std::borrow::Cow), but also stores some additional context internal to Zenoh to optimize
//! routing and network usage.
//! routing and network usage.
//!
//! All of these types [`Deref`](core::ops::Deref) to [`keyexpr`], which notably has methods to check whether a given [`keyexpr::intersects`] with another,
//! or even if a [`keyexpr::includes`] another.
Expand Down
3 changes: 3 additions & 0 deletions zenoh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,6 @@ license-file = ["../LICENSE", "0"]
depends = "zenohd (=0.11.0-dev-1), zenoh-plugin-rest (=0.11.0-dev-1), zenoh-plugin-storage-manager (=0.11.0-dev-1)"
maintainer-scripts = ".deb"
assets = [["../README.md", "README.md", "644"]]

[lints.rust]
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(doc_auto_cfg)'] }
4 changes: 0 additions & 4 deletions zenoh/src/api/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,16 +901,12 @@ impl EncodingMapping for u128 {
}

impl EncodingMapping for usize {
#[cfg(target_pointer_width = "8")]
const ENCODING: Encoding = Encoding::ZENOH_UINT8;
#[cfg(target_pointer_width = "16")]
const ENCODING: Encoding = Encoding::ZENOH_UINT16;
#[cfg(target_pointer_width = "32")]
const ENCODING: Encoding = Encoding::ZENOH_UINT32;
#[cfg(target_pointer_width = "64")]
const ENCODING: Encoding = Encoding::ZENOH_UINT64;
#[cfg(target_pointer_width = "128")]
const ENCODING: Encoding = Encoding::ZENOH_UINT128;
}

// Zenoh signed integers
Expand Down
10 changes: 5 additions & 5 deletions zenoh/src/api/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ pub trait RunningPluginTrait: Send + Sync + PluginControl {
/// Thus the plugin can reply its contribution to the global admin space of this zenohd.
/// Parameters:
/// * `key_expr`: the key_expr selector of the query. This key_expr is
/// exactly the same as it was requested by user, for example "@/ROUTER_ID/router/plugins/PLUGIN_NAME/some/plugin/info" or "@/*/router/plugins/*/foo/bar".
/// But the plugin's [RunningPluginTrait::adminspace_getter] is called only if the key_expr matches the `plugin_status_key`
/// exactly the same as it was requested by user, for example "@/ROUTER_ID/router/plugins/PLUGIN_NAME/some/plugin/info" or "@/*/router/plugins/*/foo/bar".
/// But the plugin's [RunningPluginTrait::adminspace_getter] is called only if the key_expr matches the `plugin_status_key`
/// * `plugin_status_key`: the actual path to plugin's status in the admin space. For example "@/ROUTER_ID/router/plugins/PLUGIN_NAME"
/// Returns value:
/// Returns value:
/// * `Ok(Vec<Response>)`: the list of responses to the query. For example if plugins can return information on subleys "foo", "bar", "foo/buzz" and "bar/buzz"
/// and it's requested with the query "@/ROUTER_ID/router/plugins/PLUGIN_NAME/*", it should return only information on "foo" and "bar" subkeys, but not on "foo/buzz" and "bar/buzz"
/// as they doesn't match the query.
/// and it's requested with the query "@/ROUTER_ID/router/plugins/PLUGIN_NAME/*", it should return only information on "foo" and "bar" subkeys, but not on "foo/buzz" and "bar/buzz"
/// as they doesn't match the query.
/// * `Err(ZError)`: Problem occurred when processing the query.
///
/// If plugin implements subplugins (as the storage plugin), then it should also reply with information about its subplugins with the same rules.
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 @@ -2033,7 +2033,7 @@ impl<'s> SessionDeclarations<'s, 'static> for Arc<Session> {
/// # Arguments
///
/// * `key_expr` - The key expression matching the queries the
/// [`Queryable`](crate::query::Queryable) will reply to
/// [`Queryable`](crate::query::Queryable) will reply to
///
/// # Examples
/// ```no_run
Expand Down Expand Up @@ -2692,7 +2692,7 @@ pub trait SessionDeclarations<'s, 'a> {
/// # Arguments
///
/// * `key_expr` - The key expression matching the queries the
/// [`Queryable`](crate::query::Queryable) will reply to
/// [`Queryable`](crate::query::Queryable) will reply to
///
/// # Examples
/// ```no_run
Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub mod prelude;
/// - [`keyexpr`](crate::key_expr::keyexpr) is the equivalent of a [`str`],
/// - [`OwnedKeyExpr`](crate::key_expr::OwnedKeyExpr) works like an [`std::sync::Arc<str>`],
/// - [`KeyExpr`](crate::key_expr::KeyExpr) works like a [`std::borrow::Cow<str>`], but also stores some additional context internal to Zenoh to optimize
/// routing and network usage.
/// routing and network usage.
///
/// All of these types [`Deref`](std::ops::Deref) to [`keyexpr`](crate::key_expr::keyexpr), which notably has methods to check whether a given [`intersects`](crate::key_expr::keyexpr::includes) with another,
/// or even if a [`includes`](crate::key_expr::keyexpr::includes) another.
Expand Down
4 changes: 4 additions & 0 deletions zenoh/src/net/routing/dispatcher/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ impl PartialEq for Resource {
}
impl Eq for Resource {}

// NOTE: The `clippy::mutable_key_type` lint takes issue with the fact that `Resource` contains
// interior mutable data. A configuration option is used to assert that the accessed fields are
// not interior mutable in clippy.toml. Thus care should be taken to ensure soundness of this impl
// as Clippy will not warn about its usage in sets/maps.
impl Hash for Resource {
fn hash<H: Hasher>(&self, state: &mut H) {
self.expr().hash(state);
Expand Down
4 changes: 4 additions & 0 deletions zenoh/src/net/routing/interceptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ impl<T: InterceptorTrait> InterceptorTrait for ComputeOnMiss<T> {
}
}

#[allow(dead_code)]
pub(crate) struct IngressMsgLogger {}

impl InterceptorTrait for IngressMsgLogger {
Expand Down Expand Up @@ -186,6 +187,8 @@ impl InterceptorTrait for IngressMsgLogger {
Some(ctx)
}
}

#[allow(dead_code)]
pub(crate) struct EgressMsgLogger {}

impl InterceptorTrait for EgressMsgLogger {
Expand Down Expand Up @@ -213,6 +216,7 @@ impl InterceptorTrait for EgressMsgLogger {
}
}

#[allow(dead_code)]
pub(crate) struct LoggerInterceptor {}

impl InterceptorFactoryTrait for LoggerInterceptor {
Expand Down
15 changes: 5 additions & 10 deletions zenoh/src/net/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,17 @@ impl RuntimeBuilder {
runtime: std::sync::RwLock::new(WeakRuntime { state: Weak::new() }),
});

let transport_manager = TransportManager::builder()
let transport_manager_builder = TransportManager::builder()
.from_config(&config)
.await?
.whatami(whatami)
.zid(zid);

#[cfg(feature = "unstable")]
let transport_manager = zcondfeat!(
"shared-memory",
transport_manager.shm_reader(shm_clients.map(ShmReader::new)),
transport_manager
)
.build(handler.clone())?;
#[cfg(feature = "shared-memory")]
let transport_manager_builder =
transport_manager_builder.shm_reader(shm_clients.map(ShmReader::new));

#[cfg(not(feature = "unstable"))]
let transport_manager = transport_manager.build(handler.clone())?;
let transport_manager = transport_manager_builder.build(handler.clone())?;

// Plugins manager
#[cfg(feature = "plugins")]
Expand Down
5 changes: 3 additions & 2 deletions zenohd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ struct Args {
/// Allows arbitrary configuration changes as column-separated KEY:VALUE pairs, where:
/// - KEY must be a valid config path.
/// - VALUE must be a valid JSON5 string that can be deserialized to the expected type for the KEY field.
///
/// Examples:
/// --cfg='startup/subscribe:["demo/**"]'
/// --cfg='plugins/storage_manager/storages/demo:{key_expr:"demo/example/**",volume:"memory"}'
/// - `--cfg='startup/subscribe:["demo/**"]'`
/// - `--cfg='plugins/storage_manager/storages/demo:{key_expr:"demo/example/**",volume:"memory"}'`
#[arg(long)]
cfg: Vec<String>,
/// Configure the read and/or write permissions on the admin space. Default is read only.
Expand Down
Loading