From e587aa9ce43af6cb78bbe418f478804218f7b19f Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Fri, 26 Jul 2024 11:16:28 +0200 Subject: [PATCH] Fix Clippy errors from Rust 1.80 (#1273) * Allow unexpected `doc_auto_cfg` flag * Keep never-constructed logger interceptor * Ignore interior mutability of `Resource` * Fix typo * Resolve `clippy::doc-lazy-continuation` errors * Upgrade `time@0.3.28` to `time@0.3.36` See https://github.com/time-rs/time/issues/693 --- Cargo.lock | 42 ++++++++++++++------ clippy.toml | 6 +++ zenoh/Cargo.toml | 3 ++ zenoh/src/key_expr.rs | 2 +- zenoh/src/net/routing/dispatcher/resource.rs | 4 ++ zenoh/src/net/routing/interceptor/mod.rs | 5 +++ zenoh/src/plugins/sealed.rs | 9 +++-- zenoh/src/session.rs | 4 +- zenohd/src/main.rs | 5 ++- 9 files changed, 59 insertions(+), 21 deletions(-) create mode 100644 clippy.toml diff --git a/Cargo.lock b/Cargo.lock index 8aee8b7638..7282479a20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1022,9 +1022,12 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.8" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] [[package]] name = "derive-new" @@ -1896,7 +1899,7 @@ dependencies = [ "regex", "serde", "serde_json", - "time 0.3.28", + "time 0.3.36", "url", "uuid", ] @@ -2264,6 +2267,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-integer" version = "0.1.45" @@ -2676,6 +2685,12 @@ dependencies = [ "universal-hash", ] +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -2887,7 +2902,7 @@ checksum = "4954fbc00dcd4d8282c987710e50ba513d351400dbdd00e803a05172a90d8976" dependencies = [ "pem", "ring 0.16.20", - "time 0.3.28", + "time 0.3.36", "yasna", ] @@ -3926,21 +3941,23 @@ dependencies = [ [[package]] name = "time" -version = "0.3.28" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f6bb557fd245c28e6411aa56b6403c689ad95061f50e4be16c274e70a17e48" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", + "num-conv", + "powerfmt", "serde", "time-core", - "time-macros 0.2.14", + "time-macros 0.2.18", ] [[package]] name = "time-core" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" @@ -3954,10 +3971,11 @@ dependencies = [ [[package]] name = "time-macros" -version = "0.2.14" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a942f44339478ef67935ab2bbaec2fb0322496cf3cbe84b261e06ac3814c572" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ + "num-conv", "time-core", ] @@ -4870,7 +4888,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e17bb3549cc1321ae1296b9cdc2698e2b6cb1992adfa19a8c72e5b7a738f44cd" dependencies = [ - "time 0.3.28", + "time 0.3.36", ] [[package]] diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 0000000000..49436d7ba9 --- /dev/null +++ b/clippy.toml @@ -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", +] diff --git a/zenoh/Cargo.toml b/zenoh/Cargo.toml index a8bf041c11..78b90ad9f1 100644 --- a/zenoh/Cargo.toml +++ b/zenoh/Cargo.toml @@ -130,3 +130,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)'] } diff --git a/zenoh/src/key_expr.rs b/zenoh/src/key_expr.rs index c3117561cb..99f5aa6187 100644 --- a/zenoh/src/key_expr.rs +++ b/zenoh/src/key_expr.rs @@ -24,7 +24,7 @@ //! - [`keyexpr`] is the equivalent of a [`str`], //! - [`OwnedKeyExpr`] works like an [`std::sync::Arc`], //! - [`KeyExpr`] works like a [`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. diff --git a/zenoh/src/net/routing/dispatcher/resource.rs b/zenoh/src/net/routing/dispatcher/resource.rs index 34f1229137..edfcf26925 100644 --- a/zenoh/src/net/routing/dispatcher/resource.rs +++ b/zenoh/src/net/routing/dispatcher/resource.rs @@ -185,6 +185,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(&self, state: &mut H) { self.expr().hash(state); diff --git a/zenoh/src/net/routing/interceptor/mod.rs b/zenoh/src/net/routing/interceptor/mod.rs index ef8e6e0fb1..d7a5fc63f3 100644 --- a/zenoh/src/net/routing/interceptor/mod.rs +++ b/zenoh/src/net/routing/interceptor/mod.rs @@ -158,6 +158,8 @@ impl InterceptorTrait for ComputeOnMiss { } } +#[allow(dead_code)] + pub(crate) struct IngressMsgLogger {} impl InterceptorTrait for IngressMsgLogger { @@ -185,6 +187,8 @@ impl InterceptorTrait for IngressMsgLogger { Some(ctx) } } + +#[allow(dead_code)] pub(crate) struct EgressMsgLogger {} impl InterceptorTrait for EgressMsgLogger { @@ -212,6 +216,7 @@ impl InterceptorTrait for EgressMsgLogger { } } +#[allow(dead_code)] pub(crate) struct LoggerInterceptor {} impl InterceptorFactoryTrait for LoggerInterceptor { diff --git a/zenoh/src/plugins/sealed.rs b/zenoh/src/plugins/sealed.rs index 8bfc1f1dab..1c6d752abf 100644 --- a/zenoh/src/plugins/sealed.rs +++ b/zenoh/src/plugins/sealed.rs @@ -93,13 +93,14 @@ pub trait RunningPluginTrait: Send + Sync + PluginControl { /// Thus the plugin can reply its contribution to the global admin space of this zenohd. /// Parameters: /// * `selector`: the full selector of the query (usually only key_expr part is used). This selector is - /// exactly the same as it was requested by user, for example "@/router/ROUTER_ID/plugins/PLUGIN_NAME/some/plugin/info" or "@/router/*/plugins/*/foo/bar". - /// But the plugin's [RunningPluginTrait::adminspace_getter] is called only if the selector matches the `plugin_status_key` + /// exactly the same as it was requested by user, for example "@/router/ROUTER_ID/plugins/PLUGIN_NAME/some/plugin/info" or "@/router/*/plugins/*/foo/bar". + /// But the plugin's [RunningPluginTrait::adminspace_getter] is called only if the selector matches the `plugin_status_key` /// * `plugin_status_key`: the actual path to plugin's status in the admin space. For example "@/router/ROUTER_ID/plugins/PLUGIN_NAME" + /// /// Returns value: /// * `Ok(Vec)`: 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/ROUTER_ID/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/ROUTER_ID/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. diff --git a/zenoh/src/session.rs b/zenoh/src/session.rs index 0763018c75..95366c9216 100644 --- a/zenoh/src/session.rs +++ b/zenoh/src/session.rs @@ -2003,7 +2003,7 @@ impl<'s> SessionDeclarations<'s, 'static> for Arc { /// # Arguments /// /// * `key_expr` - The key expression matching the queries the - /// [`Queryable`](Queryable) will reply to + /// [`Queryable`](Queryable) will reply to /// /// # Examples /// ```no_run @@ -2602,7 +2602,7 @@ pub trait SessionDeclarations<'s, 'a> { /// # Arguments /// /// * `key_expr` - The key expression matching the queries the - /// [`Queryable`](crate::queryable::Queryable) will reply to + /// [`Queryable`](crate::queryable::Queryable) will reply to /// /// # Examples /// ```no_run diff --git a/zenohd/src/main.rs b/zenohd/src/main.rs index c32c7d15ca..bcd57f3735 100644 --- a/zenohd/src/main.rs +++ b/zenohd/src/main.rs @@ -81,9 +81,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, /// Configure the read and/or write permissions on the admin space. Default is read only.