Skip to content

Commit

Permalink
CI print rust vers, clippy ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
billythedummy committed Oct 8, 2023
1 parent a6f4138 commit d8759e7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ jobs:
with:
rust-version: stable
components: clippy,rustfmt
- name: Print versions
run: |
cargo --version
rustc --version
clippy-driver --version
rustfmt --version
- name: Build
run: cargo build
- name: Run tests
Expand Down
1 change: 1 addition & 0 deletions src/entry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ impl<'a, K: Ord, V: Default, const CAP: usize, I: PrimInt + Unsigned> Entry<'a,
/// Ensures a value is in the entry by inserting the default value if empty, and returns a mutable reference to the value in the entry.
///
/// Also moves the entry to most-recently-used position if previously existing
#[allow(clippy::unwrap_or_default)] // TODO: clippy bug? Suggests I use self.or_default() instead but i'm implementing self.or_default() here...
pub fn or_default(self) -> &'a mut V {
self.or_insert(V::default())
}
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,9 @@ impl<K: Ord, V, const CAP: usize, I: PrimInt + Unsigned> ConstLru<K, V, CAP, I>
let t = i.to_usize().unwrap();
let evicted_k = unsafe { self.keys[t].assume_init_read() };
let evicted_v = unsafe { self.values[t].assume_init_read() };
let Ok((_should_be_t, evicted_bs_i)) = self.get_index_of(&evicted_k) else { unreachable!() };
let Ok((_should_be_t, evicted_bs_i)) = self.get_index_of(&evicted_k) else {
unreachable!()
};
self.keys[t].write(k);
self.values[t].write(v);

Expand Down
24 changes: 18 additions & 6 deletions tests/test_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ fn vacant_insert_alloc() {
c.insert(1, 1);
assert!(c.get(&k).is_none());

let Entry::Vacant(entry) = c.entry(k) else { panic!("not vacant") };
let Entry::Vacant(entry) = c.entry(k) else {
panic!("not vacant")
};
let (m, opt) = entry.insert(v);

assert_eq!(*m, v);
Expand All @@ -36,7 +38,9 @@ fn vacant_insert_evict_1() {
c.insert(evicted_k, evicted_v);
assert!(c.get(&k).is_none());

let Entry::Vacant(entry) = c.entry(k) else { panic!("not vacant") };
let Entry::Vacant(entry) = c.entry(k) else {
panic!("not vacant")
};
let (m, opt) = entry.insert(v);

assert_eq!(*m, v);
Expand All @@ -59,7 +63,9 @@ fn vacant_insert_evict_3() {
c.insert(3, 3);
assert!(c.get(&k).is_none());

let Entry::Vacant(entry) = c.entry(k) else { panic!("not vacant") };
let Entry::Vacant(entry) = c.entry(k) else {
panic!("not vacant")
};
let (m, opt) = entry.insert(v);

assert_eq!(*m, v);
Expand All @@ -77,7 +83,9 @@ fn occupied_get() {
let mut c: ConstLru<u8, u8, 3, u8> = ConstLru::new();
c.insert(k, v);

let Entry::Occupied(mut entry) = c.entry(k) else { panic!("not occupied") };
let Entry::Occupied(mut entry) = c.entry(k) else {
panic!("not occupied")
};

assert_eq!(*entry.get(), v);
assert_eq!(*entry.get_mut(), v);
Expand All @@ -104,7 +112,9 @@ fn occupied_insert() {
c.insert(k, v);
c.insert(3, 4);

let Entry::Occupied(mut entry) = c.entry(k) else { panic!("not occupied") };
let Entry::Occupied(mut entry) = c.entry(k) else {
panic!("not occupied")
};

assert_eq!(entry.insert(new_v), v);
assert_eq!(*c.get(&k).unwrap(), new_v);
Expand All @@ -119,7 +129,9 @@ fn occupied_remove() {
c.insert(k, v);
c.insert(3, 4);

let Entry::Occupied(entry) = c.entry(k) else { panic!("not occupied") };
let Entry::Occupied(entry) = c.entry(k) else {
panic!("not occupied")
};

assert_eq!(entry.remove(), v);
assert!(c.get(&k).is_none());
Expand Down

0 comments on commit d8759e7

Please sign in to comment.