fix: clippy warnings — needless borrows, dead code, identical blocks

Author: Aaron Steven White
Commit c6b1b763a5a144174f093267b3bbfae07d16411e
Parent: 350e810bc3
Structural diff unavailable

These commits were pushed via plain git push, so no pre-parsed schemas are available. Install git-remote-cospan and re-push via panproto:// to see scope-level changes, breaking change detection, and semantic diffs.

brew install panproto/tap/git-remote-cospan
6 files changed +30 -29
@@ -9,6 +9,7 @@ use panproto_protocols::emit::{IndentWriter, children_by_edge};
99 use crate::record_config::RecordConfig;
1010 
1111 /// Column info extracted from the panproto schema + record config.
12+#[allow(dead_code)]
1213 pub struct Column {
1314     pub name: String,
1415     pub camel_name: String,
@@ -274,7 +275,9 @@ pub fn emit_crud(
274275     w.line(")");
275276     for col_name in &insert_cols {
276277         let col = cols.iter().find(|c| c.name == *col_name).unwrap();
277-        if col.rust_type.starts_with("Option<") || col.rust_type == "String" {
278+        // Borrow String and Option<String>; pass Copy types by value
279+        let needs_borrow = col.rust_type == "String" || col.rust_type == "Option<String>";
280+        if needs_borrow {
278281             w.line(&format!(".bind(&row.{col_name})"));
279282         } else {
280283             w.line(&format!(".bind(row.{col_name})"));
@@ -419,10 +422,10 @@ fn is_field_required(schema: &panproto_schema::Schema, body_id: &str, field_name
419422 
420423 fn lexicon_kind_to_db_types(kind: &panproto_gat::Name, field_name: &str) -> (String, String) {
421424     // DateTime fields
422-    if field_name.ends_with("At") || field_name == "createdAt" || field_name == "completedAt" {
423-        if kind.as_str() == "string" {
424-            return ("DateTime<Utc>".into(), "TIMESTAMPTZ".into());
425-        }
425+    if (field_name.ends_with("At") || field_name == "createdAt" || field_name == "completedAt")
426+        && kind.as_str() == "string"
427+    {
428+        return ("DateTime<Utc>".into(), "TIMESTAMPTZ".into());
426429     }
427430     match kind.as_str() {
428431         "string" => ("String".into(), "TEXT".into()),
@@ -4,7 +4,7 @@
44 //! ATProto protocol parser, then emits Rust structs with serde derives.
55 
66 use anyhow::Result;
7-use panproto_protocols::emit::{IndentWriter, children_by_edge, constraint_value};
7+use panproto_protocols::emit::{IndentWriter, children_by_edge};
88 use panproto_schema::Schema;
99 
1010 /// Emit Rust types for a query (Params struct) or procedure (Input struct).
@@ -149,13 +149,12 @@ fn main() -> Result<()> {
149149             .pointer("/defs/main/type")
150150             .and_then(|v| v.as_str())
151151             .unwrap_or("");
152-        if def_type == "query" || def_type == "procedure" {
153-            if let Ok(code) = emit_xrpc::emit_xrpc_types(&atproto_schema, nsid, def_type) {
154-                if !code.is_empty() {
155-                    all_xrpc_types.push_str(&format!("// {nsid}\n"));
156-                    all_xrpc_types.push_str(&code);
157-                }
158-            }
152+        if (def_type == "query" || def_type == "procedure")
153+            && let Ok(code) = emit_xrpc::emit_xrpc_types(&atproto_schema, nsid, def_type)
154+            && !code.is_empty()
155+        {
156+            all_xrpc_types.push_str(&format!("// {nsid}\n"));
157+            all_xrpc_types.push_str(&code);
159158         }
160159 
161160         // --- Database Row types + CRUD ---
@@ -18,6 +18,7 @@ pub struct ExtraColumn {
1818 
1919 /// How to decompose an AT-URI field into separate columns.
2020 #[derive(Clone)]
21+#[allow(dead_code)]
2122 pub struct UriDecomposition {
2223     /// The Lexicon field name (camelCase) containing the AT-URI.
2324     pub source_field: &'static str,
@@ -29,6 +30,7 @@ pub struct UriDecomposition {
2930 
3031 /// Store an AT-URI field as a single string column (renamed).
3132 #[derive(Clone)]
33+#[allow(dead_code)]
3234 pub struct UriStorage {
3335     /// The Lexicon field name (camelCase).
3436     pub source_field: &'static str,
@@ -38,6 +40,7 @@ pub struct UriStorage {
3840 
3941 /// Rename a Lexicon field in the database.
4042 #[derive(Clone)]
43+#[allow(dead_code)]
4144 pub struct FieldRename {
4245     /// The Lexicon field name (camelCase).
4346     pub source_field: &'static str,
@@ -28,13 +28,13 @@ pub struct InteropMorphism {
2828 /// between source and target schemas.
2929 fn identity_morphism(src: &Schema, tgt: &Schema) -> Migration {
3030     let mut vertex_map = HashMap::new();
31-    for (vid, _) in &src.vertices {
31+    for vid in src.vertices.keys() {
3232         if tgt.has_vertex(vid) {
3333             vertex_map.insert(vid.clone(), vid.clone());
3434         }
3535     }
3636     let mut edge_map = HashMap::new();
37-    for (edge, _) in &src.edges {
37+    for edge in src.edges.keys() {
3838         if tgt.edges.contains_key(edge) {
3939             edge_map.insert(edge.clone(), edge.clone());
4040         }
@@ -84,7 +84,7 @@ fn renamed_morphism(
8484     let rename_map: HashMap<&str, &str> = renames.iter().copied().collect();
8585 
8686     // Walk source vertices to find body.X vertices and map them
87-    for (vid, _) in &src.vertices {
87+    for vid in src.vertices.keys() {
8888         let vid_str = vid.to_string();
8989         if let Some(suffix) = vid_str.strip_prefix(&format!("{src_body}.")) {
9090             // Check if this is a top-level field (no further dots) or a sub-object field
@@ -118,8 +118,8 @@ fn renamed_morphism(
118118     }
119119 
120120     // Walk source edges to find property edges and map them
121-    for (edge, _) in &src.edges {
122-        if edge.kind.to_string() != "prop" {
121+    for edge in src.edges.keys() {
122+        if edge.kind != "prop" {
123123             continue;
124124         }
125125         let src_str = edge.src.to_string();
@@ -383,14 +383,12 @@ fn build_nsid_index(lexicons_dir: &Path) -> HashMap<String, std::path::PathBuf>
383383             let path = entry.path();
384384             if path.is_dir() {
385385                 walk(&path, index);
386-            } else if path.extension().is_some_and(|e| e == "json") {
387-                if let Ok(content) = std::fs::read_to_string(&path) {
388-                    if let Ok(json) = serde_json::from_str::<serde_json::Value>(&content) {
389-                        if let Some(id) = json.get("id").and_then(|v| v.as_str()) {
390-                            index.insert(id.to_string(), path);
391-                        }
392-                    }
393-                }
386+            } else if path.extension().is_some_and(|e| e == "json")
387+                && let Ok(content) = std::fs::read_to_string(&path)
388+                && let Ok(json) = serde_json::from_str::<serde_json::Value>(&content)
389+                && let Some(id) = json.get("id").and_then(|v| v.as_str())
390+            {
391+                index.insert(id.to_string(), path);
394392             }
395393         }
396394     }
cospan · schematic version control on atproto built on AT Protocol