From f397ec7d3a6ae8c6923a3d4feec3283a82c0a0c2 Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Thu, 17 Oct 2024 07:41:39 +0000 Subject: [PATCH] Fix Clippy errors from Rust 1.82.0 It is possible to preview unreleased rust versions like so: ```console RUSTUP_DIST_SERVER=https://dev-static.rust-lang.org rustup install 1.82.0 ``` --- commons/zenoh-buffers/src/lib.rs | 16 ++++++++++------ .../zenoh-keyexpr/src/key_expr/format/support.rs | 6 +++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/commons/zenoh-buffers/src/lib.rs b/commons/zenoh-buffers/src/lib.rs index 1024958892..5684af7d4f 100644 --- a/commons/zenoh-buffers/src/lib.rs +++ b/commons/zenoh-buffers/src/lib.rs @@ -59,17 +59,21 @@ macro_rules! unsafe_slice_mut { #[cfg(all(not(test), not(feature = "test")))] #[macro_export] macro_rules! unsafe_slice { - ($s:expr,$r:expr) => { - unsafe { $s.get_unchecked($r) } - }; + ($s:expr,$r:expr) => {{ + let slice = &*$s; + let index = $r; + unsafe { slice.get_unchecked(index) } + }}; } #[cfg(all(not(test), not(feature = "test")))] #[macro_export] macro_rules! unsafe_slice_mut { - ($s:expr,$r:expr) => { - unsafe { $s.get_unchecked_mut($r) } - }; + ($s:expr,$r:expr) => {{ + let slice = &mut *$s; + let index = $r; + unsafe { slice.get_unchecked_mut(index) } + }}; } pub mod buffer { diff --git a/commons/zenoh-keyexpr/src/key_expr/format/support.rs b/commons/zenoh-keyexpr/src/key_expr/format/support.rs index 16451797aa..65b534dc24 100644 --- a/commons/zenoh-keyexpr/src/key_expr/format/support.rs +++ b/commons/zenoh-keyexpr/src/key_expr/format/support.rs @@ -246,7 +246,11 @@ impl<'s> IKeFormatStorage<'s> for Vec> { constructor: IterativeConstructor, segment: Segment<'s>, ) -> IterativeConstructor { - let IterativeConstructor::Complete(mut this) = constructor else { + // NOTE(fuzzypixelz): Rust 1.82.0 can detect that this pattern is irrefutable but that's not + // necessarily the case for prior versions. Thus we silence this lint to keep the MSRV minimal. + #[allow(irrefutable_let_patterns)] + let IterativeConstructor::Complete(mut this) = constructor + else { unsafe { core::hint::unreachable_unchecked() } }; this.push(segment);