Skip to content

Commit dc22b03

Browse files
authored
chore(native): clean up pre-existing Rust dead-code warnings (#1484)
* chore: gitignore napi-generated artifacts in crates/codegraph-core * chore(tests): remove unused biome suppression in visitor.test.ts * fix(titan-run): sync --start-from enum and phase-timestamp list with actual phases * fix(hooks): track Bash file modifications via before/after git status diff Adds snapshot-pre-bash.sh (PreToolUse Bash) + track-bash-writes.sh (PostToolUse Bash): the pre-hook captures git status --porcelain to a per-worktree temp file before each Bash call; the post-hook diffs the before/after state and appends newly modified or created files to .claude/session-edits.log. This closes the gap where files written by sed -i, printf redirects, tee, heredocs, or build tools (Cargo.lock, lockfiles) were never recorded, causing guard-git.sh to emit false-positive BLOCKED errors. Closes #1457 * chore(native): remove dead code (unused var, method, variant, fields) - clojure.rs: annotate lifetime-anchor assignment to silence false-positive - cfg.rs: remove never-called start_line_of method - complexity.rs: remove never-constructed NotHandled variant; convert irrefutable if-let patterns to plain let destructures - dataflow.rs: remove never-read callee fields from CallReturn/Destructured - incremental.rs: remove never-read lang field from CacheEntry cargo check and cargo clippy both clean after these changes. * fix(native): simplify stale struct-pattern syntax on now-unit LocalSource variants CallReturn and Destructured became unit variants when their callee fields were removed. The find_binding match arms still used { .. } struct-pattern syntax which implies ignored fields where none exist. Simplify to plain unit patterns.
1 parent 9de318c commit dc22b03

5 files changed

Lines changed: 27 additions & 34 deletions

File tree

crates/codegraph-core/src/ast_analysis/cfg.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,10 +659,6 @@ impl<'a> CfgBuilder<'a> {
659659
}
660660
}
661661

662-
fn start_line_of(&self, block_idx: u32) -> Option<u32> {
663-
self.blocks.iter().find(|b| b.index == block_idx).and_then(|b| b.start_line)
664-
}
665-
666662
/// Get statement children from a block or statement list.
667663
fn get_statements<'b>(&self, node: &Node<'b>) -> Vec<Node<'b>> {
668664
let kind = node.kind();

crates/codegraph-core/src/ast_analysis/complexity.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,6 @@ fn walk_children(
516516
enum BranchAction {
517517
/// Node handled — walk children at the given nesting delta, then return.
518518
Handled { cognitive_delta: u32, cyclomatic_delta: u32, nesting_delta: u32 },
519-
/// Not a special branch pattern — fall through to normal processing.
520-
NotHandled,
521519
}
522520

523521
/// Classify a branch node (one where `rules.is_branch(kind)` is true).
@@ -675,14 +673,12 @@ fn walk(
675673

676674
// Branch/control flow nodes (skip keyword leaf tokens)
677675
if rules.is_branch(kind) && node.child_count() > 0 {
678-
if let BranchAction::Handled { cognitive_delta, cyclomatic_delta, nesting_delta } =
679-
classify_branch(node, kind, rules, nesting_level)
680-
{
681-
*cognitive += cognitive_delta;
682-
*cyclomatic += cyclomatic_delta;
683-
walk_children(node, nesting_level + nesting_delta, false, rules, cognitive, cyclomatic, max_nesting, depth);
684-
return;
685-
}
676+
let BranchAction::Handled { cognitive_delta, cyclomatic_delta, nesting_delta } =
677+
classify_branch(node, kind, rules, nesting_level);
678+
*cognitive += cognitive_delta;
679+
*cyclomatic += cyclomatic_delta;
680+
walk_children(node, nesting_level + nesting_delta, false, rules, cognitive, cyclomatic, max_nesting, depth);
681+
return;
686682
}
687683

688684
// Pattern C plain else (Go/Java)
@@ -1323,17 +1319,15 @@ fn walk_all(
13231319

13241320
// Branch/control flow nodes (skip keyword leaf tokens)
13251321
if c_rules.is_branch(kind) && node.child_count() > 0 {
1326-
if let BranchAction::Handled { cognitive_delta, cyclomatic_delta, nesting_delta } =
1327-
classify_branch(node, kind, c_rules, nesting_level)
1328-
{
1329-
*cognitive += cognitive_delta;
1330-
*cyclomatic += cyclomatic_delta;
1331-
walk_all_children(
1332-
node, source, nesting_level + nesting_delta, false, skip_h,
1333-
c_rules, h_rules, cognitive, cyclomatic, max_nesting, operators, operands,
1334-
);
1335-
return;
1336-
}
1322+
let BranchAction::Handled { cognitive_delta, cyclomatic_delta, nesting_delta } =
1323+
classify_branch(node, kind, c_rules, nesting_level);
1324+
*cognitive += cognitive_delta;
1325+
*cyclomatic += cyclomatic_delta;
1326+
walk_all_children(
1327+
node, source, nesting_level + nesting_delta, false, skip_h,
1328+
c_rules, h_rules, cognitive, cyclomatic, max_nesting, operators, operands,
1329+
);
1330+
return;
13371331
}
13381332

13391333
// Pattern C plain else (Go/Java)

crates/codegraph-core/src/ast_analysis/dataflow.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -882,8 +882,8 @@ fn collect_identifiers(node: &Node, out: &mut Vec<String>, rules: &DataflowRules
882882

883883
#[derive(Debug, Clone)]
884884
enum LocalSource {
885-
CallReturn { callee: String },
886-
Destructured { callee: String },
885+
CallReturn,
886+
Destructured,
887887
}
888888

889889
struct ScopeFrame {
@@ -908,8 +908,8 @@ fn find_binding(scope_stack: &[ScopeFrame], name: &str) -> Option<BindingInfo> {
908908
}
909909
if let Some(local) = scope.locals.get(name) {
910910
let confidence = match local {
911-
LocalSource::CallReturn { .. } => 0.9,
912-
LocalSource::Destructured { .. } => 0.8,
911+
LocalSource::CallReturn => 0.9,
912+
LocalSource::Destructured => 0.8,
913913
};
914914
return Some(BindingInfo {
915915
binding_type: "local".to_string(),
@@ -1200,7 +1200,7 @@ fn handle_var_declarator(
12001200
});
12011201
scope
12021202
.locals
1203-
.insert(n.clone(), LocalSource::Destructured { callee: callee.clone() });
1203+
.insert(n.clone(), LocalSource::Destructured);
12041204
}
12051205
} else {
12061206
let var_name = node_text(&name_n, source).to_string();
@@ -1211,7 +1211,7 @@ fn handle_var_declarator(
12111211
expression: truncate(node_text(node, source), DATAFLOW_TRUNCATION_LIMIT),
12121212
line: node_line(node),
12131213
});
1214-
scope.locals.insert(var_name, LocalSource::CallReturn { callee });
1214+
scope.locals.insert(var_name, LocalSource::CallReturn);
12151215
}
12161216
}
12171217

@@ -1267,7 +1267,7 @@ fn handle_assignment(
12671267
line: node_line(node),
12681268
});
12691269
if let Some(scope) = scope_stack.last_mut() {
1270-
scope.locals.insert(var_name, LocalSource::CallReturn { callee });
1270+
scope.locals.insert(var_name, LocalSource::CallReturn);
12711271
}
12721272
}
12731273
}

crates/codegraph-core/src/domain/graph/builder/incremental.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::types::FileSymbols;
1010

1111
struct CacheEntry {
1212
tree: Tree,
13-
lang: LanguageKind,
1413
}
1514

1615
/// Cache of parse trees for incremental parsing.
@@ -51,7 +50,7 @@ impl ParseTreeCache {
5150

5251
let symbols = extract_symbols(lang, &tree, source_bytes, &file_path);
5352

54-
self.entries.insert(file_path, CacheEntry { tree, lang });
53+
self.entries.insert(file_path, CacheEntry { tree });
5554

5655
Some(symbols)
5756
}

crates/codegraph-core/src/extractors/clojure.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ fn walk_clojure(
5151
return;
5252
}
5353

54+
// `next_ns_owned` holds the String so that `next_ns` can borrow it as
55+
// `&str` for the duration of this stack frame. The assignment looks
56+
// "never read" to the compiler but the borrow on the next line reads it.
57+
#[allow(unused_assignments)]
5458
let mut next_ns_owned: Option<String> = None;
5559
let next_ns: Option<&str> = if node.kind() == "list_lit" {
5660
match handle_list_form(node, source, symbols, current_ns) {

0 commit comments

Comments
 (0)