Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable some clippy lints #110

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@

#![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)]

#[cfg(any(test, feature = "std"))]
#[macro_use]
Expand Down Expand Up @@ -1830,33 +1833,32 @@ pub struct IterMut<'a, B: 'a + BitBlock = u32> {

impl<'a, B: 'a + BitBlock> IterMut<'a, B> {
fn get(&mut self, index: Option<usize>) -> Option<MutBorrowedBit<'a, B>> {
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,
})
}
}

impl<'a, B: BitBlock> Deref for MutBorrowedBit<'a, B> {
impl<B: BitBlock> Deref for MutBorrowedBit<'_, B> {
type Target = bool;

fn deref(&self) -> &Self::Target {
&self.new_value
}
}

impl<'a, B: BitBlock> DerefMut for MutBorrowedBit<'a, B> {
impl<B: BitBlock> 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<B: BitBlock> Drop for MutBorrowedBit<'_, B> {
fn drop(&mut self) {
let mut vec = (*self.vec).borrow_mut();
#[cfg(debug_assertions)]
Expand All @@ -1869,7 +1871,7 @@ impl<'a, B: BitBlock> Drop for MutBorrowedBit<'a, B> {
}
}

impl<'a, B: BitBlock> Iterator for Iter<'a, B> {
impl<B: BitBlock> Iterator for Iter<'_, B> {
type Item = bool;

#[inline]
Expand Down Expand Up @@ -1898,24 +1900,24 @@ impl<'a, B: BitBlock> Iterator for IterMut<'a, B> {
}
}

impl<'a, B: BitBlock> DoubleEndedIterator for Iter<'a, B> {
impl<B: BitBlock> DoubleEndedIterator for Iter<'_, B> {
#[inline]
fn next_back(&mut self) -> Option<bool> {
self.range.next_back().map(|i| self.bit_vec.get(i).unwrap())
}
}

impl<'a, B: BitBlock> DoubleEndedIterator for IterMut<'a, B> {
impl<B: BitBlock> DoubleEndedIterator for IterMut<'_, B> {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> {
let index = self.range.next_back();
self.get(index)
}
}

impl<'a, B: BitBlock> ExactSizeIterator for Iter<'a, B> {}
impl<B: BitBlock> ExactSizeIterator for Iter<'_, B> {}

impl<'a, B: BitBlock> ExactSizeIterator for IterMut<'a, B> {}
impl<B: BitBlock> ExactSizeIterator for IterMut<'_, B> {}

impl<'a, B: BitBlock> IntoIterator for &'a BitVec<B> {
type Item = bool;
Expand Down Expand Up @@ -1970,7 +1972,7 @@ pub struct Blocks<'a, B: 'a> {
iter: slice::Iter<'a, B>,
}

impl<'a, B: BitBlock> Iterator for Blocks<'a, B> {
impl<B: BitBlock> Iterator for Blocks<'_, B> {
type Item = B;

#[inline]
Expand All @@ -1984,17 +1986,21 @@ impl<'a, B: BitBlock> Iterator for Blocks<'a, B> {
}
}

impl<'a, B: BitBlock> DoubleEndedIterator for Blocks<'a, B> {
impl<B: BitBlock> DoubleEndedIterator for Blocks<'_, B> {
#[inline]
fn next_back(&mut self) -> Option<B> {
self.iter.next_back().cloned()
}
}

impl<'a, B: BitBlock> ExactSizeIterator for Blocks<'a, B> {}
impl<B: BitBlock> 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
Expand Down
Loading