Skip to content

Commit e4c52d4

Browse files
Fix for Rust 1.70 (#20)
* Fix for Rust 1.70 * Clippy suggestions * Add regression test for #20 (rust-lang/rust#98112) * Update pinned rustc version in GHA to 1.69 (rayon requires a newer version than previously pinned) --------- Co-authored-by: boydgreenfield <nick.greenfield@gmail.com>
1 parent a8c7c5d commit e4c52d4

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
include:
1212
- build: pinned
1313
os: ubuntu-22.04
14-
rust: 1.60.0
14+
rust: 1.69.0
1515
- build: stable
1616
os: ubuntu-22.04
1717
rust: stable

src/mmap_bitvec.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl MmapBitVec {
192192
io::ErrorKind::InvalidData,
193193
format!(
194194
"file should be {} bytes (with {} header), but file is {} bytes",
195-
byte_size + total_header_size as u64,
195+
byte_size + total_header_size,
196196
total_header_size,
197197
file.metadata()?.len(),
198198
),
@@ -282,9 +282,9 @@ impl MmapBitVec {
282282
if r.end > self.size {
283283
panic!("Range ends outside of BitVec")
284284
}
285-
let byte_idx_st = (r.start >> 3) as usize;
286-
let byte_idx_en = ((r.end - 1) >> 3) as usize;
287-
let new_size: usize = (((r.end - r.start) as usize - 1) >> 3) + 1;
285+
let byte_idx_st = r.start >> 3;
286+
let byte_idx_en = (r.end - 1) >> 3;
287+
let new_size: usize = (((r.end - r.start) - 1) >> 3) + 1;
288288

289289
let ptr: *const u8 = self.mmap.as_ptr();
290290
let mut v = vec![0; new_size];
@@ -333,7 +333,7 @@ impl MmapBitVec {
333333
} else {
334334
0
335335
};
336-
let byte_idx_en = ((r.end - 1) >> 3) as usize;
336+
let byte_idx_en = (r.end - 1) >> 3;
337337

338338
let mmap: *mut u8 = self
339339
.mmap
@@ -406,8 +406,8 @@ impl BitVector for MmapBitVec {
406406

407407
/// Return the number of set bits in the range `r`
408408
fn rank(&self, r: Range<usize>) -> usize {
409-
let byte_idx_st = (r.start >> 3) as usize;
410-
let byte_idx_en = ((r.end - 1) >> 3) as usize;
409+
let byte_idx_st = r.start >> 3;
410+
let byte_idx_en = (r.end - 1) >> 3;
411411
let mmap: *const u8 = self.mmap.as_ptr();
412412

413413
let mut bit_count = 0usize;
@@ -452,7 +452,7 @@ impl BitVector for MmapBitVec {
452452

453453
/// Return the position of the `nth` set bit with `start` treated as the 0th position, or `None` if there is no set bit
454454
fn select(&self, n: usize, start: usize) -> Option<usize> {
455-
let byte_idx_st = (start >> 3) as usize;
455+
let byte_idx_st = start >> 3;
456456
let size_front = 8u8 - (start & 7) as u8;
457457
let mmap: *const u8 = self.mmap.as_ptr();
458458

@@ -494,8 +494,8 @@ impl BitVector for MmapBitVec {
494494
} else if r.end > self.size {
495495
panic!("Range ends outside of BitVec")
496496
}
497-
let byte_idx_st = (r.start >> 3) as usize;
498-
let byte_idx_en = ((r.end - 1) >> 3) as usize;
497+
let byte_idx_st = r.start >> 3;
498+
let byte_idx_en = (r.end - 1) >> 3;
499499
let new_size: u8 = (r.end - r.start) as u8;
500500

501501
let mut v;
@@ -513,7 +513,7 @@ impl BitVector for MmapBitVec {
513513
// we have to transmute since we don't know if it's a u64 or u128
514514
#[allow(clippy::transmute_ptr_to_ptr)]
515515
let lg_ptr: *const u128 = transmute(ptr.add(byte_idx_st));
516-
v |= (*lg_ptr).to_be() << (r.start & 7) >> (128 - new_size);
516+
v |= lg_ptr.read_unaligned().to_be() << (r.start & 7) >> (128 - new_size);
517517
}
518518
} else {
519519
// special case if we can't get a whole u64 out without running outside the buffer
@@ -526,7 +526,7 @@ impl BitVector for MmapBitVec {
526526
}
527527

528528
// mask out the high bits in case we copied extra
529-
v & (u128::max_value() >> (128 - new_size))
529+
v & (u128::MAX >> (128 - new_size))
530530
}
531531

532532
/// Set an unaligned range of bits using a `u64`.
@@ -542,8 +542,8 @@ impl BitVector for MmapBitVec {
542542
if r.end > self.size {
543543
panic!("Range ends outside of BitVec")
544544
}
545-
let byte_idx_st = (r.start >> 3) as usize;
546-
let byte_idx_en = ((r.end - 1) >> 3) as usize;
545+
let byte_idx_st = r.start >> 3;
546+
let byte_idx_en = (r.end - 1) >> 3;
547547
let new_size: u8 = (r.end - r.start) as u8;
548548

549549
// split off the front byte
@@ -602,8 +602,8 @@ impl BitVector for MmapBitVec {
602602
if (r.end - 1) > self.size {
603603
panic!("Range ends outside of BitVec")
604604
}
605-
let byte_idx_st = (r.start >> 3) as usize;
606-
let byte_idx_en = ((r.end - 1) >> 3) as usize;
605+
let byte_idx_st = r.start >> 3;
606+
let byte_idx_en = (r.end - 1) >> 3;
607607

608608
let mmap: *mut u8 = self
609609
.mmap
@@ -701,7 +701,7 @@ mod test {
701701

702702
#[test]
703703
fn test_bitvec_get_range() {
704-
let mut b = MmapBitVec::from_memory(128).unwrap();
704+
let mut b = MmapBitVec::from_memory(1024).unwrap();
705705
b.set(2, true);
706706
b.set(3, true);
707707
b.set(5, true);

0 commit comments

Comments
 (0)