Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Growth ring const function checks #383

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions growth-ring/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice having the lints directly in the cargo.toml!

6 changes: 3 additions & 3 deletions growth-ring/src/wal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn sort_fids(file_nbit: u64, mut fids: Vec<u64>) -> 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 {
Expand Down Expand Up @@ -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
}
}
Expand Down
8 changes: 4 additions & 4 deletions growth-ring/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub trait FailGen {
struct FileContentEmul(RefCell<Vec<u8>>);

impl FileContentEmul {
pub fn new() -> Self {
pub const fn new() -> Self {
FileContentEmul(RefCell::new(Vec::new()))
}
}
Expand Down Expand Up @@ -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,
Expand All @@ -214,7 +214,7 @@ impl FailGen for ZeroFailGen {
pub struct CountFailGen(std::cell::Cell<usize>);

impl CountFailGen {
pub fn new() -> Self {
pub const fn new() -> Self {
CountFailGen(std::cell::Cell::new(0))
}
pub fn get_count(&self) -> usize {
Expand All @@ -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())
}

Expand Down