diff --git a/growth-ring/Cargo.toml b/growth-ring/Cargo.toml index 1ba541bcf..80d58437f 100644 --- a/growth-ring/Cargo.toml +++ b/growth-ring/Cargo.toml @@ -31,3 +31,6 @@ tokio = { version = "1.28.1", features = ["tokio-macros", "rt", "macros"] } name = "growthring" path = "src/lib.rs" crate-type = ["dylib", "rlib", "staticlib"] + +[lints.clippy] +missing_const_for_fn = "warn" diff --git a/growth-ring/src/wal.rs b/growth-ring/src/wal.rs index 622477c37..71ee1ed30 100644 --- a/growth-ring/src/wal.rs +++ b/growth-ring/src/wal.rs @@ -86,7 +86,7 @@ fn sort_fids(file_nbit: u64, mut fids: Vec) -> Vec<(u8, u64)> { } } -fn counter_lt(a: u32, b: u32) -> bool { +const fn counter_lt(a: u32, b: u32) -> bool { if u32::abs_diff(a, b) > u32::MAX / 2 { b < a } else { @@ -125,10 +125,10 @@ impl WalRingId { counter: 0, } } - pub fn get_start(&self) -> WalPos { + pub const fn get_start(&self) -> WalPos { self.start } - pub fn get_end(&self) -> WalPos { + pub const fn get_end(&self) -> WalPos { self.end } } diff --git a/growth-ring/tests/common/mod.rs b/growth-ring/tests/common/mod.rs index 16c110c24..3c5955a4f 100644 --- a/growth-ring/tests/common/mod.rs +++ b/growth-ring/tests/common/mod.rs @@ -20,7 +20,7 @@ pub trait FailGen { struct FileContentEmul(RefCell>); impl FileContentEmul { - pub fn new() -> Self { + pub const fn new() -> Self { FileContentEmul(RefCell::new(Vec::new())) } } @@ -187,7 +187,7 @@ pub struct SingleFailGen { } impl SingleFailGen { - pub fn new(fail_point: usize) -> Self { + pub const fn new(fail_point: usize) -> Self { SingleFailGen { cnt: std::cell::Cell::new(0), fail_point, @@ -214,7 +214,7 @@ impl FailGen for ZeroFailGen { pub struct CountFailGen(std::cell::Cell); impl CountFailGen { - pub fn new() -> Self { + pub const fn new() -> Self { CountFailGen(std::cell::Cell::new(0)) } pub fn get_count(&self) -> usize { @@ -234,7 +234,7 @@ impl FailGen for CountFailGen { pub struct PaintStrokes(Vec<(u32, u32, u32)>); impl PaintStrokes { - pub fn new() -> Self { + pub const fn new() -> Self { PaintStrokes(Vec::new()) }