Skip to content

Commit

Permalink
Fix clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cberner committed Nov 6, 2024
1 parent 0f0006f commit 03cc943
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/complex_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<T: Value> Value for Vec<T> {
};
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);
Expand Down
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/multimap_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ impl<V: Key> Value for &DynamicCollection<V> {

impl<V: Key> DynamicCollection<V> {
fn new(data: &[u8]) -> &Self {
unsafe { &*(data as *const [u8] as *const DynamicCollection<V>) }
unsafe { &*(std::ptr::from_ref::<[u8]>(data) as *const DynamicCollection<V>) }
}

fn collection_type(&self) -> DynamicCollectionType {
Expand Down Expand Up @@ -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<u8> {
Expand Down
12 changes: 6 additions & 6 deletions src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
///
Expand All @@ -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:
///
Expand All @@ -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
///
Expand Down Expand Up @@ -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]`
Expand Down Expand Up @@ -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()
);

Expand Down
2 changes: 1 addition & 1 deletion src/tree_store/btree_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions src/tree_store/page_store/buddy_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 4 additions & 6 deletions src/tree_store/page_store/page_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,12 +872,10 @@ impl TransactionalMemory {
lowest: bool,
) -> Result<Option<PageNumber>> {
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)
Expand Down
2 changes: 1 addition & 1 deletion src/tree_store/page_store/savepoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/tree_store/table_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -388,7 +389,7 @@ impl<const N: usize, T: Value> 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
Expand Down

0 comments on commit 03cc943

Please sign in to comment.