Skip to content

Commit

Permalink
Apply Clippy lints from Rust 1.78 (#1020)
Browse files Browse the repository at this point in the history
* fix: Add step to update Stable Rust toolchain

When GitHub runners images update their Rust stable channel,
this update may not be propagated to all runners at the same time.

In such a case CI jobs will use different Rust versions which leads to inconsistent behavior.

* fix: Apply clippy lints

* fix: Restore deleted `utfdbg` macro

* fix: Workaround `clippy:assigning_clones` in `KeyExprFuzzer`
  • Loading branch information
fuzzypixelz committed May 14, 2024
1 parent 45e05f0 commit c853eba
Show file tree
Hide file tree
Showing 30 changed files with 60 additions and 168 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ jobs:
- name: Setup rust-cache
uses: Swatinem/rust-cache@v2

- name: Update Stable Rust toolchain
run: rustup update stable

- name: Install dependencies
run: cargo +stable install cargo-deny --locked

Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ members = [
exclude = ["ci/nostd-check", "ci/valgrind-check"]

[workspace.package]
rust-version = "1.66.1"
rust-version = "1.72.0"
version = "0.11.0-dev" # Zenoh version
repository = "https://github.com/eclipse-zenoh/zenoh"
homepage = "http://zenoh.io"
Expand Down Expand Up @@ -91,7 +91,7 @@ crc = "3.0.1"
criterion = "0.5"
derive_more = "0.99.17"
derive-new = "0.6.0"
tracing-subscriber = {version = "0.3", features = ["json", "env-filter"]}
tracing-subscriber = { version = "0.3", features = ["json", "env-filter"] }
tracing-loki = "0.2"
event-listener = "4.0.0"
flume = "0.11"
Expand Down
12 changes: 12 additions & 0 deletions commons/zenoh-codec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ pub trait LCodec<Message> {
#[derive(Clone, Copy)]
pub struct Zenoh080;

impl Default for Zenoh080 {
fn default() -> Self {
Self::new()
}
}

impl Zenoh080 {
pub const fn new() -> Self {
Self
Expand Down Expand Up @@ -119,6 +125,12 @@ pub struct Zenoh080Bounded<T> {
_t: PhantomData<T>,
}

impl<T> Default for Zenoh080Bounded<T> {
fn default() -> Self {
Self::new()
}
}

impl<T> Zenoh080Bounded<T> {
pub const fn new() -> Self {
Self { _t: PhantomData }
Expand Down
6 changes: 6 additions & 0 deletions commons/zenoh-codec/src/transport/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ pub struct Zenoh080Batch {
pub latest_sn: LatestSn,
}

impl Default for Zenoh080Batch {
fn default() -> Self {
Self::new()
}
}

impl Zenoh080Batch {
pub const fn new() -> Self {
Self {
Expand Down
4 changes: 2 additions & 2 deletions commons/zenoh-keyexpr/src/key_expr/fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ impl<Rng: rand::Rng> Iterator for KeyExprFuzzer<Rng> {
let mut next = Vec::new();
make(&mut next, &mut self.0);
let mut next = String::from_utf8(next).unwrap();
if let Some(n) = next.strip_prefix('/') {
next = n.to_owned()
if let Some(n) = next.strip_prefix('/').map(ToOwned::to_owned) {
next = n
}
Some(OwnedKeyExpr::autocanonize(next).unwrap())
}
Expand Down
30 changes: 5 additions & 25 deletions commons/zenoh-keyexpr/src/key_expr/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// Contributors:
// ZettaScale Zenoh Team, <zenoh@zettascale.tech>
//
use core::{ptr, str};
use core::ptr;

pub(crate) struct Writer {
pub ptr: *mut u8,
Expand Down Expand Up @@ -118,7 +118,6 @@ impl<'a, S: Split<D> + ?Sized, D: ?Sized> DoubleEndedIterator for Splitter<'a, S
pub trait Split<Delimiter: ?Sized> {
fn split_once<'a>(&'a self, delimiter: &Delimiter) -> (&'a Self, &'a Self);
fn try_split_once<'a>(&'a self, delimiter: &Delimiter) -> (&'a Self, Option<&'a Self>);
fn rsplit_once<'a>(&'a self, delimiter: &Delimiter) -> (&'a Self, &'a Self);
fn try_rsplit_once<'a>(&'a self, delimiter: &Delimiter) -> (Option<&'a Self>, &'a Self);
fn splitter<'a>(&'a self, delimiter: &'a Delimiter) -> Splitter<'a, Self, Delimiter> {
Splitter {
Expand All @@ -134,12 +133,6 @@ impl Split<u8> for [u8] {
None => (self, &[]),
}
}
fn rsplit_once<'a>(&'a self, delimiter: &u8) -> (&'a Self, &'a Self) {
match self.iter().rposition(|c| c == delimiter) {
Some(i) => (&self[..i], &self[(i + 1)..]),
None => (&[], self),
}
}

fn try_split_once<'a>(&'a self, delimiter: &u8) -> (&'a Self, Option<&'a Self>) {
match self.iter().position(|c| c == delimiter) {
Expand All @@ -164,14 +157,6 @@ impl Split<[u8]> for [u8] {
}
(self, &[])
}
fn rsplit_once<'a>(&'a self, delimiter: &[u8]) -> (&'a Self, &'a Self) {
for i in (0..self.len()).rev() {
if self[..i].ends_with(delimiter) {
return (&self[..(i - delimiter.len())], &self[i..]);
}
}
(&[], self)
}

fn try_split_once<'a>(&'a self, delimiter: &[u8]) -> (&'a Self, Option<&'a Self>) {
for i in 0..self.len() {
Expand Down Expand Up @@ -200,14 +185,6 @@ impl<const N: usize> Split<[u8; N]> for [u8] {
}
(self, &[])
}
fn rsplit_once<'a>(&'a self, delimiter: &[u8; N]) -> (&'a Self, &'a Self) {
for i in (0..self.len()).rev() {
if self[..i].ends_with(delimiter) {
return (&self[..(i - delimiter.len())], &self[i..]);
}
}
(&[], self)
}

fn try_split_once<'a>(&'a self, delimiter: &[u8; N]) -> (&'a Self, Option<&'a Self>) {
for i in 0..self.len() {
Expand All @@ -228,12 +205,15 @@ impl<const N: usize> Split<[u8; N]> for [u8] {
}
}

#[allow(dead_code)]
pub(crate) trait Utf {
fn utf(&self) -> &str;
}

#[allow(dead_code)]
impl Utf for [u8] {
fn utf(&self) -> &str {
unsafe { str::from_utf8_unchecked(self) }
unsafe { ::core::str::from_utf8_unchecked(self) }
}
}
/// This macro is generally useful when introducing new matchers to debug them.
Expand Down
26 changes: 1 addition & 25 deletions commons/zenoh-keyexpr/src/keyexpr_tree/box_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ use alloc::string::String;
use core::ptr::NonNull;

use crate::keyexpr;
use crate::keyexpr_tree::{
support::{IWildness, NonWild, UnknownWildness},
*,
};
use crate::keyexpr_tree::{support::IWildness, *};

use super::impls::KeyedSetProvider;
use super::support::IterOrOption;

/// A fully owned KeTree.
Expand Down Expand Up @@ -402,26 +398,6 @@ impl<Weight, Wildness: IWildness, Children: IChildrenProvider<Box<Self>>> AsMut<
}
}

trait TransmuteInto<T> {
fn transmute_into(self) -> T;
}
impl<'a, Weight: 'static>
TransmuteInto<&'a mut KeyExprTreeNode<Weight, UnknownWildness, KeyedSetProvider>>
for &'a mut KeyExprTreeNode<Weight, NonWild, KeyedSetProvider>
{
fn transmute_into(self) -> &'a mut KeyExprTreeNode<Weight, UnknownWildness, KeyedSetProvider> {
unsafe { core::mem::transmute(self) }
}
}
impl<'a, Weight: 'static>
TransmuteInto<&'a KeyExprTreeNode<Weight, UnknownWildness, KeyedSetProvider>>
for &'a KeyExprTreeNode<Weight, NonWild, KeyedSetProvider>
{
fn transmute_into(self) -> &'a KeyExprTreeNode<Weight, UnknownWildness, KeyedSetProvider> {
unsafe { core::mem::transmute(self) }
}
}

impl<
'a,
K: AsRef<keyexpr>,
Expand Down
6 changes: 3 additions & 3 deletions commons/zenoh-keyexpr/src/keyexpr_tree/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ fn test_keyset<K: Deref<Target = keyexpr> + Debug>(keys: &[K]) {
assert!(expected.insert(k, v).is_none());
}
}
exclone = expected.clone();
exclone.clone_from(&expected);
for node in tree.included_nodes(target) {
let ke = node.keyexpr();
let weight = node.weight();
Expand Down Expand Up @@ -203,7 +203,7 @@ fn test_keyset<K: Deref<Target = keyexpr> + Debug>(keys: &[K]) {
assert!(expected.insert(k, v).is_none());
}
}
exclone = expected.clone();
exclone.clone_from(&expected);
for node in tree.nodes_including(dbg!(target)) {
let ke = node.keyexpr();
let weight = node.weight();
Expand Down Expand Up @@ -302,7 +302,7 @@ fn test_keyset_vec<K: Deref<Target = keyexpr>>(keys: &[K]) {
assert!(expected.insert(k, v).is_none());
}
}
exclone = expected.clone();
exclone.clone_from(&expected);
for node in tree.included_nodes(target) {
let ke = node.keyexpr();
let weight = node.weight();
Expand Down
6 changes: 6 additions & 0 deletions commons/zenoh-protocol/src/common/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ pub struct DidntConvert;
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct ZExtUnit<const ID: u8>;

impl<const ID: u8> Default for ZExtUnit<{ ID }> {
fn default() -> Self {
Self::new()
}
}

impl<const ID: u8> ZExtUnit<{ ID }> {
pub const ID: u8 = ID;

Expand Down
6 changes: 6 additions & 0 deletions commons/zenoh-protocol/src/zenoh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ pub mod ext {
Self
}
}
#[cfg(feature = "shared-memory")]
impl<const ID: u8> Default for ShmType<{ ID }> {
fn default() -> Self {
Self::new()
}
}

/// 7 6 5 4 3 2 1 0
/// +-+-+-+-+-+-+-+-+
Expand Down
5 changes: 0 additions & 5 deletions io/zenoh-transport/src/unicast/lowlatency/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,6 @@ impl TransportUnicastTrait for TransportUnicastLowlatency {
/*************************************/
/* TERMINATION */
/*************************************/
async fn close_link(&self, link: Link, reason: u8) -> ZResult<()> {
tracing::trace!("Closing link {} with peer: {}", link, self.config.zid);
self.finalize(reason).await
}

async fn close(&self, reason: u8) -> ZResult<()> {
tracing::trace!("Closing transport with peer: {}", self.config.zid);
self.finalize(reason).await
Expand Down
1 change: 0 additions & 1 deletion io/zenoh-transport/src/unicast/transport_unicast_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ pub(crate) trait TransportUnicastTrait: Send + Sync {
/*************************************/
/* TERMINATION */
/*************************************/
async fn close_link(&self, link: Link, reason: u8) -> ZResult<()>;
async fn close(&self, reason: u8) -> ZResult<()>;

fn add_debug_fields<'a, 'b: 'a, 'c>(
Expand Down
28 changes: 0 additions & 28 deletions io/zenoh-transport/src/unicast/universal/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ use zenoh_protocol::{
};
use zenoh_result::{bail, zerror, ZResult};

macro_rules! zlinkget {
($guard:expr, $link:expr) => {
// Compare LinkUnicast link to not compare TransportLinkUnicast direction
$guard.iter().find(|tl| tl.link == $link)
};
}

macro_rules! zlinkindex {
($guard:expr, $link:expr) => {
// Compare LinkUnicast link to not compare TransportLinkUnicast direction
Expand Down Expand Up @@ -356,27 +349,6 @@ impl TransportUnicastTrait for TransportUnicastUniversal {
/*************************************/
/* TERMINATION */
/*************************************/
async fn close_link(&self, link: Link, reason: u8) -> ZResult<()> {
tracing::trace!("Closing link {} with peer: {}", link, self.config.zid);

let transport_link_pipeline = zlinkget!(zread!(self.links), link)
.ok_or_else(|| zerror!("Cannot close Link {:?}: not found", link))?
.pipeline
.clone();

// Close message to be sent on the target link
let msg: TransportMessage = Close {
reason,
session: false,
}
.into();

transport_link_pipeline.push_transport_message(msg, Priority::Background);

// Remove the link from the channel
self.del_link(link).await
}

async fn close(&self, reason: u8) -> ZResult<()> {
tracing::trace!("Closing transport with peer: {}", self.config.zid);

Expand Down
1 change: 0 additions & 1 deletion plugins/zenoh-backend-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ pub enum History {
All,
}

///
pub enum StorageInsertionResult {
Outdated,
Inserted,
Expand Down
20 changes: 0 additions & 20 deletions plugins/zenoh-plugin-rest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,26 +193,6 @@ fn response(status: StatusCode, content_type: impl TryInto<Mime>, body: &str) ->
zenoh_plugin_trait::declare_plugin!(RestPlugin);

pub struct RestPlugin {}
#[derive(Clone, Copy, Debug)]
struct StrError {
err: &'static str,
}
impl std::error::Error for StrError {}
impl std::fmt::Display for StrError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.err)
}
}
#[derive(Debug, Clone)]
struct StringError {
err: String,
}
impl std::error::Error for StringError {}
impl std::fmt::Display for StringError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.err)
}
}

impl ZenohPlugin for RestPlugin {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ impl AlignQueryable {
fn parse_selector(&self, selector: Selector) -> Option<AlignComponent> {
let properties = selector.parameters_stringmap().unwrap(); // note: this is a hashmap
tracing::trace!("[ALIGN QUERYABLE] Properties are: {:?}", properties);
if properties.get(super::ERA).is_some() {
if properties.contains_key(super::ERA) {
Some(AlignComponent::Era(
EraType::from_str(properties.get(super::ERA).unwrap()).unwrap(),
))
} else if properties.get(super::INTERVALS).is_some() {
} else if properties.contains_key(super::INTERVALS) {
let mut intervals = properties.get(super::INTERVALS).unwrap().to_string();
intervals.remove(0);
intervals.pop();
Expand All @@ -191,7 +191,7 @@ impl AlignQueryable {
.map(|x| x.parse::<u64>().unwrap())
.collect::<Vec<u64>>(),
))
} else if properties.get(super::SUBINTERVALS).is_some() {
} else if properties.contains_key(super::SUBINTERVALS) {
let mut subintervals = properties.get(super::SUBINTERVALS).unwrap().to_string();
subintervals.remove(0);
subintervals.pop();
Expand All @@ -201,7 +201,7 @@ impl AlignQueryable {
.map(|x| x.parse::<u64>().unwrap())
.collect::<Vec<u64>>(),
))
} else if properties.get(super::CONTENTS).is_some() {
} else if properties.contains_key(super::CONTENTS) {
let contents = serde_json::from_str(properties.get(super::CONTENTS).unwrap()).unwrap();
Some(AlignComponent::Contents(contents))
} else {
Expand Down
4 changes: 0 additions & 4 deletions zenoh/src/net/primitives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ pub(crate) trait EPrimitives: Send + Sync {
fn send_response(&self, ctx: RoutingContext<Response>);

fn send_response_final(&self, ctx: RoutingContext<ResponseFinal>);

fn send_close(&self);
}

#[derive(Default)]
Expand Down Expand Up @@ -80,8 +78,6 @@ impl EPrimitives for DummyPrimitives {

fn send_response_final(&self, _ctx: RoutingContext<ResponseFinal>) {}

fn send_close(&self) {}

fn as_any(&self) -> &dyn Any {
self
}
Expand Down

0 comments on commit c853eba

Please sign in to comment.