From f6d10e55951ccbec1867cdbdaadf49a861388bc3 Mon Sep 17 00:00:00 2001 From: Piotr Czarnecki Date: Tue, 16 Jul 2024 23:21:02 +0200 Subject: [PATCH 1/3] Enable some clippy lints --- src/lib.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4266fff..d6e641f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -85,6 +85,10 @@ #![doc(html_root_url = "https://docs.rs/bit-vec/0.8.0")] #![no_std] +#![forbid(clippy::shadow_reuse)] +#![forbid(clippy::shadow_same)] +#![forbid(clippy::shadow_unrelated)] + #[cfg(any(test, feature = "std"))] #[macro_use] extern crate std; @@ -1830,11 +1834,10 @@ pub struct IterMut<'a, B: 'a + BitBlock = u32> { impl<'a, B: 'a + BitBlock> IterMut<'a, B> { fn get(&mut self, index: Option) -> Option> { - let index = index?; - let value = (*self.vec).borrow().get(index)?; + let value = (*self.vec).borrow().get(index?)?; Some(MutBorrowedBit { vec: self.vec.clone(), - index, + index: index?, #[cfg(debug_assertions)] old_value: value, new_value: value, From eeac031ef95d36973144afae49fa95d92ad1e696 Mon Sep 17 00:00:00 2001 From: Piotr Czarnecki Date: Sun, 1 Dec 2024 21:29:01 +0100 Subject: [PATCH 2/3] Fix clippy warnings for elidable lifetimes --- src/lib.rs | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d6e641f..6eb2393 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -85,9 +85,9 @@ #![doc(html_root_url = "https://docs.rs/bit-vec/0.8.0")] #![no_std] -#![forbid(clippy::shadow_reuse)] -#![forbid(clippy::shadow_same)] -#![forbid(clippy::shadow_unrelated)] +#![deny(clippy::shadow_reuse)] +#![deny(clippy::shadow_same)] +#![deny(clippy::shadow_unrelated)] #[cfg(any(test, feature = "std"))] #[macro_use] @@ -1845,7 +1845,7 @@ impl<'a, B: 'a + BitBlock> IterMut<'a, B> { } } -impl<'a, B: BitBlock> Deref for MutBorrowedBit<'a, B> { +impl Deref for MutBorrowedBit<'_, B> { type Target = bool; fn deref(&self) -> &Self::Target { @@ -1853,13 +1853,13 @@ impl<'a, B: BitBlock> Deref for MutBorrowedBit<'a, B> { } } -impl<'a, B: BitBlock> DerefMut for MutBorrowedBit<'a, B> { +impl DerefMut for MutBorrowedBit<'_, B> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.new_value } } -impl<'a, B: BitBlock> Drop for MutBorrowedBit<'a, B> { +impl Drop for MutBorrowedBit<'_, B> { fn drop(&mut self) { let mut vec = (*self.vec).borrow_mut(); #[cfg(debug_assertions)] @@ -1872,7 +1872,7 @@ impl<'a, B: BitBlock> Drop for MutBorrowedBit<'a, B> { } } -impl<'a, B: BitBlock> Iterator for Iter<'a, B> { +impl Iterator for Iter<'_, B> { type Item = bool; #[inline] @@ -1901,14 +1901,14 @@ impl<'a, B: BitBlock> Iterator for IterMut<'a, B> { } } -impl<'a, B: BitBlock> DoubleEndedIterator for Iter<'a, B> { +impl DoubleEndedIterator for Iter<'_, B> { #[inline] fn next_back(&mut self) -> Option { self.range.next_back().map(|i| self.bit_vec.get(i).unwrap()) } } -impl<'a, B: BitBlock> DoubleEndedIterator for IterMut<'a, B> { +impl DoubleEndedIterator for IterMut<'_, B> { #[inline] fn next_back(&mut self) -> Option { let index = self.range.next_back(); @@ -1916,9 +1916,9 @@ impl<'a, B: BitBlock> DoubleEndedIterator for IterMut<'a, B> { } } -impl<'a, B: BitBlock> ExactSizeIterator for Iter<'a, B> {} +impl ExactSizeIterator for Iter<'_, B> {} -impl<'a, B: BitBlock> ExactSizeIterator for IterMut<'a, B> {} +impl ExactSizeIterator for IterMut<'_, B> {} impl<'a, B: BitBlock> IntoIterator for &'a BitVec { type Item = bool; @@ -1973,7 +1973,7 @@ pub struct Blocks<'a, B: 'a> { iter: slice::Iter<'a, B>, } -impl<'a, B: BitBlock> Iterator for Blocks<'a, B> { +impl Iterator for Blocks<'_, B> { type Item = B; #[inline] @@ -1987,17 +1987,21 @@ impl<'a, B: BitBlock> Iterator for Blocks<'a, B> { } } -impl<'a, B: BitBlock> DoubleEndedIterator for Blocks<'a, B> { +impl DoubleEndedIterator for Blocks<'_, B> { #[inline] fn next_back(&mut self) -> Option { self.iter.next_back().cloned() } } -impl<'a, B: BitBlock> ExactSizeIterator for Blocks<'a, B> {} +impl ExactSizeIterator for Blocks<'_, B> {} #[cfg(test)] mod tests { + #![allow(clippy::shadow_reuse)] + #![allow(clippy::shadow_same)] + #![allow(clippy::shadow_unrelated)] + use super::{BitVec, Iter, Vec}; // This is stupid, but I want to differentiate from a "random" 32 From cf05c09b839cefc1d6acd09a47dc0723377f8711 Mon Sep 17 00:00:00 2001 From: Piotr Czarnecki Date: Sun, 1 Dec 2024 21:45:03 +0100 Subject: [PATCH 3/3] Formatting --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 6eb2393..6349f55 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -84,7 +84,6 @@ #![doc(html_root_url = "https://docs.rs/bit-vec/0.8.0")] #![no_std] - #![deny(clippy::shadow_reuse)] #![deny(clippy::shadow_same)] #![deny(clippy::shadow_unrelated)]