Skip to content

Commit

Permalink
Clippy lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
haxelion committed Jan 11, 2025
1 parent 06e799e commit 62fcb1a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
25 changes: 12 additions & 13 deletions src/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,14 @@ impl BitVector for Bvd {
match endianness {
Endianness::Little => {
for i in 0..num_bytes {
buf[i] = (self.data[i / Self::BYTE_UNIT] >> ((i % Self::BYTE_UNIT) * 8) & 0xff)
buf[i] = ((self.data[i / Self::BYTE_UNIT] >> ((i % Self::BYTE_UNIT) * 8)) & 0xff)
as u8;
}
}
Endianness::Big => {
for i in 0..num_bytes {
buf[num_bytes - i - 1] = (self.data[i / Self::BYTE_UNIT]
>> ((i % Self::BYTE_UNIT) * 8)
& 0xff) as u8;
buf[num_bytes - i - 1] = ((self.data[i / Self::BYTE_UNIT]
>> ((i % Self::BYTE_UNIT) * 8)) & 0xff) as u8;
}
}
}
Expand All @@ -313,12 +312,12 @@ impl BitVector for Bvd {
}

fn write<W: Write>(&self, writer: &mut W, endianness: Endianness) -> std::io::Result<()> {
return writer.write_all(self.to_vec(endianness).as_slice());
writer.write_all(self.to_vec(endianness).as_slice())
}

fn get(&self, index: usize) -> Bit {
debug_assert!(index < self.length);
(self.data[index / Self::BIT_UNIT] >> (index % Self::BIT_UNIT) & 1).into()
((self.data[index / Self::BIT_UNIT] >> (index % Self::BIT_UNIT)) & 1).into()
}

fn set(&mut self, index: usize, bit: Bit) {
Expand Down Expand Up @@ -446,15 +445,15 @@ impl BitVector for Bvd {
fn shl_in(&mut self, bit: Bit) -> Bit {
let mut carry = bit;
for i in 0..(self.length / Self::BIT_UNIT) {
let b = self.data[i] >> (Self::BIT_UNIT - 1) & 1;
self.data[i] = self.data[i] << 1 | carry as u64;
let b = (self.data[i] >> (Self::BIT_UNIT - 1)) & 1;
self.data[i] = (self.data[i] << 1) | carry as u64;
carry = b.into();
}
if self.length % Self::BIT_UNIT != 0 {
let i = self.length / Self::BIT_UNIT;
let b = self.data[i] >> (self.length % Self::BIT_UNIT - 1) & 1;
let b = (self.data[i] >> (self.length % Self::BIT_UNIT - 1)) & 1;
self.data[i] =
(self.data[i] << 1 | carry as u64) & u64::mask(self.length % Self::BIT_UNIT);
((self.data[i] << 1) | carry as u64) & u64::mask(self.length % Self::BIT_UNIT);
carry = b.into();
}
carry
Expand All @@ -465,12 +464,12 @@ impl BitVector for Bvd {
if self.length % Self::BIT_UNIT != 0 {
let i = self.length / Self::BIT_UNIT;
let b = self.data[i] & 1;
self.data[i] = self.data[i] >> 1 | (carry as u64) << (self.length % Self::BIT_UNIT - 1);
self.data[i] = (self.data[i] >> 1) | ((carry as u64) << (self.length % Self::BIT_UNIT - 1));
carry = b.into();
}
for i in (0..(self.length / Self::BIT_UNIT)).rev() {
let b = self.data[i] & 1;
self.data[i] = self.data[i] >> 1 | (carry as u64) << (Self::BIT_UNIT - 1);
self.data[i] = (self.data[i] >> 1) | ((carry as u64) << (Self::BIT_UNIT - 1));
carry = b.into();
}
carry
Expand Down Expand Up @@ -725,7 +724,7 @@ impl fmt::Octal for Bvd {
while let Some(b0) = it.next() {
let b1 = it.next().unwrap_or(Bit::Zero);
let b2 = it.next().unwrap_or(Bit::Zero);
let octet = (b2 as u8) << 2 | (b1 as u8) << 1 | b0 as u8;
let octet = ((b2 as u8) << 2) | ((b1 as u8) << 1) | b0 as u8;
if octet != 0 {
last_nz = s.len();
}
Expand Down
18 changes: 9 additions & 9 deletions src/fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,12 @@ where
writer: &mut W,
endianness: Endianness,
) -> std::io::Result<()> {
return writer.write_all(self.to_vec(endianness).as_slice());
writer.write_all(self.to_vec(endianness).as_slice())
}

fn get(&self, index: usize) -> Bit {
debug_assert!(index < self.length);
(self.data[index / Self::BIT_UNIT] >> (index % Self::BIT_UNIT) & I::ONE).into()
((self.data[index / Self::BIT_UNIT] >> (index % Self::BIT_UNIT)) & I::ONE).into()
}

fn set(&mut self, index: usize, bit: Bit) {
Expand Down Expand Up @@ -448,15 +448,15 @@ where
fn shl_in(&mut self, bit: Bit) -> Bit {
let mut carry = bit;
for i in 0..(self.length / Self::BIT_UNIT) {
let b = self.data[i] >> (Self::BIT_UNIT - 1) & I::ONE;
self.data[i] = self.data[i] << 1 | carry.into();
let b = (self.data[i] >> (Self::BIT_UNIT - 1)) & I::ONE;
self.data[i] = (self.data[i] << 1) | carry.into();
carry = b.into();
}
if self.length % Self::BIT_UNIT != 0 {
let i = self.length / Self::BIT_UNIT;
let b = self.data[i] >> (self.length % Self::BIT_UNIT - 1) & I::ONE;
let b = (self.data[i] >> (self.length % Self::BIT_UNIT - 1)) & I::ONE;
self.data[i] =
(self.data[i] << 1 | carry.into()) & I::mask(self.length % Self::BIT_UNIT);
((self.data[i] << 1) | carry.into()) & I::mask(self.length % Self::BIT_UNIT);
carry = b.into();
}
carry
Expand All @@ -467,12 +467,12 @@ where
if self.length % Self::BIT_UNIT != 0 {
let i = self.length / Self::BIT_UNIT;
let b = self.data[i] & I::ONE;
self.data[i] = self.data[i] >> 1 | I::from(carry) << (self.length % Self::BIT_UNIT - 1);
self.data[i] = (self.data[i] >> 1) | (I::from(carry) << (self.length % Self::BIT_UNIT - 1));
carry = b.into();
}
for i in (0..(self.length / Self::BIT_UNIT)).rev() {
let b = self.data[i] & I::ONE;
self.data[i] = self.data[i] >> 1 | I::from(carry) << (Self::BIT_UNIT - 1);
self.data[i] = (self.data[i] >> 1) | (I::from(carry) << (Self::BIT_UNIT - 1));
carry = b.into();
}
carry
Expand Down Expand Up @@ -725,7 +725,7 @@ impl<I: Integer, const N: usize> fmt::Octal for Bvf<I, N> {
while let Some(b0) = it.next() {
let b1 = it.next().unwrap_or(Bit::Zero);
let b2 = it.next().unwrap_or(Bit::Zero);
let octet = (b2 as u8) << 2 | (b1 as u8) << 1 | b0 as u8;
let octet = ((b2 as u8) << 2) | ((b1 as u8) << 1) | b0 as u8;
if octet != 0 {
last_nz = s.len();
}
Expand Down
4 changes: 2 additions & 2 deletions src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl<'a, B: BitVector> BitIterator<'a, B> {
}
}

impl<'a, B: BitVector> Iterator for BitIterator<'a, B> {
impl<B: BitVector> Iterator for BitIterator<'_, B> {
type Item = Bit;

fn next(&mut self) -> Option<Self::Item> {
Expand Down Expand Up @@ -59,7 +59,7 @@ impl<'a, B: BitVector> Iterator for BitIterator<'a, B> {
}
}

impl<'a, B: BitVector> DoubleEndedIterator for BitIterator<'a, B> {
impl<B: BitVector> DoubleEndedIterator for BitIterator<'_, B> {
fn next_back(&mut self) -> Option<Self::Item> {
if self.range.start < self.range.end {
self.range.end -= 1;
Expand Down

0 comments on commit 62fcb1a

Please sign in to comment.