diff --git a/CHANGELOG.md b/CHANGELOG.md index c3b0b56f..87202d74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## Minimum Supported Rust Version (MSRV) + +The MSRV is updated to `1.88.0` due to dependencies requiring a higher bound. +This effectively puts all published crates in `heartwood` to an MSRV of `1.88.0`. + ## Domain Name Migration Following a domain move of the project, the names of the bootstrap nodes change: diff --git a/Cargo.toml b/Cargo.toml index cf0156e4..eb174602 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ version = "0.9.0" # *per crate*. If anyone ever wants to set it to a different # value per crate, this is of course possible. We're waiting # for the day it makes a difference… -rust-version = "1.85.0" +rust-version = "1.88.0" [workspace.dependencies] amplify = { version = "4.0.0", default-features = false } diff --git a/crates/radicle-cli-test/src/lib.rs b/crates/radicle-cli-test/src/lib.rs index 118dccdc..d900ec1a 100644 --- a/crates/radicle-cli-test/src/lib.rs +++ b/crates/radicle-cli-test/src/lib.rs @@ -209,10 +209,10 @@ impl TestFormula { for result in results { match result { Ok(msg) => { - if let Ok(Message::CompilerArtifact(a)) = msg.decode() { - if let Some(e) = a.executable { - log::debug!(target: "test", "Built {}", e.display()); - } + if let Ok(Message::CompilerArtifact(a)) = msg.decode() + && let Some(e) = a.executable + { + log::debug!(target: "test", "Built {}", e.display()); } } Err(e) => { diff --git a/crates/radicle-cli/src/commands/init.rs b/crates/radicle-cli/src/commands/init.rs index cfa5bb78..661c4062 100644 --- a/crates/radicle-cli/src/commands/init.rs +++ b/crates/radicle-cli/src/commands/init.rs @@ -38,10 +38,10 @@ pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> { } Err(e) => return Err(e.into()), }; - if let Ok((remote, _)) = git::rad_remote(&repo) { - if let Some(remote) = remote.url() { - bail!("repository is already initialized with remote {remote}"); - } + if let Ok((remote, _)) = git::rad_remote(&repo) + && let Some(remote) = remote.url() + { + bail!("repository is already initialized with remote {remote}"); } if let Some(rid) = args.existing { diff --git a/crates/radicle-cli/src/commands/issue.rs b/crates/radicle-cli/src/commands/issue.rs index 64d1974e..c52df0f6 100644 --- a/crates/radicle-cli/src/commands/issue.rs +++ b/crates/radicle-cli/src/commands/issue.rs @@ -261,16 +261,16 @@ where } }; - if let Some(a) = assignee { - if !issue.assignees().any(|v| v == &Did::from(a)) { - return None; - } + if let Some(a) = assignee + && !issue.assignees().any(|v| v == &Did::from(a)) + { + return None; } - if let Some(s) = state { - if s != issue.state() { - return None; - } + if let Some(s) = state + && s != issue.state() + { + return None; } Some((id, issue)) diff --git a/crates/radicle-cli/src/commands/node/logs.rs b/crates/radicle-cli/src/commands/node/logs.rs index 5f8c16aa..9292a742 100644 --- a/crates/radicle-cli/src/commands/node/logs.rs +++ b/crates/radicle-cli/src/commands/node/logs.rs @@ -148,10 +148,10 @@ impl Rotate { /// Remove the existing file, if it exists. Then create the next log, and /// create a hard link to it. pub fn execute(self) -> io::Result { - if let Some(to_remove) = self.remove { - if let Err(err) = to_remove.execute() { - log::warn!(target: "cli", "Failed to remove current log file: {err}"); - } + if let Some(to_remove) = self.remove + && let Err(err) = to_remove.execute() + { + log::warn!(target: "cli", "Failed to remove current log file: {err}"); } let log = OpenOptions::new() diff --git a/crates/radicle-cli/src/commands/patch/review/builder.rs b/crates/radicle-cli/src/commands/patch/review/builder.rs index ee124479..bd4f0e52 100644 --- a/crates/radicle-cli/src/commands/patch/review/builder.rs +++ b/crates/radicle-cli/src/commands/patch/review/builder.rs @@ -679,10 +679,10 @@ impl<'a> ReviewBuilder<'a> { let total = queue.len(); while let Some((ix, item)) = queue.next() { - if let Some(hunk) = self.hunk { - if hunk != ix + 1 { - continue; - } + if let Some(hunk) = self.hunk + && hunk != ix + 1 + { + continue; } let progress = term::format::secondary(format!("({}/{total})", ix + 1)); let file = match file.as_mut() { diff --git a/crates/radicle-cli/src/commands/seed.rs b/crates/radicle-cli/src/commands/seed.rs index ea585564..2b9e01a2 100644 --- a/crates/radicle-cli/src/commands/seed.rs +++ b/crates/radicle-cli/src/commands/seed.rs @@ -27,10 +27,11 @@ pub fn run(args: Args, ctx: impl term::Context) -> anyhow::Result<()> { for rid in rids { update(rid, scope, &mut node, &profile)?; - if should_fetch && node.is_running() { - if let Err(e) = sync::fetch(rid, settings.clone(), &mut node, &profile) { - term::error(e); - } + if should_fetch + && node.is_running() + && let Err(e) = sync::fetch(rid, settings.clone(), &mut node, &profile) + { + term::error(e); } } } @@ -57,11 +58,11 @@ pub fn update( let updated = profile.seed(rid, scope, node)?; let outcome = if updated { "updated" } else { "exists" }; - if let Ok(repo) = profile.storage.repository(rid) { - if repo.identity_doc()?.is_public() { - profile.add_inventory(rid, node)?; - term::success!("Inventory updated with {}", term::format::tertiary(rid)); - } + if let Ok(repo) = profile.storage.repository(rid) + && repo.identity_doc()?.is_public() + { + profile.add_inventory(rid, node)?; + term::success!("Inventory updated with {}", term::format::tertiary(rid)); } term::success!( diff --git a/crates/radicle-cli/src/git.rs b/crates/radicle-cli/src/git.rs index 5d1e329a..1dd074f0 100644 --- a/crates/radicle-cli/src/git.rs +++ b/crates/radicle-cli/src/git.rs @@ -381,10 +381,10 @@ pub fn commit_ssh_fingerprint(path: &Path, sha1: &str) -> Result, .transpose()?; // We only return a fingerprint if it's not an empty string - if let Some(s) = string { - if !s.is_empty() { - return Ok(Some(s)); - } + if let Some(s) = string + && !s.is_empty() + { + return Ok(Some(s)); } Ok(None) diff --git a/crates/radicle-cli/src/terminal.rs b/crates/radicle-cli/src/terminal.rs index f5245cda..0b8a85ef 100644 --- a/crates/radicle-cli/src/terminal.rs +++ b/crates/radicle-cli/src/terminal.rs @@ -65,10 +65,10 @@ pub fn fail(error: &anyhow::Error) { } // Catch common node errors, and offer a hint. - if let Some(e) = error.downcast_ref::() { - if e.is_connection_err() { - io::hint("to start your node, run `rad node start`."); - } + if let Some(e) = error.downcast_ref::() + && e.is_connection_err() + { + io::hint("to start your node, run `rad node start`."); } if let Some(Error::WithHint { hint, .. }) = error.downcast_ref::() { io::hint(hint); diff --git a/crates/radicle-cli/src/terminal/cob.rs b/crates/radicle-cli/src/terminal/cob.rs index 5267f03d..c8fa266a 100644 --- a/crates/radicle-cli/src/terminal/cob.rs +++ b/crates/radicle-cli/src/terminal/cob.rs @@ -39,10 +39,10 @@ impl MigrateCallback for MigrateSpinner { progress.rows.percentage() )); - if progress.is_done() { - if let Some(spinner) = self.spinner.take() { - spinner.finish() - } + if progress.is_done() + && let Some(spinner) = self.spinner.take() + { + spinner.finish() } } } diff --git a/crates/radicle-cli/src/terminal/patch/common.rs b/crates/radicle-cli/src/terminal/patch/common.rs index 6768a93b..cf518a48 100644 --- a/crates/radicle-cli/src/terminal/patch/common.rs +++ b/crates/radicle-cli/src/terminal/patch/common.rs @@ -89,10 +89,10 @@ pub fn branches(target: &Oid, repo: &git::raw::Repository) -> anyhow::Result Dag { stack.extend(from.dependents.iter()); while let Some(key) = stack.pop_front() { - if let Some(node) = self.graph.get(&key) { - if visited.insert(key) { - nodes.push(key); + if let Some(node) = self.graph.get(&key) + && visited.insert(key) + { + nodes.push(key); - for &neighbour in &node.dependents { - stack.push_back(neighbour); - } + for &neighbour in &node.dependents { + stack.push_back(neighbour); } } } @@ -351,13 +351,13 @@ impl Dag { stack.extend(from.dependencies.iter()); while let Some(key) = stack.pop_front() { - if let Some(node) = self.graph.get(&key) { - if visited.insert(key) { - nodes.push(key); + if let Some(node) = self.graph.get(&key) + && visited.insert(key) + { + nodes.push(key); - for &neighbour in &node.dependencies { - stack.push_back(neighbour); - } + for &neighbour in &node.dependencies { + stack.push_back(neighbour); } } } diff --git a/crates/radicle-git-metadata/src/commit/parse.rs b/crates/radicle-git-metadata/src/commit/parse.rs index 63e2d0bf..e16185e0 100644 --- a/crates/radicle-git-metadata/src/commit/parse.rs +++ b/crates/radicle-git-metadata/src/commit/parse.rs @@ -155,10 +155,10 @@ fn parse_body(body: &str) -> (String, Vec) { if let Some(split) = body.rfind("\n\n") { let candidate = &body[split + 2..]; // Only treat non-empty paragraphs as trailers. - if !candidate.trim().is_empty() { - if let Some(trailers) = try_parse_trailers(candidate) { - return (body[..split].to_string(), trailers); - } + if !candidate.trim().is_empty() + && let Some(trailers) = try_parse_trailers(candidate) + { + return (body[..split].to_string(), trailers); } } diff --git a/crates/radicle-node/src/reactor/transport.rs b/crates/radicle-node/src/reactor/transport.rs index a751c28f..6caa6dd4 100644 --- a/crates/radicle-node/src/reactor/transport.rs +++ b/crates/radicle-node/src/reactor/transport.rs @@ -301,15 +301,15 @@ impl EventHandler for Transport { fn handle(&mut self, event: &Event) -> Vec { let mut events = Vec::with_capacity(2); - if event.is_writable() { - if let Some(event) = self.handle_io(Interest::WRITABLE) { - events.push(event); - } + if event.is_writable() + && let Some(event) = self.handle_io(Interest::WRITABLE) + { + events.push(event); } - if event.is_readable() { - if let Some(event) = self.handle_io(Interest::READABLE) { - events.push(event); - } + if event.is_readable() + && let Some(event) = self.handle_io(Interest::READABLE) + { + events.push(event); } events } diff --git a/crates/radicle-node/src/runtime/handle.rs b/crates/radicle-node/src/runtime/handle.rs index c8ff9a98..6a35c936 100644 --- a/crates/radicle-node/src/runtime/handle.rs +++ b/crates/radicle-node/src/runtime/handle.rs @@ -174,10 +174,10 @@ impl radicle::node::Handle for Handle { let sessions = self.sessions()?; let session = sessions.iter().find(|s| s.nid == node); - if let Some(s) = session { - if s.state.is_connected() { - return Ok(ConnectResult::Connected); - } + if let Some(s) = session + && s.state.is_connected() + { + return Ok(ConnectResult::Connected); } self.command(service::Command::Connect(node, addr, opts))?; diff --git a/crates/radicle-node/src/test/node.rs b/crates/radicle-node/src/test/node.rs index dacc988c..72fde339 100644 --- a/crates/radicle-node/src/test/node.rs +++ b/crates/radicle-node/src/test/node.rs @@ -249,11 +249,11 @@ impl + cyphernet::Ecdh> NodeHandle { let events = self.handle.events(); loop { - if let Ok(repo) = self.storage.repository(*rid) { - if repo.remote(nid).is_ok() { - log::debug!(target: "test", "Node {} has {rid}/{nid}", self.id); - break; - } + if let Ok(repo) = self.storage.repository(*rid) + && repo.remote(nid).is_ok() + { + log::debug!(target: "test", "Node {} has {rid}/{nid}", self.id); + break; } events .wait( diff --git a/crates/radicle-node/src/test/peer.rs b/crates/radicle-node/src/test/peer.rs index cc4c95f3..60655e18 100644 --- a/crates/radicle-node/src/test/peer.rs +++ b/crates/radicle-node/src/test/peer.rs @@ -329,22 +329,21 @@ where pub fn refs_announcement(&self, rid: RepoId) -> Message { let mut refs = BoundedVec::new(); - if let Ok(repo) = self.storage().repository(rid) { - if let Ok(false) = repo.is_empty() { - if let Ok(remotes) = repo.remotes() { - for (remote_id, _) in remotes.into_iter() { - match RefsAt::new(&repo, remote_id) { - Ok(refs_at) => { - if let Err(e) = refs.push(refs_at) { - debug!(target: "test", "Failed to push {remote_id} to refs: {e}"); - break; - } - } - Err(e) => { - debug!(target: "test", "Failed to get `rad/sigrefs` for {remote_id}: {e}") - } + if let Ok(repo) = self.storage().repository(rid) + && let Ok(false) = repo.is_empty() + && let Ok(remotes) = repo.remotes() + { + for (remote_id, _) in remotes.into_iter() { + match RefsAt::new(&repo, remote_id) { + Ok(refs_at) => { + if let Err(e) = refs.push(refs_at) { + debug!(target: "test", "Failed to push {remote_id} to refs: {e}"); + break; } } + Err(e) => { + debug!(target: "test", "Failed to get `rad/sigrefs` for {remote_id}: {e}") + } } } } diff --git a/crates/radicle-node/src/test/simulator.rs b/crates/radicle-node/src/test/simulator.rs index 242b05a3..aa95e710 100644 --- a/crates/radicle-node/src/test/simulator.rs +++ b/crates/radicle-node/src/test/simulator.rs @@ -331,7 +331,7 @@ where // between individual nodes. We need to think about more realistic // scenarios. We should also think about creating various network // topologies. - if self.time.as_secs() % 10 == 0 { + if self.time.as_secs().is_multiple_of(10) { for (i, x) in nodes.keys().enumerate() { for y in nodes.keys().skip(i + 1) { if self.is_fallible() { diff --git a/crates/radicle-node/src/worker/fetch.rs b/crates/radicle-node/src/worker/fetch.rs index e51649e1..d63a4458 100644 --- a/crates/radicle-node/src/worker/fetch.rs +++ b/crates/radicle-node/src/worker/fetch.rs @@ -186,12 +186,12 @@ fn notify( // for sigref verification. continue; } - if let Some(rest) = r.strip_prefix(git::fmt::refname!("refs/heads/patches")) { - if radicle::cob::ObjectId::from_str(rest.as_str()).is_ok() { - // Don't notify about patch branches, since we already get - // notifications about patch updates. - continue; - } + if let Some(rest) = r.strip_prefix(git::fmt::refname!("refs/heads/patches")) + && radicle::cob::ObjectId::from_str(rest.as_str()).is_ok() + { + // Don't notify about patch branches, since we already get + // notifications about patch updates. + continue; } } if let RefUpdate::Skipped { .. } = update { diff --git a/crates/radicle-protocol/src/service.rs b/crates/radicle-protocol/src/service.rs index eedb3f5d..5743a19a 100644 --- a/crates/radicle-protocol/src/service.rs +++ b/crates/radicle-protocol/src/service.rs @@ -464,10 +464,10 @@ where continue; }; // Skip this repo if the sync status matches what we have in storage. - if let Some(announced) = announced.get(&rid) { - if updated_at.oid == announced.oid { - continue; - } + if let Some(announced) = announced.get(&rid) + && updated_at.oid == announced.oid + { + continue; } // Make sure our local node's sync status is up to date with storage. if self.db.seeds_mut().synced( @@ -1300,16 +1300,14 @@ where self.outbox.write_all(peer, msgs); } Entry::Vacant(e) => { - if let HostName::Ip(ip) = addr.host { - if !address::is_local(&ip) { - if let Err(e) = - self.db - .addresses_mut() - .record_ip(&remote, ip, self.clock.into()) - { - log::debug!(target: "service", "Failed to record IP address for {remote}: {e}"); - } - } + if let HostName::Ip(ip) = addr.host + && !address::is_local(&ip) + && let Err(e) = + self.db + .addresses_mut() + .record_ip(&remote, ip, self.clock.into()) + { + log::debug!(target: "service", "Failed to record IP address for {remote}: {e}"); } let peer = e.insert(Session::inbound( remote, @@ -1811,20 +1809,20 @@ where let relayer = remote; let relayer_addr = peer.addr.clone(); - if let Some(id) = self.handle_announcement(relayer, &relayer_addr, &ann)? { - if self.config.is_relay() { - if let AnnouncementMessage::Inventory(_) = ann.message { - if let Err(e) = self - .database_mut() - .gossip_mut() - .set_relay(id, gossip::RelayStatus::Relay) - { - warn!(target: "service", "Failed to set relay flag for message: {e}"); - return Ok(()); - } - } else { - self.relay(id, ann); + if let Some(id) = self.handle_announcement(relayer, &relayer_addr, &ann)? + && self.config.is_relay() + { + if let AnnouncementMessage::Inventory(_) = ann.message { + if let Err(e) = self + .database_mut() + .gossip_mut() + .set_relay(id, gossip::RelayStatus::Relay) + { + warn!(target: "service", "Failed to set relay flag for message: {e}"); + return Ok(()); } + } else { + self.relay(id, ann); } } } @@ -1876,20 +1874,18 @@ where ); } Message::Pong { zeroes } => { - if let Some((ping, latencies)) = connected { - if let session::PingState::AwaitingResponse { + if let Some((ping, latencies)) = connected + && let session::PingState::AwaitingResponse { len: ponglen, since, } = *ping - { - if (ponglen as usize) == zeroes.len() { - *ping = session::PingState::Ok; - // Keep track of peer latency. - latencies.push_back(self.clock - since); - if latencies.len() > MAX_LATENCIES { - latencies.pop_front(); - } - } + && (ponglen as usize) == zeroes.len() + { + *ping = session::PingState::Ok; + // Keep track of peer latency. + latencies.push_back(self.clock - since); + if latencies.len() > MAX_LATENCIES { + latencies.pop_front(); } } } @@ -1929,11 +1925,11 @@ where /// Add a seed to our routing table. fn seed_discovered(&mut self, rid: RepoId, nid: NodeId, time: Timestamp) { - if let Ok(result) = self.db.routing_mut().add_inventory([&rid], nid, time) { - if let &[(_, InsertResult::SeedAdded)] = result.as_slice() { - self.emitter.emit(Event::SeedDiscovered { rid, nid }); - debug!(target: "service", "Routing table updated for {rid} with seed {nid}"); - } + if let Ok(result) = self.db.routing_mut().add_inventory([&rid], nid, time) + && let &[(_, InsertResult::SeedAdded)] = result.as_slice() + { + self.emitter.emit(Event::SeedDiscovered { rid, nid }); + debug!(target: "service", "Routing table updated for {rid} with seed {nid}"); } } diff --git a/crates/radicle-protocol/src/service/limiter.rs b/crates/radicle-protocol/src/service/limiter.rs index 0246ba17..5d58b687 100644 --- a/crates/radicle-protocol/src/service/limiter.rs +++ b/crates/radicle-protocol/src/service/limiter.rs @@ -36,10 +36,10 @@ impl RateLimiter { tokens: &T, now: LocalTime, ) -> bool { - if let Some(nid) = nid { - if self.bypass.contains(nid) { - return false; - } + if let Some(nid) = nid + && self.bypass.contains(nid) + { + return false; } if let HostName::Ip(ip) = addr { // Don't limit LAN addresses. diff --git a/crates/radicle-protocol/src/service/session.rs b/crates/radicle-protocol/src/service/session.rs index 121805ca..1bf41594 100644 --- a/crates/radicle-protocol/src/service/session.rs +++ b/crates/radicle-protocol/src/service/session.rs @@ -218,12 +218,12 @@ impl Session { ref mut stable, .. } = self.state + && now >= since + && now.duration_since(since) >= CONNECTION_STABLE_THRESHOLD { - if now >= since && now.duration_since(since) >= CONNECTION_STABLE_THRESHOLD { - *stable = true; - // Reset number of attempts for stable connections. - self.attempts = 0; - } + *stable = true; + // Reset number of attempts for stable connections. + self.attempts = 0; } } diff --git a/crates/radicle-remote-helper/src/main.rs b/crates/radicle-remote-helper/src/main.rs index 590e4a38..b401dc69 100644 --- a/crates/radicle-remote-helper/src/main.rs +++ b/crates/radicle-remote-helper/src/main.rs @@ -245,10 +245,10 @@ fn run(profile: radicle::Profile) -> Result<(), Error> { let git = service::RealGitService; let mut node = service::RealNodeSession::new(&profile); - if let Err(e) = radicle::io::set_file_limit(4096) { - if debug { - eprintln!("{}: unable to set open file limit: {e}", VERSION.name); - } + if let Err(e) = radicle::io::set_file_limit(4096) + && debug + { + eprintln!("{}: unable to set open file limit: {e}", VERSION.name); } run_loop( diff --git a/crates/radicle-remote-helper/src/push.rs b/crates/radicle-remote-helper/src/push.rs index 1b264bd4..ec6b25b4 100644 --- a/crates/radicle-remote-helper/src/push.rs +++ b/crates/radicle-remote-helper/src/push.rs @@ -662,17 +662,15 @@ where // Set up current branch so that pushing updates the patch. else if let Some(branch) = rad::setup_patch_upstream(&patch, *head, working, upstream, false)? + && let Some(name) = branch.name()? + && profile.hints() { - if let Some(name) = branch.name()? { - if profile.hints() { - // Remove the remote portion of the name, i.e. - // rad/patches/deadbeef -> patches/deadbeef - let name = name.split_once('/').unwrap_or_default().1; - hint(format!( - "to update, run `git push` or `git push {upstream} --force-with-lease HEAD:{name}`" - )); - } - } + // Remove the remote portion of the name, i.e. + // rad/patches/deadbeef -> patches/deadbeef + let name = name.split_once('/').unwrap_or_default().1; + hint(format!( + "to update, run `git push` or `git push {upstream} --force-with-lease HEAD:{name}`" + )); } } diff --git a/crates/radicle-term/src/editor.rs b/crates/radicle-term/src/editor.rs index 9ddcc33d..e42a7368 100644 --- a/crates/radicle-term/src/editor.rs +++ b/crates/radicle-term/src/editor.rs @@ -204,15 +204,15 @@ impl Editor { /// Get the default editor command. fn default_editor() -> Option { // First check the standard environment variables. - if let Ok(visual) = env::var("VISUAL") { - if !visual.is_empty() { - return Some(visual.into()); - } + if let Ok(visual) = env::var("VISUAL") + && !visual.is_empty() + { + return Some(visual.into()); } - if let Ok(editor) = env::var("EDITOR") { - if !editor.is_empty() { - return Some(editor.into()); - } + if let Ok(editor) = env::var("EDITOR") + && !editor.is_empty() + { + return Some(editor.into()); } // Check Git. The user might have configured their editor there. diff --git a/crates/radicle-term/src/spinner.rs b/crates/radicle-term/src/spinner.rs index e00c1223..10573c94 100644 --- a/crates/radicle-term/src/spinner.rs +++ b/crates/radicle-term/src/spinner.rs @@ -59,10 +59,10 @@ pub struct Spinner { impl Drop for Spinner { fn drop(&mut self) { - if let Ok(mut progress) = self.progress.lock() { - if let State::Running = progress.state { - progress.state = State::Canceled; - } + if let Ok(mut progress) = self.progress.lock() + && let State::Running = progress.state + { + progress.state = State::Canceled; } unsafe { ManuallyDrop::take(&mut self.handle) } diff --git a/crates/radicle/src/cob/cache/migrations/2.rs b/crates/radicle/src/cob/cache/migrations/2.rs index 3be7f088..e67a6fc8 100644 --- a/crates/radicle/src/cob/cache/migrations/2.rs +++ b/crates/radicle/src/cob/cache/migrations/2.rs @@ -48,11 +48,11 @@ pub fn run( .ok_or(Error::MalformedJsonSchema)?; for (_, review) in reviews.iter_mut() { - if let Some(list) = review.as_array_mut() { - if let Some(last) = list.pop() { - *review = last; - transformed = true; - } + if let Some(list) = review.as_array_mut() + && let Some(last) = list.pop() + { + *review = last; + transformed = true; } } } diff --git a/crates/radicle/src/cob/patch.rs b/crates/radicle/src/cob/patch.rs index 3bfe1552..aef44798 100644 --- a/crates/radicle/src/cob/patch.rs +++ b/crates/radicle/src/cob/patch.rs @@ -726,10 +726,10 @@ impl Patch { review, comment, .. } | Action::ReviewCommentRedact { review, comment } => { - if let Some((_, review)) = lookup::review(self, review)? { - if let Some(comment) = review.comments.comment(comment) { - return Ok(Authorization::from(*actor == comment.author())); - } + if let Some((_, review)) = lookup::review(self, review)? + && let Some(comment) = review.comments.comment(comment) + { + return Ok(Authorization::from(*actor == comment.author())); } // Redacted. Authorization::Unknown @@ -739,14 +739,14 @@ impl Patch { // The reviewer, commenter or revision author can resolve and unresolve review comments. Action::ReviewCommentResolve { review, comment } | Action::ReviewCommentUnresolve { review, comment } => { - if let Some((revision, review)) = lookup::review(self, review)? { - if let Some(comment) = review.comments.comment(comment) { - return Ok(Authorization::from( - actor == &comment.author() - || actor == review.author.public_key() - || actor == revision.author.public_key(), - )); - } + if let Some((revision, review)) = lookup::review(self, review)? + && let Some(comment) = review.comments.comment(comment) + { + return Ok(Authorization::from( + actor == &comment.author() + || actor == review.author.public_key() + || actor == revision.author.public_key(), + )); } // Redacted. Authorization::Unknown @@ -773,10 +773,10 @@ impl Patch { | Action::RevisionCommentRedact { revision, comment, .. } => { - if let Some(revision) = lookup::revision(self, revision)? { - if let Some(comment) = revision.discussion.comment(comment) { - return Ok(Authorization::from(actor == &comment.author())); - } + if let Some(revision) = lookup::revision(self, revision)? + && let Some(comment) = revision.discussion.comment(comment) + { + return Ok(Authorization::from(actor == &comment.author())); } // Redacted. Authorization::Unknown diff --git a/crates/radicle/src/cob/thread.rs b/crates/radicle/src/cob/thread.rs index d810eedd..6b96d808 100644 --- a/crates/radicle/src/cob/thread.rs +++ b/crates/radicle/src/cob/thread.rs @@ -399,10 +399,10 @@ impl Thread> { to: &'a CommentId, ) -> impl Iterator)> { self.comments().filter_map(move |(id, c)| { - if let Some(reply_to) = c.reply_to { - if &reply_to == to { - return Some((id, c)); - } + if let Some(reply_to) = c.reply_to + && &reply_to == to + { + return Some((id, c)); } None }) @@ -503,10 +503,10 @@ pub fn comment( if body.is_empty() { return Err(Error::Comment(id)); } - if let Some(id) = reply_to { - if !thread.comments.contains_key(&id) { - return Err(Error::Missing(id)); - } + if let Some(id) = reply_to + && !thread.comments.contains_key(&id) + { + return Err(Error::Missing(id)); } debug_assert!(!thread.timeline.contains(&id)); thread.timeline.push(id); diff --git a/crates/radicle/src/git/canonical/symbolic.rs b/crates/radicle/src/git/canonical/symbolic.rs index 23cb355e..9b1a7b06 100644 --- a/crates/radicle/src/git/canonical/symbolic.rs +++ b/crates/radicle/src/git/canonical/symbolic.rs @@ -347,19 +347,19 @@ impl SymbolicRefs { // A [`Target::Direct`] whose string is already a key is actually // an intermediate link — downgrade to [`Target::Symbolic`]. - if let Target::Direct(q) = &target { - if self.0.contains_key(&q.as_ref().to_ref_string()) { - target = Target::symbolic(q.to_ref_string()); - } + if let Target::Direct(q) = &target + && self.0.contains_key(&q.as_ref().to_ref_string()) + { + target = Target::symbolic(q.to_ref_string()); } - if let Target::Symbolic(s) = &target { - if self.resolve(s.as_ref()).is_none() { - return Err(InsertionError::TargetNotQualified { - name: name.into_inner(), - target: target_str, - }); - } + if let Target::Symbolic(s) = &target + && self.resolve(s.as_ref()).is_none() + { + return Err(InsertionError::TargetNotQualified { + name: name.into_inner(), + target: target_str, + }); } self.reclassify_targets(&name); @@ -373,10 +373,10 @@ impl SymbolicRefs { fn reclassify_targets(&mut self, new_key: &Name) { let key = new_key.as_ref(); for existing in self.0.values_mut() { - if let Target::Direct(q) = existing { - if q == key { - *existing = Target::symbolic(q.to_ref_string()); - } + if let Target::Direct(q) = existing + && q == key + { + *existing = Target::symbolic(q.to_ref_string()); } } } diff --git a/crates/radicle/src/profile.rs b/crates/radicle/src/profile.rs index b43fa0b0..8c00f4ca 100644 --- a/crates/radicle/src/profile.rs +++ b/crates/radicle/src/profile.rs @@ -91,10 +91,10 @@ pub mod env { // because of the complexity surrounding how the pager command is // parsed and executed. See also . #[cfg(not(windows))] - if let Ok(cfg) = crate::git::raw::Config::open_default() { - if let Ok(pager) = cfg.get_string("core.pager") { - return Some(pager); - } + if let Ok(cfg) = crate::git::raw::Config::open_default() + && let Ok(pager) = cfg.get_string("core.pager") + { + return Some(pager); } if let Ok(pager) = var("PAGER") { return Some(pager); diff --git a/crates/radicle/src/profile/config.rs b/crates/radicle/src/profile/config.rs index a831e7aa..b9686cc8 100644 --- a/crates/radicle/src/profile/config.rs +++ b/crates/radicle/src/profile/config.rs @@ -187,18 +187,18 @@ impl Config { // Handle deprecated policy configuration. // Nb. This will override "seedingPolicy" if set! This code should be removed after 1.0. - if let (Some(p), Some(s)) = (cfg.node.extra.get("policy"), cfg.node.extra.get("scope")) { - if let (Ok(policy), Ok(scope)) = ( + if let (Some(p), Some(s)) = (cfg.node.extra.get("policy"), cfg.node.extra.get("scope")) + && let (Ok(policy), Ok(scope)) = ( json::from_value::(p.clone()), json::from_value::(s.clone()), - ) { - log::warn!(target: "radicle", "Overwriting `seedingPolicy` configuration"); - cfg.node.seeding_policy = match policy { - Policy::Allow => DefaultSeedingPolicy::Allow { - scope: node::config::Scope::explicit(scope), - }, - Policy::Block => DefaultSeedingPolicy::Block, - } + ) + { + log::warn!(target: "radicle", "Overwriting `seedingPolicy` configuration"); + cfg.node.seeding_policy = match policy { + Policy::Allow => DefaultSeedingPolicy::Allow { + scope: node::config::Scope::explicit(scope), + }, + Policy::Block => DefaultSeedingPolicy::Block, } } Ok(cfg) diff --git a/crates/radicle/src/rad.rs b/crates/radicle/src/rad.rs index 61d00a52..7af413b2 100644 --- a/crates/radicle/src/rad.rs +++ b/crates/radicle/src/rad.rs @@ -85,10 +85,10 @@ where if let Err(e) = project.remove() { log::warn!(target: "radicle", "Failed to remove project during `rad::init` cleanup: {e}"); } - if repo.find_remote(&REMOTE_NAME).is_ok() { - if let Err(e) = repo.remote_delete(&REMOTE_NAME) { - log::warn!(target: "radicle", "Failed to remove remote during `rad::init` cleanup: {e}"); - } + if repo.find_remote(&REMOTE_NAME).is_ok() + && let Err(e) = repo.remote_delete(&REMOTE_NAME) + { + log::warn!(target: "radicle", "Failed to remove remote during `rad::init` cleanup: {e}"); } Err(err) } @@ -497,10 +497,10 @@ pub fn setup_patch_upstream<'a>( )?; assert!(remote_branch.is_remote()); - if let Some(name) = name { - if force || branch.upstream().is_err() { - git::set_upstream(working, remote, name.as_str(), git::refs::patch(patch))?; - } + if let Some(name) = name + && (force || branch.upstream().is_err()) + { + git::set_upstream(working, remote, name.as_str(), git::refs::patch(patch))?; } Ok(Some(crate::git::raw::Branch::wrap(remote_branch))) } diff --git a/crates/radicle/src/storage/git.rs b/crates/radicle/src/storage/git.rs index bdc5f2ac..56b18543 100644 --- a/crates/radicle/src/storage/git.rs +++ b/crates/radicle/src/storage/git.rs @@ -842,10 +842,10 @@ impl ReadRepository for Repository { fn head(&self) -> Result<(Qualified<'_>, Oid), RepositoryError> { // If `HEAD` is already set locally, just return that. - if let Ok(head) = self.backend.head() { - if let Ok((name, oid)) = git::refs::qualified_from(&head) { - return Ok((name.to_owned(), oid)); - } + if let Ok(head) = self.backend.head() + && let Ok((name, oid)) = git::refs::qualified_from(&head) + { + return Ok((name.to_owned(), oid)); } self.canonical_head() } diff --git a/crates/radicle/src/test.rs b/crates/radicle/src/test.rs index 89b36289..3fc9dc0d 100644 --- a/crates/radicle/src/test.rs +++ b/crates/radicle/src/test.rs @@ -34,12 +34,12 @@ pub fn fetch( }; callbacks.update_tips(|name, old, new| { - if let Ok(name) = git::fmt::RefString::try_from(name) { - if name.to_namespaced().is_some() { - updates.push(RefUpdate::from(name, old, new)); - // Returning `true` ensures the process is not aborted. - return true; - } + if let Ok(name) = git::fmt::RefString::try_from(name) + && name.to_namespaced().is_some() + { + updates.push(RefUpdate::from(name, old, new)); + // Returning `true` ensures the process is not aborted. + return true; } false });