Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.

Commit f0ca23a

Browse files
authored
Merge pull request #5 from structured-world/fix/#1-clippy-warnings
fix: resolve all clippy warnings for strict -D warnings CI
2 parents 9b155e1 + 894f526 commit f0ca23a

18 files changed

Lines changed: 175 additions & 19 deletions

clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
allowed-duplicate-crates = ["hashbrown"]

src/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ impl<O: Openable> Builder<O> {
183183
/// #
184184
/// # Ok::<_, fjall::Error>(())
185185
/// ```
186+
#[must_use]
186187
pub fn with_compaction_filter_factories(mut self, f: CompactionFilterAssigner) -> Self {
187188
self.inner.compaction_filter_factory_assigner = Some(f);
188189
self

src/db.rs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,19 @@ impl Drop for DatabaseInner {
8585

8686
// IMPORTANT: Break cyclic Arcs
8787
self.supervisor.flush_manager.clear();
88+
#[expect(
89+
clippy::expect_used,
90+
reason = "Drop impl cannot propagate errors from poisoned locks"
91+
)]
8892
self.supervisor
8993
.keyspaces
9094
.write()
9195
.expect("lock is poisoned")
9296
.clear();
97+
#[expect(
98+
clippy::expect_used,
99+
reason = "Drop impl cannot propagate errors from poisoned locks"
100+
)]
93101
self.supervisor
94102
.journal_manager
95103
.write()
@@ -277,7 +285,12 @@ impl Database {
277285
/// # Ok::<(), fjall::Error>(())
278286
/// ```
279287
#[must_use]
288+
#[expect(
289+
clippy::missing_panics_doc,
290+
reason = "panics only if internal RwLock is poisoned"
291+
)]
280292
pub fn journal_count(&self) -> usize {
293+
#[expect(clippy::expect_used, reason = "poisoned lock is unrecoverable")]
281294
self.supervisor
282295
.journal_manager
283296
.read()
@@ -288,6 +301,7 @@ impl Database {
288301
/// Returns the disk space usage of the journal.
289302
#[doc(hidden)]
290303
pub fn journal_disk_space(&self) -> crate::Result<u64> {
304+
#[expect(clippy::expect_used, reason = "poisoned lock is unrecoverable")]
291305
Ok(self.supervisor.journal.get_writer().len()?
292306
+ self
293307
.supervisor
@@ -311,9 +325,18 @@ impl Database {
311325
/// #
312326
/// # Ok::<(), fjall::Error>(())
313327
/// ```
328+
///
329+
/// # Errors
330+
///
331+
/// Returns an error if an IO error occurs.
332+
#[expect(
333+
clippy::missing_panics_doc,
334+
reason = "panics only if internal RwLock is poisoned"
335+
)]
314336
pub fn disk_space(&self) -> crate::Result<u64> {
315337
let journal_size = self.journal_disk_space()?;
316338

339+
#[expect(clippy::expect_used, reason = "poisoned lock is unrecoverable")]
317340
let keyspaces_size = self
318341
.supervisor
319342
.keyspaces
@@ -349,7 +372,7 @@ impl Database {
349372
///
350373
/// # Errors
351374
///
352-
/// Returns error, if an IO error occurred.
375+
/// Returns an error if an IO error occurs.
353376
pub fn persist(&self, mode: PersistMode) -> crate::Result<()> {
354377
if self.is_poisoned.load(std::sync::atomic::Ordering::Relaxed) {
355378
return Err(crate::Error::Poisoned);
@@ -385,7 +408,7 @@ impl Database {
385408
///
386409
/// # Errors
387410
///
388-
/// Returns error, if an IO error occurred.
411+
/// Returns an error if an IO error occurs.
389412
pub fn open(config: Config) -> crate::Result<Self> {
390413
log::debug!(
391414
"cache capacity={}MiB",
@@ -443,7 +466,7 @@ impl Database {
443466
///
444467
/// # Errors
445468
///
446-
/// Returns error, if an IO error occurred.
469+
/// Returns an error if an IO error occurs.
447470
///
448471
/// # Panics
449472
///
@@ -455,6 +478,7 @@ impl Database {
455478
) -> crate::Result<Keyspace> {
456479
assert!(is_valid_keyspace_name(name));
457480

481+
#[expect(clippy::expect_used, reason = "poisoned lock is unrecoverable")]
458482
let keyspaces = self.supervisor.keyspaces.write().expect("lock is poisoned");
459483

460484
Ok(if let Some(keyspace) = keyspaces.get(name) {
@@ -490,7 +514,12 @@ impl Database {
490514

491515
/// Returns the number of keyspaces.
492516
#[must_use]
517+
#[expect(
518+
clippy::missing_panics_doc,
519+
reason = "panics only if internal RwLock is poisoned"
520+
)]
493521
pub fn keyspace_count(&self) -> usize {
522+
#[expect(clippy::expect_used, reason = "poisoned lock is unrecoverable")]
494523
self.supervisor
495524
.keyspaces
496525
.read()
@@ -500,7 +529,12 @@ impl Database {
500529

501530
/// Gets a list of all keyspace names in the database.
502531
#[must_use]
532+
#[expect(
533+
clippy::missing_panics_doc,
534+
reason = "panics only if internal RwLock is poisoned"
535+
)]
503536
pub fn list_keyspace_names(&self) -> Vec<KeyspaceKey> {
537+
#[expect(clippy::expect_used, reason = "poisoned lock is unrecoverable")]
504538
self.supervisor
505539
.keyspaces
506540
.read()
@@ -771,6 +805,10 @@ impl Database {
771805

772806
db.supervisor.snapshot_tracker.gc();
773807

808+
#[expect(
809+
clippy::expect_used,
810+
reason = "poisoned lock during recovery is unrecoverable"
811+
)]
774812
for keyspace in db
775813
.supervisor
776814
.keyspaces

src/db_config.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ use std::{
99
sync::Arc,
1010
};
1111

12-
pub(crate) type CompactionFilterAssigner =
12+
// NOTE: This type is used crate-internally. The module is private so `pub` here
13+
// is effectively `pub(crate)`. Using `pub` avoids clippy::redundant_pub_crate.
14+
pub type CompactionFilterAssigner =
1315
Arc<dyn Fn(&str) -> Option<Arc<dyn lsm_tree::compaction::filter::Factory>> + Send + Sync>;
1416

1517
/// Global database configuration

src/journal/entry.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,13 @@ impl Entry {
196196
let compressed_value =
197197
Slice::from_reader(reader, on_disk_value_len as usize)?;
198198

199-
#[warn(unsafe_code)]
199+
#[expect(
200+
unsafe_code,
201+
reason = "unzeroed buffer for LZ4 decompression performance"
202+
)]
203+
// SAFETY: decompress_into writes exactly value_len bytes on success
204+
// (validated by the size check below). The buffer is fully initialized
205+
// before freeze() is called.
200206
let mut value = unsafe { Slice::builder_unzeroed(value_len as usize) };
201207

202208
let size = lz4_flex::decompress_into(&compressed_value, &mut value)

src/journal/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/// Recovery mode to use
66
///
77
/// Based on `RocksDB`'s WAL Recovery Modes: <https://github.com/facebook/rocksdb/wiki/WAL-Recovery-Modes>
8+
#[expect(dead_code, reason = "reserved for future WAL recovery mode selection")]
89
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
910
#[non_exhaustive]
1011
pub enum RecoveryMode {

src/journal/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ impl Drop for Journal {
5656
impl Journal {
5757
pub fn with_compression(self, comp: CompressionType, threshold: usize) -> Self {
5858
{
59+
#[expect(clippy::expect_used, reason = "poisoned lock is unrecoverable")]
5960
let mut writer = self.writer.lock().expect("lock is poisoned");
6061
writer.set_compression(comp, threshold);
6162
}
@@ -72,6 +73,10 @@ impl Journal {
7273
let path = path.as_ref();
7374
log::trace!("Creating new journal at {}", path.display());
7475

76+
#[expect(
77+
clippy::expect_used,
78+
reason = "journal path always has a parent directory"
79+
)]
7580
let folder = path.parent().expect("parent should exist");
7681

7782
std::fs::create_dir_all(folder).inspect_err(|e| {

src/journal/writer.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,20 @@ impl Writer {
8282

8383
let prev_path = self.path.clone();
8484

85+
#[expect(
86+
clippy::expect_used,
87+
reason = "journal path always has a parent directory"
88+
)]
8589
let folder = self
8690
.path
8791
.parent()
8892
.expect("should have parent")
8993
.to_path_buf();
9094

95+
#[expect(
96+
clippy::expect_used,
97+
reason = "journal file names are always valid .jnl files"
98+
)]
9199
let Some(basename) = self
92100
.path
93101
.file_name()

src/keyspace/config/filter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ impl EncodeConfig for crate::config::FilterPolicy {
1515
v.write_u8(self.len() as u8)
1616
.expect("cannot fail writing into a vec");
1717

18+
#[expect(clippy::expect_used, reason = "writing into a Vec cannot fail")]
1819
for item in self.iter() {
1920
match item {
2021
crate::config::FilterPolicyEntry::None => {

src/keyspace/config/pinning.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ impl EncodeConfig for crate::config::PinningPolicy {
2525

2626
impl DecodeConfig for crate::config::PinningPolicy {
2727
fn decode(mut bytes: &[u8]) -> crate::Result<Self> {
28-
let len = bytes.read_u8().expect("cannot fail");
28+
let len = bytes.read_u8()?;
2929

3030
let mut v = vec![];
3131

3232
for _ in 0..len {
33-
let b = bytes.read_u8().expect("cannot fail");
33+
let b = bytes.read_u8()?;
3434
v.push(b == 1);
3535
}
3636

0 commit comments

Comments
 (0)