From 731a04f8327d69e48e4f1daee89587a2eee8cf92 Mon Sep 17 00:00:00 2001 From: Jerome Froelich Date: Wed, 20 Jul 2022 16:55:35 -0400 Subject: [PATCH 01/10] Fix CI config --- .github/workflows/main.yml | 46 +++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 213ef14..2d50ff2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,54 +1,50 @@ on: pull_request: + types: + - opened + - reopened push: branches: - master name: CI +# Adapted from recipe: https://github.com/actions-rs/meta/blob/master/recipes/matrix.md#workflow. jobs: ci: - runs-on: [ubuntu-latest, windows-latest, macOS-latest] + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - stable + - beta + - nightly + - 1.31.0 # MSRV steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: stable + toolchain: ${{ matrix.rust }} + override: true components: rustfmt, clippy - uses: actions-rs/cargo@v1 with: - command: fmt - args: --all -- --check - - - uses: actions-rs/install@v0.1 - with: - crate: cargo-hack - version: latest - use-tool-cache: true + command: build - uses: actions-rs/cargo@v1 with: - command: hack - args: check --workspace --ignore-private --each-feature --no-dev-deps + command: test - uses: actions-rs/cargo@v1 with: - command: check - args: --workspace --all-targets --all-features + command: fmt + args: --all -- --check - uses: actions-rs/cargo@v1 with: - command: test - - - uses: actions-rs/clippy-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - args: --all-features - - - uses: actions-rs/audit-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} + command: clippy + args: -- -D warnings From 9ed92e0f39f06e45ba7741e6bedacdcd3ebdce5c Mon Sep 17 00:00:00 2001 From: Jerome Froelich Date: Wed, 20 Jul 2022 17:01:47 -0400 Subject: [PATCH 02/10] fmt --- src/lib.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f002a88..8f8a1d0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -915,10 +915,9 @@ impl Drop for LruCache { }); // We rebox the head/tail, and because these are maybe-uninit // they do not have the absent k/v dropped. - - let _head = unsafe { *Box::from_raw(self.head) }; - let _tail = unsafe { *Box::from_raw(self.tail) }; - + + let _head = unsafe { *Box::from_raw(self.head) }; + let _tail = unsafe { *Box::from_raw(self.tail) }; } } From a887286b48fb9893ea824c360cfd175c43aaaba6 Mon Sep 17 00:00:00 2001 From: Jerome Froelich Date: Wed, 20 Jul 2022 17:04:28 -0400 Subject: [PATCH 03/10] Run when PR updated --- .github/workflows/main.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2d50ff2..bceca62 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,8 +1,5 @@ on: - pull_request: - types: - - opened - - reopened + pull_request_target: push: branches: - master From 43bdedac38b207d652da6806ba299ba981b9633c Mon Sep 17 00:00:00 2001 From: Jerome Froelich Date: Wed, 20 Jul 2022 17:05:19 -0400 Subject: [PATCH 04/10] Fix event trigger --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bceca62..e799820 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,5 +1,5 @@ on: - pull_request_target: + pull_request: push: branches: - master From bcb8ceb3372a428cd5567bec7ccdda8dd58fc63b Mon Sep 17 00:00:00 2001 From: Jerome Froelich Date: Wed, 20 Jul 2022 17:13:57 -0400 Subject: [PATCH 05/10] Fix clippy warnings --- src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 8f8a1d0..f6371c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -356,6 +356,7 @@ impl LruCache { // Used internally to swap out a node if the cache is full or to create a new node if space // is available. Shared between `put`, `push`, and `get_or_insert`. + #[allow(clippy::type_complexity)] fn replace_or_create_node(&mut self, k: K, v: V) -> (Option<(K, V)>, Box>) { if self.len() == self.cap() { // if the cache is full, remove the last entry so we can use it for the new key @@ -474,7 +475,7 @@ impl LruCache { /// assert_eq!(cache.get_or_insert(1, ||"a"), Some(&"a")); /// assert_eq!(cache.get_or_insert(1, ||"b"), Some(&"a")); /// ``` - pub fn get_or_insert<'a, F>(&'a mut self, k: K, f: F) -> Option<&'a V> + pub fn get_or_insert<'a, F>(&mut self, k: K, f: F) -> Option<&'a V> where F: FnOnce() -> V, { From 1558315646379456d91d113defd90235bb258522 Mon Sep 17 00:00:00 2001 From: Jerome Froelich Date: Wed, 20 Jul 2022 17:20:44 -0400 Subject: [PATCH 06/10] Fix MSRV --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e799820..ff114f1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ jobs: - stable - beta - nightly - - 1.31.0 # MSRV + - 1.36.0 # MSRV steps: - uses: actions/checkout@v2 From c534fbadf042b871b2d2210b8688e3aacbf86eb2 Mon Sep 17 00:00:00 2001 From: Jerome Froelich Date: Wed, 20 Jul 2022 17:37:09 -0400 Subject: [PATCH 07/10] Test 1.48 as MSRV --- .github/workflows/main.yml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ff114f1..4b86e61 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ jobs: - stable - beta - nightly - - 1.36.0 # MSRV + - 1.48.0 # MSRV steps: - uses: actions/checkout@v2 diff --git a/README.md b/README.md index 3f33cec..6da46a0 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ An implementation of a LRU cache. The cache supports `put`, `get`, `get_mut` and all of which are O(1). This crate was heavily influenced by the [LRU Cache implementation in an earlier version of Rust's std::collections crate]. -The MSRV for this crate is 1.36.0. +The MSRV for this crate is 1.48.0. ## Example From 37f0ae3a8a3e5953ffa3e0e8dfaf4cb14329c329 Mon Sep 17 00:00:00 2001 From: Jerome Froelich Date: Wed, 20 Jul 2022 17:39:20 -0400 Subject: [PATCH 08/10] Bump MSRV to 1.49.0 --- .github/workflows/main.yml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4b86e61..4ccc62e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ jobs: - stable - beta - nightly - - 1.48.0 # MSRV + - 1.49.0 # MSRV steps: - uses: actions/checkout@v2 diff --git a/README.md b/README.md index 6da46a0..a235b36 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ An implementation of a LRU cache. The cache supports `put`, `get`, `get_mut` and all of which are O(1). This crate was heavily influenced by the [LRU Cache implementation in an earlier version of Rust's std::collections crate]. -The MSRV for this crate is 1.48.0. +The MSRV for this crate is 1.49.0. ## Example From b272f5c0216bfcf6e154af2c9fa5c4fae0d0867a Mon Sep 17 00:00:00 2001 From: Jerome Froelich Date: Wed, 20 Jul 2022 17:52:11 -0400 Subject: [PATCH 09/10] Update MSRV to 1.56 --- .github/workflows/main.yml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4ccc62e..8099e67 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ jobs: - stable - beta - nightly - - 1.49.0 # MSRV + - 1.56.0 # MSRV steps: - uses: actions/checkout@v2 diff --git a/README.md b/README.md index a235b36..cf1855e 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ An implementation of a LRU cache. The cache supports `put`, `get`, `get_mut` and all of which are O(1). This crate was heavily influenced by the [LRU Cache implementation in an earlier version of Rust's std::collections crate]. -The MSRV for this crate is 1.49.0. +The MSRV for this crate is 1.56.0. ## Example From 67c3c2f29316fca1dbc26a8a12fc3443e6275c53 Mon Sep 17 00:00:00 2001 From: Jerome Froelich Date: Wed, 20 Jul 2022 17:57:33 -0400 Subject: [PATCH 10/10] Fix warnings --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f6371c8..7f09dbe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -527,7 +527,7 @@ impl LruCache { { self.map .get(k) - .map(|node| unsafe { &(*(*node).val.as_ptr()) as &V }) + .map(|node| unsafe { &(*node.val.as_ptr()) as &V }) } /// Returns a mutable reference to the value corresponding to the key in the cache or `None` @@ -553,7 +553,7 @@ impl LruCache { { match self.map.get_mut(k) { None => None, - Some(node) => Some(unsafe { &mut (*(*node).val.as_mut_ptr()) as &mut V }), + Some(node) => Some(unsafe { &mut (*node.val.as_mut_ptr()) as &mut V }), } }