From b1d858a61f332424a666959a7a5e604cc62c91d1 Mon Sep 17 00:00:00 2001 From: Emil Hofstetter Date: Mon, 12 Dec 2022 09:37:52 -0500 Subject: [PATCH] fix clippy lint by dereferencing ptr explicitly before swapping mem --- src/lib.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0a96da6..07cdca6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -342,11 +342,15 @@ impl LruCache { match node_ref { Some(node_ref) => { - let node_ptr: *mut LruEntry = node_ref.as_ptr(); - // if the key is already in the cache just update its value and move it to the // front of the list - unsafe { mem::swap(&mut v, &mut *(*node_ptr).val.as_mut_ptr()) } + let node_ptr: *mut LruEntry = node_ref.as_ptr(); + + // gets a reference to the node to perform a swap and drops it right after + let node_ref = unsafe { &mut (*(*node_ptr).val.as_mut_ptr()) }; + mem::swap(&mut v, node_ref); + let _ = node_ref; + self.detach(node_ptr); self.attach(node_ptr); Some((k, v))