Skip to content

Commit 9837c3c

Browse files
committed
Simplify vec_cache::tests::slot_index_exhaustive by pulling out 0 case
`slot_index_exhaustive` has additional complexity in its loop that only applies for index 0. Pull that case out of the loop.
1 parent 43ee7cd commit 9837c3c

File tree

1 file changed

+8
-11
lines changed
  • compiler/rustc_data_structures/src/vec_cache

1 file changed

+8
-11
lines changed

compiler/rustc_data_structures/src/vec_cache/tests.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,21 @@ fn slot_index_exhaustive() {
7575
for idx in 0..=u32::MAX {
7676
buckets[SlotIndex::from_index(idx).bucket_idx] += 1;
7777
}
78-
let mut prev = None::<SlotIndex>;
79-
for idx in 0..=u32::MAX {
78+
let slot_idx = SlotIndex::from_index(0);
79+
assert_eq!(slot_idx.index_in_bucket, 0);
80+
assert_eq!(slot_idx.bucket_idx, 0);
81+
let mut prev = slot_idx;
82+
for idx in 1..=u32::MAX {
8083
let slot_idx = SlotIndex::from_index(idx);
81-
if let Some(p) = prev {
82-
if p.bucket_idx == slot_idx.bucket_idx {
83-
assert_eq!(p.index_in_bucket + 1, slot_idx.index_in_bucket);
84-
} else {
85-
assert_eq!(slot_idx.index_in_bucket, 0);
86-
}
84+
if prev.bucket_idx == slot_idx.bucket_idx {
85+
assert_eq!(prev.index_in_bucket + 1, slot_idx.index_in_bucket);
8786
} else {
88-
assert_eq!(idx, 0);
8987
assert_eq!(slot_idx.index_in_bucket, 0);
90-
assert_eq!(slot_idx.bucket_idx, 0);
9188
}
9289

9390
assert_eq!(buckets[slot_idx.bucket_idx], slot_idx.entries as u32);
9491
assert_eq!(ENTRIES_BY_BUCKET[slot_idx.bucket_idx], slot_idx.entries, "{}", idx);
9592

96-
prev = Some(slot_idx);
93+
prev = slot_idx;
9794
}
9895
}

0 commit comments

Comments
 (0)