From 03cc9432509b4d718a3cbbc138afbad725319c17 Mon Sep 17 00:00:00 2001 From: Christopher Berner Date: Tue, 5 Nov 2024 20:42:53 -0800 Subject: [PATCH] Fix clippy errors --- src/complex_types.rs | 2 +- src/error.rs | 4 ++-- src/lib.rs | 3 ++- src/multimap_table.rs | 4 ++-- src/transactions.rs | 12 ++++++------ src/tree_store/btree_base.rs | 2 +- src/tree_store/page_store/buddy_allocator.rs | 4 +--- src/tree_store/page_store/page_manager.rs | 10 ++++------ src/tree_store/page_store/savepoint.rs | 2 +- src/tree_store/table_tree.rs | 2 +- src/types.rs | 3 ++- 11 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/complex_types.rs b/src/complex_types.rs index 258937f1..836c1f2e 100644 --- a/src/complex_types.rs +++ b/src/complex_types.rs @@ -75,7 +75,7 @@ impl Value for Vec { }; encode_varint_len(value.len(), &mut result); - for element in value.iter() { + for element in value { let serialized = T::as_bytes(element); if T::fixed_width().is_none() { encode_varint_len(serialized.as_ref().len(), &mut result); diff --git a/src/error.rs b/src/error.rs index b533ae1f..997c1398 100644 --- a/src/error.rs +++ b/src/error.rs @@ -195,7 +195,7 @@ impl std::error::Error for TableError {} pub enum DatabaseError { /// The Database is already open. Cannot acquire lock. DatabaseAlreadyOpen, - /// [crate::RepairSession::abort] was called. + /// [`crate::RepairSession::abort`] was called. RepairAborted, /// The database file is in an old file format and must be manually upgraded UpgradeRequired(u8), @@ -445,7 +445,7 @@ pub enum Error { /// Savepoints become invalid when an older savepoint is restored after it was created, /// and savepoints cannot be created if the transaction is "dirty" (any tables have been opened) InvalidSavepoint, - /// [crate::RepairSession::abort] was called. + /// [`crate::RepairSession::abort`] was called. RepairAborted, /// A persistent savepoint exists PersistentSavepointExists, diff --git a/src/lib.rs b/src/lib.rs index a5f5dcab..5756ccac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,11 @@ #![deny(clippy::all, clippy::pedantic, clippy::disallowed_methods)] #![allow( + let_underscore_drop, clippy::default_trait_access, clippy::if_not_else, clippy::inline_always, clippy::iter_not_returning_iterator, - clippy::let_underscore_drop, + clippy::manual_let_else, clippy::missing_errors_doc, clippy::missing_panics_doc, clippy::module_name_repetitions, diff --git a/src/multimap_table.rs b/src/multimap_table.rs index 69886761..5c24c3a3 100644 --- a/src/multimap_table.rs +++ b/src/multimap_table.rs @@ -574,7 +574,7 @@ impl Value for &DynamicCollection { impl DynamicCollection { fn new(data: &[u8]) -> &Self { - unsafe { &*(data as *const [u8] as *const DynamicCollection) } + unsafe { &*(std::ptr::from_ref::<[u8]>(data) as *const DynamicCollection) } } fn collection_type(&self) -> DynamicCollectionType { @@ -700,7 +700,7 @@ impl UntypedDynamicCollection { } fn new(data: &[u8]) -> &Self { - unsafe { &*(data as *const [u8] as *const UntypedDynamicCollection) } + unsafe { &*(std::ptr::from_ref::<[u8]>(data) as *const UntypedDynamicCollection) } } fn make_subtree_data(header: BtreeHeader) -> Vec { diff --git a/src/transactions.rs b/src/transactions.rs index ab10f266..e290ef18 100644 --- a/src/transactions.rs +++ b/src/transactions.rs @@ -147,10 +147,10 @@ pub enum Durability { /// this durability level will result in rapid growth of the database file. None, /// Commits with this durability level have been queued for persitance to disk, and should be - /// persistent some time after [WriteTransaction::commit] returns. + /// persistent some time after [`WriteTransaction::commit`] returns. Eventual, /// Commits with this durability level are guaranteed to be persistent as soon as - /// [WriteTransaction::commit] returns. + /// [`WriteTransaction::commit`] returns. /// /// Data is written with checksums, with the following commit algorithm: /// @@ -167,7 +167,7 @@ pub enum Durability { /// the ability to cause the database process to crash, can cause invalid data to be written /// with a valid checksum, leaving the database in an invalid, attacker-controlled state. Immediate, - /// Commits with this durability level have the same gaurantees as [Durability::Immediate] + /// Commits with this durability level have the same gaurantees as [`Durability::Immediate`] /// /// Additionally, aata is written with the following 2-phase commit algorithm: /// @@ -178,7 +178,7 @@ pub enum Durability { /// /// This mitigates a theoretical attack where an attacker who /// 1. can control the order in which pages are flushed to disk - /// 2. can introduce crashes during fsync(), + /// 2. can introduce crashes during `fsync`, /// 3. has knowledge of the database file contents, and /// 4. can include arbitrary data in a write transaction /// @@ -654,7 +654,7 @@ impl WriteTransaction { /// Delete the given persistent savepoint. /// - /// Note that if the transaction is abort()'ed this deletion will be rolled back. + /// Note that if the transaction is `abort()`'ed this deletion will be rolled back. /// /// Returns `true` if the savepoint existed /// Returns `[SavepointError::InvalidSavepoint`] if the transaction's durability is less than `[Durability::Immediate]` @@ -751,7 +751,7 @@ impl WriteTransaction { pub fn restore_savepoint(&mut self, savepoint: &Savepoint) -> Result<(), SavepointError> { // Ensure that user does not try to restore a Savepoint that is from a different Database assert_eq!( - self.transaction_tracker.as_ref() as *const _, + std::ptr::from_ref(self.transaction_tracker.as_ref()), savepoint.db_address() ); diff --git a/src/tree_store/btree_base.rs b/src/tree_store/btree_base.rs index 2574b927..8bcca720 100644 --- a/src/tree_store/btree_base.rs +++ b/src/tree_store/btree_base.rs @@ -606,7 +606,7 @@ impl<'a, 'b> LeafBuilder<'a, 'b> { self.fixed_value_size, self.total_key_bytes - first_split_key_bytes, ); - for (key, value) in self.pairs[division..].iter() { + for (key, value) in &self.pairs[division..] { builder.append(key, value); } drop(builder); diff --git a/src/tree_store/page_store/buddy_allocator.rs b/src/tree_store/page_store/buddy_allocator.rs index e1b05114..30006786 100644 --- a/src/tree_store/page_store/buddy_allocator.rs +++ b/src/tree_store/page_store/buddy_allocator.rs @@ -497,9 +497,7 @@ impl BuddyAllocator { debug_assert!(self.get_order_free_mut(order).get(page_number)); debug_assert!( self.get_order_allocated(order).get(page_number), - "Attempted to free page {}, order {}, which is not allocated", - page_number, - order + "Attempted to free page {page_number}, order {order}, which is not allocated", ); self.get_order_allocated_mut(order).clear(page_number); diff --git a/src/tree_store/page_store/page_manager.rs b/src/tree_store/page_store/page_manager.rs index 0d9943a3..04f29aa6 100644 --- a/src/tree_store/page_store/page_manager.rs +++ b/src/tree_store/page_store/page_manager.rs @@ -872,12 +872,10 @@ impl TransactionalMemory { lowest: bool, ) -> Result> { loop { - let candidate_region = - if let Some(candidate) = state.get_region_tracker_mut().find_free(required_order) { - candidate - } else { - return Ok(None); - }; + let Some(candidate_region) = state.get_region_tracker_mut().find_free(required_order) + else { + return Ok(None); + }; let region = state.get_region_mut(candidate_region); let r = if lowest { region.alloc_lowest(required_order) diff --git a/src/tree_store/page_store/savepoint.rs b/src/tree_store/page_store/savepoint.rs index f42b848a..534fedfb 100644 --- a/src/tree_store/page_store/savepoint.rs +++ b/src/tree_store/page_store/savepoint.rs @@ -79,7 +79,7 @@ impl Savepoint { } pub(crate) fn db_address(&self) -> *const TransactionTracker { - self.transaction_tracker.as_ref() as *const _ + std::ptr::from_ref(self.transaction_tracker.as_ref()) } pub(crate) fn set_persistent(&mut self) { diff --git a/src/tree_store/table_tree.rs b/src/tree_store/table_tree.rs index ad3990ab..fc964563 100644 --- a/src/tree_store/table_tree.rs +++ b/src/tree_store/table_tree.rs @@ -165,7 +165,7 @@ impl MutInPlaceValue for FreedPageList<'_> { } fn from_bytes_mut(data: &mut [u8]) -> &mut Self::BaseRefType { - unsafe { &mut *(data as *mut [u8] as *mut FreedPageListMut) } + unsafe { &mut *(std::ptr::from_mut::<[u8]>(data) as *mut FreedPageListMut) } } } diff --git a/src/types.rs b/src/types.rs index ab244a9b..c87548ff 100644 --- a/src/types.rs +++ b/src/types.rs @@ -149,6 +149,7 @@ impl Value for () { () } + #[allow(clippy::ignored_unit_patterns)] fn as_bytes<'a, 'b: 'a>(_: &'a Self::SelfType<'b>) -> &'a [u8] where Self: 'b, @@ -388,7 +389,7 @@ impl Value for [T; N] { { if let Some(fixed) = T::fixed_width() { let mut result = Vec::with_capacity(fixed * N); - for item in value.iter() { + for item in value { result.extend_from_slice(T::as_bytes(item).as_ref()); } result