From 29d5ed47a1392623a06e0d577911c7e64a41480d Mon Sep 17 00:00:00 2001 From: ProofOfConcept Date: Sat, 28 Feb 2026 23:47:11 -0500 Subject: [PATCH] clippy: fix all warnings across all binaries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - &PathBuf → &Path in memory-search.rs signatures - Redundant field name in graph.rs struct init - Add truncate(false) to lock file open - Derive Default for Store instead of manual impl - slice::from_ref instead of &[x.clone()] - rsplit_once instead of split().last() - str::repeat instead of iter::repeat().take().collect() - is_none_or instead of map_or(true, ...) - strip_prefix instead of manual slicing Zero warnings on `cargo clippy`. --- src/bin/memory-search.rs | 8 ++++---- src/capnp_store.rs | 20 ++++---------------- src/graph.rs | 2 +- src/main.rs | 10 +++++----- src/neuro.rs | 2 +- 5 files changed, 15 insertions(+), 27 deletions(-) diff --git a/src/bin/memory-search.rs b/src/bin/memory-search.rs index 552a85d..cf41804 100644 --- a/src/bin/memory-search.rs +++ b/src/bin/memory-search.rs @@ -10,7 +10,7 @@ use std::collections::HashSet; use std::fs; use std::io::{self, Read, Write}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::process::Command; fn main() { @@ -138,7 +138,7 @@ fn extract_key_from_line(line: &str) -> Option { } } -fn load_or_create_cookie(dir: &PathBuf, session_id: &str) -> String { +fn load_or_create_cookie(dir: &Path, session_id: &str) -> String { let path = dir.join(format!("cookie-{}", session_id)); if path.exists() { fs::read_to_string(&path).unwrap_or_default().trim().to_string() @@ -165,7 +165,7 @@ fn generate_cookie() -> String { .collect() } -fn load_seen(dir: &PathBuf, session_id: &str) -> HashSet { +fn load_seen(dir: &Path, session_id: &str) -> HashSet { let path = dir.join(format!("seen-{}", session_id)); if path.exists() { fs::read_to_string(path) @@ -178,7 +178,7 @@ fn load_seen(dir: &PathBuf, session_id: &str) -> HashSet { } } -fn mark_seen(dir: &PathBuf, session_id: &str, key: &str) { +fn mark_seen(dir: &Path, session_id: &str, key: &str) { let path = dir.join(format!("seen-{}", session_id)); if let Ok(mut f) = fs::OpenOptions::new().create(true).append(true).open(path) { writeln!(f, "{}", key).ok(); diff --git a/src/capnp_store.rs b/src/capnp_store.rs index 7b45cfe..360cbc2 100644 --- a/src/capnp_store.rs +++ b/src/capnp_store.rs @@ -49,7 +49,7 @@ impl StoreLock { fn acquire() -> Result { let path = lock_path(); let file = fs::OpenOptions::new() - .create(true).write(true).open(&path) + .create(true).truncate(false).write(true).open(&path) .map_err(|e| format!("open lock {}: {}", path.display(), e))?; // Blocking exclusive lock @@ -268,7 +268,7 @@ pub struct GapRecord { } // The full in-memory store -#[derive(Serialize, Deserialize)] +#[derive(Default, Serialize, Deserialize)] pub struct Store { pub nodes: HashMap, // key → latest node #[serde(skip)] @@ -279,18 +279,6 @@ pub struct Store { pub params: Params, } -impl Default for Store { - fn default() -> Self { - Store { - nodes: HashMap::new(), - uuid_to_key: HashMap::new(), - relations: Vec::new(), - retrieval_log: Vec::new(), - gaps: Vec::new(), - params: Params::default(), - } - } -} impl Store { /// Load store: try state.json cache first, rebuild from capnp logs if stale @@ -498,7 +486,7 @@ impl Store { /// Add a relation (appends to log + updates cache) pub fn add_relation(&mut self, rel: Relation) -> Result<(), String> { - self.append_relations(&[rel.clone()])?; + self.append_relations(std::slice::from_ref(&rel))?; self.relations.push(rel); Ok(()) } @@ -1036,7 +1024,7 @@ impl Store { let mut output = String::new(); for node in §ions { if node.key.contains('#') { - let section_id = node.key.split('#').last().unwrap_or(""); + let section_id = node.key.rsplit_once('#').map_or("", |(_, s)| s); let links: Vec<_> = self.relations.iter() .filter(|r| r.source_key == node.key && !r.deleted diff --git a/src/graph.rs b/src/graph.rs index df9badb..a2c87e8 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -371,7 +371,7 @@ impl Graph { same_community, delta_cc_source: cc_after_source - cc_before_source, delta_cc_target: cc_after_target - cc_before_target, - delta_gini: delta_gini, + delta_gini, assessment, } } diff --git a/src/main.rs b/src/main.rs index 25f353c..ffbc3af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,7 +44,7 @@ fn find_current_transcript() -> Option { if p.extension().map(|x| x == "jsonl").unwrap_or(false) { if let Ok(meta) = p.metadata() { if let Ok(mtime) = meta.modified() { - if newest.as_ref().map_or(true, |(t, _)| mtime > *t) { + if newest.as_ref().is_none_or(|(t, _)| mtime > *t) { newest = Some((mtime, p)); } } @@ -554,8 +554,8 @@ fn cmd_apply_agent(args: &[String]) -> Result<(), String> { let reason = link.get("reason").and_then(|v| v.as_str()).unwrap_or(""); // Skip NOTE: targets (new topics, not existing nodes) - if target.starts_with("NOTE:") { - println!(" NOTE: {} — {}", &target[5..], reason); + if let Some(note) = target.strip_prefix("NOTE:") { + println!(" NOTE: {} — {}", note, reason); continue; } @@ -932,12 +932,12 @@ fn cmd_write(args: &[String]) -> Result<(), String> { let mut node = existing.clone(); node.content = content; node.version += 1; - store.append_nodes(&[node.clone()])?; + store.append_nodes(std::slice::from_ref(&node))?; store.nodes.insert(key.clone(), node); println!("Updated '{}' (v{})", key, store.nodes[&key].version); } else { let node = capnp_store::Store::new_node(&key, &content); - store.append_nodes(&[node.clone()])?; + store.append_nodes(std::slice::from_ref(&node))?; store.uuid_to_key.insert(node.uuid, node.key.clone()); store.nodes.insert(key.clone(), node); println!("Created '{}'", key); diff --git a/src/neuro.rs b/src/neuro.rs index 61d4ff8..7d84762 100644 --- a/src/neuro.rs +++ b/src/neuro.rs @@ -275,7 +275,7 @@ fn format_health_section(store: &Store, graph: &Graph) -> String { for (i, &count) in buckets.iter().enumerate() { let lo = i as f32 / 10.0; let hi = (i + 1) as f32 / 10.0; - let bar: String = std::iter::repeat('█').take((count as usize) / 10).collect(); + let bar = "█".repeat((count as usize) / 10); out.push_str(&format!(" {:.1}-{:.1}: {:4} {}\n", lo, hi, count, bar)); }