caio.co/de/foca

Enable and fix missing_const_for_fn lint

Id
14bebc1e0aed1ec3b2b2ac2edc85adca03b11ee2
Author
Caio
Commit time
2025-05-19T10:30:30+02:00

Modified src/lib.rs

@@ -86,6 +86,7
clippy::match_wild_err_arm,
clippy::match_wildcard_for_single_variants,
clippy::mem_forget,
+ clippy::missing_const_for_fn,
clippy::missing_enforced_import_renames,
clippy::mut_mut,
clippy::mutex_integer,
@@ -275,7 +276,7
}

/// Getter for the current identity.
- pub fn identity(&self) -> &T {
+ pub const fn identity(&self) -> &T {
&self.identity
}

@@ -355,7 +356,7
///
/// May only be used as a bound for [`Foca::iter_members`] if no
/// Foca method that takes `&mut self` is called in-between.
- pub fn num_members(&self) -> usize {
+ pub const fn num_members(&self) -> usize {
self.members.num_active()
}

Modified src/member.rs

@@ -56,7 +56,7
///
/// `id` is an identity used to uniquely identify an individual
/// cluster member (say, a primary key).
- pub fn new(id: T, incarnation: Incarnation, state: State) -> Self {
+ pub const fn new(id: T, incarnation: Incarnation, state: State) -> Self {
Self {
id,
incarnation,
@@ -79,21 +79,21
}

/// Getter for the member's Incarnation
- pub fn incarnation(&self) -> Incarnation {
+ pub const fn incarnation(&self) -> Incarnation {
self.incarnation
}

/// Getter for the member's State
- pub fn state(&self) -> State {
+ pub const fn state(&self) -> State {
self.state
}

/// Getter for the member's identity
- pub fn id(&self) -> &T {
+ pub const fn id(&self) -> &T {
&self.id
}

- pub(crate) fn is_active(&self) -> bool {
+ pub(crate) const fn is_active(&self) -> bool {
match self.state {
State::Alive | State::Suspect => true,
State::Down => false,
@@ -110,7 +110,7
}
}

- fn can_change(&self, other_incarnation: Incarnation, other: State) -> bool {
+ const fn can_change(&self, other_incarnation: Incarnation, other: State) -> bool {
// This implements the order of preference of the Suspicion subprotocol
// outlined on section 4.2 of the paper.
match self.state {
@@ -149,7 +149,7
where
T: PartialEq + Clone + crate::Identity,
{
- pub(crate) fn num_active(&self) -> usize {
+ pub(crate) const fn num_active(&self) -> usize {
self.num_active
}

Modified src/payload.rs

@@ -143,18 +143,18
}

impl<T> Message<T> {
- pub(crate) fn allow_custom_broadcasts(&self) -> bool {
+ pub(crate) const fn allow_custom_broadcasts(&self) -> bool {
!matches!(self, Message::Announce | Message::TurnUndead)
}

- pub(crate) fn needs_piggyback(&self) -> bool {
+ pub(crate) const fn needs_piggyback(&self) -> bool {
!matches!(
self,
Message::Announce | Message::TurnUndead | Message::Broadcast
)
}

- pub(crate) fn piggyback_only_active(&self) -> bool {
+ pub(crate) const fn piggyback_only_active(&self) -> bool {
matches!(self, Message::Feed)
}
}

Modified src/probe.rs

@@ -37,7 +37,7
self.probe_number
}

- pub(crate) fn probe_number(&self) -> ProbeNumber {
+ pub(crate) const fn probe_number(&self) -> ProbeNumber {
self.probe_number
}

@@ -54,7 +54,7
self.reached_indirect_probe_stage = true;
}

- pub(crate) fn validate(&self) -> bool {
+ pub(crate) const fn validate(&self) -> bool {
// A probe that hasn't been started is
// valid
self.direct.is_none()
@@ -80,7 +80,7
self.direct.as_ref().is_some_and(|probed| probed.id() == id)
}

- pub(crate) fn succeeded(&self) -> bool {
+ pub(crate) const fn succeeded(&self) -> bool {
self.direct_ack_ok || self.indirect_ack_count > 0
}

Modified src/runtime.rs

@@ -260,7 +260,7
}

impl<T> Timer<T> {
- fn seq(&self) -> u8 {
+ const fn seq(&self) -> u8 {
match self {
Timer::SendIndirectProbe {
probed_id: _,