From 38784b39739ce22c6ec1024a53adf6d1eb6eac17 Mon Sep 17 00:00:00 2001 From: Piotr Czarnecki Date: Tue, 16 Jul 2024 22:08:02 +0200 Subject: [PATCH 1/2] Forbid shadowing --- src/lib.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 30bf8ce..2824cb6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,6 +49,9 @@ //! assert!(bv[3]); //! ``` #![doc(html_root_url = "https://docs.rs/bit-set/0.8.0")] +#![forbid(clippy::shadow_reuse)] +#![forbid(clippy::shadow_same)] +#![forbid(clippy::shadow_unrelated)] #![no_std] extern crate bit_vec; @@ -986,15 +989,16 @@ impl<'a, B: BitBlock> Iterator for TwoBitPositions<'a, B> { #[inline] fn size_hint(&self) -> (usize, Option) { - let (a, au) = self.set.size_hint(); - let (b, bu) = self.other.size_hint(); + let (first_lower_bound, first_upper_bound) = self.set.size_hint(); + let (second_lower_bound, second_upper_bound) = self.other.size_hint(); - let upper = match (au, bu) { - (Some(au), Some(bu)) => Some(cmp::max(au, bu)), - _ => None, - }; + let upper_bound = first_upper_bound.zip(second_upper_bound); - (cmp::max(a, b), upper) + let get_max = |(a, b)| cmp::max(a, b); + ( + cmp::max(first_lower_bound, second_lower_bound), + upper_bound.map(get_max), + ) } } From 99b84c75811deb30a9c3ebb511de6498bbc87006 Mon Sep 17 00:00:00 2001 From: Piotr Czarnecki Date: Sun, 1 Dec 2024 08:49:01 +0100 Subject: [PATCH 2/2] Deny shadowing with exception for tests --- src/lib.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2824cb6..cc1f3d3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,9 +49,9 @@ //! assert!(bv[3]); //! ``` #![doc(html_root_url = "https://docs.rs/bit-set/0.8.0")] -#![forbid(clippy::shadow_reuse)] -#![forbid(clippy::shadow_same)] -#![forbid(clippy::shadow_unrelated)] +#![deny(clippy::shadow_reuse)] +#![deny(clippy::shadow_same)] +#![deny(clippy::shadow_unrelated)] #![no_std] extern crate bit_vec; @@ -975,7 +975,7 @@ where } } -impl<'a, B: BitBlock> Iterator for TwoBitPositions<'a, B> { +impl Iterator for TwoBitPositions<'_, B> { type Item = B; fn next(&mut self) -> Option { @@ -1002,7 +1002,7 @@ impl<'a, B: BitBlock> Iterator for TwoBitPositions<'a, B> { } } -impl<'a, B: BitBlock> Iterator for Iter<'a, B> { +impl Iterator for Iter<'_, B> { type Item = usize; #[inline] @@ -1019,7 +1019,7 @@ impl<'a, B: BitBlock> Iterator for Iter<'a, B> { } } -impl<'a, B: BitBlock> Iterator for Union<'a, B> { +impl Iterator for Union<'_, B> { type Item = usize; #[inline] @@ -1036,7 +1036,7 @@ impl<'a, B: BitBlock> Iterator for Union<'a, B> { } } -impl<'a, B: BitBlock> Iterator for Intersection<'a, B> { +impl Iterator for Intersection<'_, B> { type Item = usize; #[inline] @@ -1063,7 +1063,7 @@ impl<'a, B: BitBlock> Iterator for Intersection<'a, B> { } } -impl<'a, B: BitBlock> Iterator for Difference<'a, B> { +impl Iterator for Difference<'_, B> { type Item = usize; #[inline] @@ -1080,7 +1080,7 @@ impl<'a, B: BitBlock> Iterator for Difference<'a, B> { } } -impl<'a, B: BitBlock> Iterator for SymmetricDifference<'a, B> { +impl Iterator for SymmetricDifference<'_, B> { type Item = usize; #[inline] @@ -1108,6 +1108,10 @@ impl<'a, B: BitBlock> IntoIterator for &'a BitSet { #[cfg(test)] mod tests { + #![allow(clippy::shadow_reuse)] + #![allow(clippy::shadow_same)] + #![allow(clippy::shadow_unrelated)] + use super::BitSet; use bit_vec::BitVec; use std::cmp::Ordering::{Equal, Greater, Less};