summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-26 21:56:20 +0100
committertv <tv@krebsco.de>2026-10-26 21:56:20 +0100
commit08f5df1f0a2e22876a5b49a4f9e2e05a61df882a (patch)
tree113050df0bef5e8f3e9d188c69fc2a0c76d2eb17
parentecdb3ee944f5c171faac3a71117e2ff27e064295 (diff)
make clippy happy again
-rw-r--r--src/api/peers.rs11
-rw-r--r--src/api/stats/prometheus.rs5
-rw-r--r--src/api/store.rs8
-rw-r--r--src/config/mod.rs28
-rw-r--r--src/document/store.rs16
-rw-r--r--src/files.rs8
-rw-r--r--src/remake/catchup.rs19
-rw-r--r--src/remake/switch.rs6
-rw-r--r--src/remake/vote.rs8
-rw-r--r--src/swarm/peer/handshake.rs32
-rw-r--r--src/swarm/peer/inbound.rs20
-rw-r--r--src/swarm/peer/worker.rs8
-rw-r--r--src/swarm/relay.rs2
-rw-r--r--src/swarm/topology.rs8
-rw-r--r--src/units.rs2
15 files changed, 90 insertions, 91 deletions
diff --git a/src/api/peers.rs b/src/api/peers.rs
index 9af24c0..f0fd1d9 100644
--- a/src/api/peers.rs
+++ b/src/api/peers.rs
@@ -186,15 +186,14 @@ pub(crate) async fn delete_peer(
.map_err(|_| StatusCode::BAD_REQUEST)?;
// Unknown locally is fine: other nodes may still know the peer.
- if let Some(peer_state_mutex) = state.get_peer_state(&peer).await {
- if peer_state_mutex
+ if let Some(peer_state_mutex) = state.get_peer_state(&peer).await
+ && peer_state_mutex
.lock()
.await
.is_alive(&state.timing, Instant::now())
- && !force.allows("alive")
- {
- return Err(StatusCode::CONFLICT);
- }
+ && !force.allows("alive")
+ {
+ return Err(StatusCode::CONFLICT);
}
let record =
diff --git a/src/api/stats/prometheus.rs b/src/api/stats/prometheus.rs
index 3baa125..30bb966 100644
--- a/src/api/stats/prometheus.rs
+++ b/src/api/stats/prometheus.rs
@@ -181,6 +181,9 @@ fn traffic_series(traffic: &PeerTraffic) -> Vec<(&'static str, &'static str, Cou
series
}
+/// A per-peer incident counter: its name, its help and how to read it.
+type IncidentSeries = (&'static str, &'static str, fn(&Incidents) -> f64);
+
pub(super) async fn render(state: &AppState, stats: &StatsResponse) -> String {
let mut out = Out::default();
@@ -619,7 +622,7 @@ pub(super) async fn render(state: &AppState, stats: &StatsResponse) -> String {
}
}
- let incidents: [(&str, &str, fn(&Incidents) -> f64); 4] = [
+ let incidents: [IncidentSeries; 4] = [
(
"peer_reply_timeouts_total",
"Sync messages unanswered until the reply timeout.",
diff --git a/src/api/store.rs b/src/api/store.rs
index a05bc23..d0fc807 100644
--- a/src/api/store.rs
+++ b/src/api/store.rs
@@ -144,10 +144,10 @@ fn mark_source(
response.headers_mut().insert(HEADS_HEADER, value);
}
}
- if let ReadSource::Stale(epoch) = source {
- if let Ok(value) = HeaderValue::from_str(&epoch.to_string()) {
- response.headers_mut().insert(STALE_HEADER, value);
- }
+ if let ReadSource::Stale(epoch) = source
+ && let Ok(value) = HeaderValue::from_str(&epoch.to_string())
+ {
+ response.headers_mut().insert(STALE_HEADER, value);
}
Ok(response)
}
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 5edf78b..c8bfa9f 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -376,12 +376,12 @@ impl Settings {
if let Some(url) = &self.mycelium_rest_url {
url::Url::parse(url).with_context(|| format!("mycelium-rest-url {url:?}"))?;
}
- if self.mycelium_rest_url.is_some() {
- if let Some((name, _)) = self.supervised_only().iter().find(|(_, set)| *set) {
- bail!(
- "{name} is for a supervised Mycelium daemon and can't be combined with mycelium-rest-url"
- );
- }
+ if self.mycelium_rest_url.is_some()
+ && let Some((name, _)) = self.supervised_only().iter().find(|(_, set)| *set)
+ {
+ bail!(
+ "{name} is for a supervised Mycelium daemon and can't be combined with mycelium-rest-url"
+ );
}
// A private network has both; one alone would be ignored or invented.
if self.mycelium_network_key_file.is_some() != self.mycelium_network_name.is_some() {
@@ -585,16 +585,12 @@ pub(crate) fn overlay(layer: &mut Layer, name: String, entry: Entry, how: Overla
let earlier = layer
.get(other)
.is_some_and(|previous| previous.origin.provenance != entry.origin.provenance);
- if earlier {
- if let Some(previous) = layer.remove(other) {
- log(
- &format!(
- "{name} can't be combined with {other}; dropped the earlier value"
- ),
- other,
- &previous,
- );
- }
+ if earlier && let Some(previous) = layer.remove(other) {
+ log(
+ &format!("{name} can't be combined with {other}; dropped the earlier value"),
+ other,
+ &previous,
+ );
}
}
}
diff --git a/src/document/store.rs b/src/document/store.rs
index 132a2ef..e742edb 100644
--- a/src/document/store.rs
+++ b/src/document/store.rs
@@ -66,10 +66,10 @@ fn resolve(
let merged = matches!(all[0].0, Value::Object(ObjType::Map));
- if all.len() > 1 {
- if let Some(log) = log {
- log.record(doc, key, &all, merged)?;
- }
+ if all.len() > 1
+ && let Some(log) = log
+ {
+ log.record(doc, key, &all, merged)?;
}
if merged {
@@ -432,10 +432,10 @@ fn copy_maps(
// merged_keys is a BTreeSet: sorted, so the operation order is deterministic.
for key in merged_keys(src, maps) {
path.push(key.clone());
- if !skip(path) {
- if let Some(resolved) = resolve(src, maps, &key, None)? {
- copy_resolved(src, &resolved, dst, target, Slot::Key(&key), path, skip)?;
- }
+ if !skip(path)
+ && let Some(resolved) = resolve(src, maps, &key, None)?
+ {
+ copy_resolved(src, &resolved, dst, target, Slot::Key(&key), path, skip)?;
}
path.pop();
}
diff --git a/src/files.rs b/src/files.rs
index 4b08469..0ec741e 100644
--- a/src/files.rs
+++ b/src/files.rs
@@ -160,10 +160,10 @@ fn write_atomic(path: &Path, bytes: &[u8]) -> std::io::Result<()> {
/// Makes a rename in `path`'s directory durable (best effort: not every platform syncs
/// directories).
fn sync_parent(path: &Path) {
- if let Some(dir) = path.parent().filter(|dir| !dir.as_os_str().is_empty()) {
- if let Ok(dir) = std::fs::File::open(dir) {
- let _ = dir.sync_all();
- }
+ if let Some(dir) = path.parent().filter(|dir| !dir.as_os_str().is_empty())
+ && let Ok(dir) = std::fs::File::open(dir)
+ {
+ let _ = dir.sync_all();
}
}
diff --git a/src/remake/catchup.rs b/src/remake/catchup.rs
index b00a210..0be7dfd 100644
--- a/src/remake/catchup.rs
+++ b/src/remake/catchup.rs
@@ -67,14 +67,14 @@ pub(super) async fn check<H: Host>(host: &H) {
}
if host.initial_sync_done() {
finish(host).await;
- } else if started.elapsed() > timeout {
- if let Some(rejoin) = host.remake().take_rejoin() {
- let reason = format!(
- "no peer on {target} completed a sync within {}s",
- timeout.as_secs()
- );
- abandon(host, rejoin, reason).await;
- }
+ } else if started.elapsed() > timeout
+ && let Some(rejoin) = host.remake().take_rejoin()
+ {
+ let reason = format!(
+ "no peer on {target} completed a sync within {}s",
+ timeout.as_secs()
+ );
+ abandon(host, rejoin, reason).await;
}
return;
}
@@ -253,6 +253,9 @@ enum Plan {
},
}
+// Every variant holds a whole document; one value lives for one step of a rejoin, so
+// boxing would only add an indirection.
+#[allow(clippy::large_enum_variant)]
enum Prepared {
/// Caught up with someone, but not with the target epoch yet: keep waiting.
NotYet(AutoCommit),
diff --git a/src/remake/switch.rs b/src/remake/switch.rs
index 903baea..ea56de6 100644
--- a/src/remake/switch.rs
+++ b/src/remake/switch.rs
@@ -232,10 +232,8 @@ async fn switch<H: Host>(
let mut doc = snapshot.doc.with_actor(actor);
// Keep this remake's record visible in the new epoch, for its history.
- if carry_record {
- if let Err(error) = store::copy_path(&copy, &mut doc, &record_path) {
- warn!(error = %error, "Could not carry the remake record into the new epoch");
- }
+ if carry_record && let Err(error) = store::copy_path(&copy, &mut doc, &record_path) {
+ warn!(error = %error, "Could not carry the remake record into the new epoch");
}
let heads = copy.get_heads();
diff --git a/src/remake/vote.rs b/src/remake/vote.rs
index 9bc8890..d5b167f 100644
--- a/src/remake/vote.rs
+++ b/src/remake/vote.rs
@@ -272,10 +272,10 @@ pub(super) async fn cast<H: Host>(host: &H) {
return;
};
// Only with the content in hand: a committed remake must have it on a majority.
- if let Some(reference) = &content {
- if content::available_or_fetch(host, reference).is_none() {
- return;
- }
+ if let Some(reference) = &content
+ && content::available_or_fetch(host, reference).is_none()
+ {
+ return;
}
// Spread over half a keepalive interval, so later voters see the earlier votes
// (the worker checks every second).
diff --git a/src/swarm/peer/handshake.rs b/src/swarm/peer/handshake.rs
index 7e494c6..109a42f 100644
--- a/src/swarm/peer/handshake.rs
+++ b/src/swarm/peer/handshake.rs
@@ -314,27 +314,27 @@ pub(super) async fn establish_peer(
) -> Result<()> {
let expected_swarm = state.swarm_id().await;
- if let Some(expected) = &expected_swarm {
- if expected != &swarm_id {
- bail!(
- "Incompatible swarm at {peer}: expected {}, received {}",
- expected,
- swarm_id
- );
- }
+ if let Some(expected) = &expected_swarm
+ && expected != &swarm_id
+ {
+ bail!(
+ "Incompatible swarm at {peer}: expected {}, received {}",
+ expected,
+ swarm_id
+ );
}
let peer_state_mutex = state.get_or_create_peer_state(peer).await;
let mut peer_state = peer_state_mutex.lock().await;
- if let Standing::Member { swarm_id: existing } = &peer_state.standing {
- if existing != &swarm_id {
- bail!(
- "Peer {peer} changed swarm identity from {} to {}",
- existing,
- swarm_id
- );
- }
+ if let Standing::Member { swarm_id: existing } = &peer_state.standing
+ && existing != &swarm_id
+ {
+ bail!(
+ "Peer {peer} changed swarm identity from {} to {}",
+ existing,
+ swarm_id
+ );
}
// Lock order: peer mutex -> lifecycle.
diff --git a/src/swarm/peer/inbound.rs b/src/swarm/peer/inbound.rs
index 73cc629..745e646 100644
--- a/src/swarm/peer/inbound.rs
+++ b/src/swarm/peer/inbound.rs
@@ -33,12 +33,12 @@ pub(crate) async fn handle_message(
// A reply to a HELLO from an earlier run of ours (late, or queued in Mycelium while
// we were down) says nothing about now; the peer answers our current HELLO.
- if let transport::ParsedMessage::HelloReply(reply) = &message {
- if reply.run_id != state.run_id {
- state.stats.stale_hello_reply();
- debug!(peer = %peer, "Ignoring a HELLO_REPLY to a HELLO from an earlier run");
- return Ok(());
- }
+ if let transport::ParsedMessage::HelloReply(reply) = &message
+ && reply.run_id != state.run_id
+ {
+ state.stats.stale_hello_reply();
+ debug!(peer = %peer, "Ignoring a HELLO_REPLY to a HELLO from an earlier run");
+ return Ok(());
}
if !admit(state, &peer, &message).await {
@@ -84,10 +84,10 @@ pub(crate) async fn handle_message(
debug!(peer = %peer, "HELLO before we know our swarm; not answering yet");
return Ok(());
};
- if let Some(theirs) = &hello.swarm_id {
- if theirs != &swarm_id {
- bail!("Incompatible swarm at {peer}: ours is {swarm_id}, it claims {theirs}");
- }
+ if let Some(theirs) = &hello.swarm_id
+ && theirs != &swarm_id
+ {
+ bail!("Incompatible swarm at {peer}: ours is {swarm_id}, it claims {theirs}");
}
// A resent HELLO (our reply was lost) or a late copy of one repeats a
// handshake we answered already: it must not reset the session again.
diff --git a/src/swarm/peer/worker.rs b/src/swarm/peer/worker.rs
index 20e2542..057e4bd 100644
--- a/src/swarm/peer/worker.rs
+++ b/src/swarm/peer/worker.rs
@@ -82,10 +82,10 @@ pub(crate) async fn run_peer_worker(state: AppState) {
let probe_due =
!ping_due && crate::swarm::source::probe_due(&state, peer, Instant::now());
- if ping_due || probe_due {
- if let Err(error) = send_ping(&state, peer).await {
- debug!(peer = %peer, error = %format!("{error:#}"), "Keepalive PING failed");
- }
+ if (ping_due || probe_due)
+ && let Err(error) = send_ping(&state, peer).await
+ {
+ debug!(peer = %peer, error = %format!("{error:#}"), "Keepalive PING failed");
}
if let Err(error) = retry_hello_if_due(&state, peer).await {
diff --git a/src/swarm/relay.rs b/src/swarm/relay.rs
index 2fa5f5f..b1cc0a7 100644
--- a/src/swarm/relay.rs
+++ b/src/swarm/relay.rs
@@ -194,7 +194,7 @@ pub(crate) async fn pull_if_behind(
pub(crate) fn pulled(state: &AppState, peer: &str) {
{
let mut pulling = state.pulling.lock_or_recover();
- if !pulling.current.as_ref().is_some_and(|(p, _)| p == peer) {
+ if pulling.current.as_ref().is_none_or(|(p, _)| p != peer) {
return;
}
pulling.current = None;
diff --git a/src/swarm/topology.rs b/src/swarm/topology.rs
index 4d37f6f..0617fc5 100644
--- a/src/swarm/topology.rs
+++ b/src/swarm/topology.rs
@@ -145,10 +145,10 @@ pub(crate) async fn refresh(state: &AppState) -> Option<NeighbourChange> {
let k = state.neighbours_k;
let mut unreachable = BTreeSet::new();
for member in &current {
- if let Some(peer_state) = state.get_peer_state(member).await {
- if peer_state.lock().await.is_unreachable() {
- unreachable.insert(member.clone());
- }
+ if let Some(peer_state) = state.get_peer_state(member).await
+ && peer_state.lock().await.is_unreachable()
+ {
+ unreachable.insert(member.clone());
}
}
let previous = {
diff --git a/src/units.rs b/src/units.rs
index cec5ffc..ac08ebf 100644
--- a/src/units.rs
+++ b/src/units.rs
@@ -134,7 +134,7 @@ pub(crate) fn parse_size(text: &str) -> Result<u64, String> {
pub(crate) fn format_size(bytes: u64) -> String {
SIZE_UNITS
.iter()
- .find(|(_, scale)| bytes != 0 && bytes % scale == 0)
+ .find(|(_, scale)| bytes != 0 && bytes.is_multiple_of(*scale))
.map(|(name, scale)| format!("{}{name}", bytes / scale))
.unwrap_or_else(|| "0B".to_owned())
}