Skip to content

chore(native): clean up pre-existing Rust dead-code warnings#1484

Merged
carlos-alm merged 8 commits into
mainfrom
chore/rust-dead-code-1456
Jun 13, 2026
Merged

chore(native): clean up pre-existing Rust dead-code warnings#1484
carlos-alm merged 8 commits into
mainfrom
chore/rust-dead-code-1456

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Removes 6 pre-existing dead-code warnings from cargo check:

  • clojure.rs: annotate the lifetime-anchor next_ns_owned assignment with #[allow(unused_assignments)] — the variable is load-bearing (extends the String's lifetime so the &str borrow stays valid), but the compiler can't see through the borrow
  • cfg.rs: remove never-called start_line_of method
  • complexity.rs: remove never-constructed NotHandled variant; convert the resulting irrefutable if let patterns to plain let destructures (no behaviour change)
  • dataflow.rs: remove never-read callee fields from CallReturn and Destructured variants
  • incremental.rs: remove never-read lang field from CacheEntry

cargo check and cargo clippy both produce zero warnings after these changes.

Closes #1456

… 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
- 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.
@claude

claude Bot commented Jun 13, 2026

Copy link
Copy Markdown

Claude finished @carlos-alm's task —— View job


PR Review: chore(native): clean up pre-existing Rust dead-code warnings

  • Gather context and read changed files
  • Phase 1: Root cause analysis
  • Phase 2: Configuration change detection
  • Phase 3: Test integrity
  • Phase 4: Code quality
  • Phase 5: Backlog compliance
  • Final assessment

⚠️ Scope Concern: This PR Contains 5 Independent Concerns

The PR title and description say "remove Rust dead-code warnings," but the branch contains 5 distinct commits touching different layers:

Commit Concern
3892e7d .gitignore — napi-generated artifacts
ef8ea4f Remove unused biome suppression in visitor.test.ts
a372b82 Fix titan-run SKILL.md sync issue
9a52c7c New feature: two new hook scripts + settings.json wiring (snapshot-pre-bash.sh + track-bash-writes.sh)
85a26df Rust dead code removal (what the PR title describes)

Per CLAUDE.md: "One PR = one concern." This PR bundles unrelated changes that each deserve their own PR. The review below covers all of them.


Phase 1: Root Cause Analysis

Rust dead code (commit 85a26df): All five removals are genuine dead code fixes — the compiler's warnings are being addressed correctly, not suppressed:

  • cfg.rs:654-659set_start_line_of method: truly unreferenced, safe to remove.
  • complexity.rsNotHandled variant was never constructed; replacing if let BranchAction::Handled { .. } with let BranchAction::Handled { .. } is correct (single-variant enum, irrefutable pattern). Clean refactor.
  • dataflow.rscallee fields in CallReturn/Destructured variants: confirmed never read — fields are pattern-matched against in find_binding at line 909-914 but the match is purely on discriminant (no field access). Removing them is safe.
  • incremental.rslang field: removed from CacheEntry struct; LanguageKind was stored but never used after storing.
  • clojure.rs:57#[allow(unused_assignments)] on next_ns_owned: the comment explains the lifetime-anchor correctly. This is the right approach — the assignment IS semantically meaningful (the borrow on line 63 reads from it). The suppress is narrowly scoped and well-justified.

Root cause is correctly identified and fixed in each case. No underlying issue is being hidden.


Phase 2: Configuration Change Detection (HIGH SCRUTINY)

Two new hook scripts were added in commit 9a52c7c:

snapshot-pre-bash.sh (PreToolUse/Bash):

  • Takes a git status --porcelain snapshot before each Bash call, keyed by a project-root hash, written to /tmp/.
  • Uses node -e inline for JSON parsing and SHA1 hashing — unusual but functional.
  • Has a fast-path skip for read-only commands. Minor concern: the fast-path regex (^\s*(ls|cat|head|...)) is prefix-anchored and will skip ls foo && echo foo > bar — a compound command starting with ls. This is a tolerable limitation given the hook is informational-only (exits 0 always).
  • Risk: low — informational hook, never blocks.

track-bash-writes.sh (PostToolUse/Bash):

  • Diffs before/after git status --porcelain to find files newly dirtied by the Bash call, then appends to .claude/session-edits.log.
  • Logic is sound: uses comm -13 to find AFTER paths not in BEFORE.
  • Minor concern at line 102: awk '{print $2}' on the session-edits log assumes a fixed two-column format (TIMESTAMP PATH). If PATH contains a space, only the first segment of the path is captured, causing false "already logged" misses. However, this just means a path gets double-logged — it does not cause incorrect blocking. Tolerable for a tracking hook.

settings.json change: Wires both hooks into PreToolUse/Bash and PostToolUse/Bash. The new entries follow the existing pattern. No rules are relaxed.

Test file change (visitor.test.ts): Removes a // biome-ignore lint/suspicious/noExplicitAny comment. This is correct — the suppression was flagged as unused (biome reports this), so removing it cleans up a stale comment. The any annotation on let parse: any remains. Test assertions are unchanged.


Phase 3: Test Integrity

  • tests/unit/visitor.test.ts: Only the unused biome suppression comment was removed. Zero assertion changes. ✓
  • All Rust changes are removals — no new code paths, no new tests needed. ✓

Phase 4: Code Quality

complexity.rs: The NotHandled variant removal + if letlet conversion is idiomatic. Single-variant enums should use plain let. The result compiles to identical machine code.

dataflow.rs: LocalSource::CallReturn and LocalSource::Destructured variants lose their unnamed fields. The find_binding match at line 909-914 still pattern-matches on discriminant only — behavior is identical.

clojure.rs: The #[allow(unused_assignments)] annotation is placed at the correct granularity (the specific let mut statement, not the entire function). The comment above it explaining the borrow-lifetime reason is clear and accurate.

incremental.rs: CacheEntry loses the lang: LanguageKind field. Confirmed the field was set in the constructor but never accessed. The parse_file method still correctly calls lang.tree_sitter_language() using the local variable — clean.


Phase 5: Backlog Compliance

  • Zero-dep: ✓ — No new runtime npm dependencies.
  • Foundation-aligned: ✓ — Rust dead code removal and hook improvements are purely infrastructural; no cloud calls, no new external toolchain.
  • Problem-fit: 2/5 — Dead code cleanup and hook quality improvements don't directly help AI agents navigate codebases. Valuable maintenance work but not core to the stated problem.
  • Breaking: No — all changes are removals or infrastructure tweaks. No DB schema changes, no API/CLI changes, no MCP contract changes.
  • Tier: 1

Critical Concerns

  1. Mixed PR (medium): This bundles 5 unrelated commits. The new Bash tracking hooks (9a52c7c) are a meaningful behavioral change (altering how session-edits.log is populated) that belongs in its own PR. Per the project's own CLAUDE.md rules, this should be split.

  2. Hook regex false-skip (low): snapshot-pre-bash.sh line 29 — the fast-path regex will incorrectly skip compound commands like ls && echo foo > bar or git log; sed -i .... Since the hook is informational-only (exits 0), the worst outcome is a missed file write in the session log. Not blocking.

  3. Space-in-path double-logging (low): track-bash-writes.sh line 102 — awk '{print $2}' will mangle paths containing spaces, causing double-log entries. Not blocking.


Final Assessment

## Root Cause Analysis
Problem Being Solved: Remove 6 pre-existing Rust dead-code warnings from `cargo check`.
Why This Approach: Correct — each warning is addressed at source, not suppressed globally.
Risk Assessment: Low for the Rust changes. The bundled hook feature is more behavioral.

## Backlog Compliance
- Zero-dep: ✓
- Foundation-aligned: ✓
- Problem-fit: 2/5 — maintenance work, not AI-navigation
- Breaking: No
- Tier: 1

## Critical Concerns
1. Mixed PR — 5 unrelated commits (Rust cleanup + new hook feature + SKILL.md fix + gitignore + test cleanup)
2. Bash hook fast-path regex false-skip on compound commands (low, informational-only)
3. Space-in-path double-logging in track-bash-writes.sh (low, tolerable)

## Final Recommendation
- Rating: ⭐⭐⭐ (3/5)
- Action: APPROVE WITH CONDITIONS
- Reasoning: The Rust dead-code removals are clean and correct. The clojure.rs
  lifetime-anchor annotation is properly scoped and justified. The hook changes
  are sound in principle but belong in their own PR per the project's own
  one-concern-per-PR rule. The two minor hook bugs (fast-path regex, space-in-path)
  are tolerable given informational-only semantics, but worth fixing. Recommend
  merging after either (a) splitting the hook feature into a separate PR, or
  (b) accepting the mixed PR given the low risk of the bundled changes.

@github-actions

github-actions Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Codegraph Impact Analysis

7 functions changed123 callers affected across 32 files

  • walk in crates/codegraph-core/src/ast_analysis/complexity.rs:642 (25 transitive callers)
  • walk_all in crates/codegraph-core/src/ast_analysis/complexity.rs:1273 (78 transitive callers)
  • find_binding in crates/codegraph-core/src/ast_analysis/dataflow.rs:901 (5 transitive callers)
  • handle_var_declarator in crates/codegraph-core/src/ast_analysis/dataflow.rs:1109 (6 transitive callers)
  • handle_assignment in crates/codegraph-core/src/ast_analysis/dataflow.rs:1218 (6 transitive callers)
  • ParseTreeCache.parse_file in crates/codegraph-core/src/domain/graph/builder/incremental.rs:40 (0 transitive callers)
  • walk_clojure in crates/codegraph-core/src/extractors/clojure.rs:43 (11 transitive callers)

@greptile-apps

greptile-apps Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR eliminates six pre-existing dead-code compiler warnings across five files without changing any runtime behaviour. All removals and suppressions are correct and the diff is internally consistent.

  • complexity.rs: NotHandled removed from BranchAction; the two if let callsites are correctly converted to irrefutable let patterns because classify_branch always returns Handled. Adding a new variant in the future would produce a compile-time exhaustiveness error, which is the safer outcome.
  • dataflow.rs: callee: String dropped from both LocalSource variants; all three insertion sites and the match arms are consistently updated to unit-variant style.
  • clojure.rs / cfg.rs / incremental.rs: Straightforward lint suppression and field/method removals — no logic altered.

Confidence Score: 5/5

Safe to merge — all changes are dead-code removals with no runtime behaviour affected.

Every change either deletes an unreachable variant/field/method or suppresses a lint for a variable that is genuinely load-bearing. The irrefutable let conversion in complexity.rs is correct because classify_branch exhaustively returns the sole remaining variant, and the three dataflow.rs call sites are all consistently updated after the field removal.

No files require special attention.

Important Files Changed

Filename Overview
crates/codegraph-core/src/extractors/clojure.rs Adds #[allow(unused_assignments)] to next_ns_owned — attribute is correctly scoped and the explanatory comment accurately describes the lifetime-anchor role of the variable.
crates/codegraph-core/src/ast_analysis/cfg.rs Removes unused start_line_of method from CfgBuilder; no callers, no behavioral change.
crates/codegraph-core/src/ast_analysis/complexity.rs Removes NotHandled variant making BranchAction a single-variant enum, then converts both if let BranchAction::Handled to irrefutable let — correct since classify_branch always returns Handled.
crates/codegraph-core/src/ast_analysis/dataflow.rs Drops callee: String from CallReturn and Destructured variants, updates all three insertion sites and the match arms to use plain unit patterns — correct and complete.
crates/codegraph-core/src/domain/graph/builder/incremental.rs Removes never-read lang: LanguageKind field from CacheEntry; the only write site is updated accordingly.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[cargo check / clippy warnings] --> B{Warning type}
    B -->|unused method| C[cfg.rs\nRemove start_line_of]
    B -->|unused variant| D[complexity.rs\nRemove NotHandled\nif let → let]
    B -->|unused struct fields| E[dataflow.rs\nRemove callee fields\nUpdate 3 call sites + match arms]
    B -->|unused struct field| F[incremental.rs\nRemove lang field\nUpdate insert site]
    B -->|unused assignment| G[clojure.rs\nAdd allow attribute\nwith explanatory comment]
    C --> H[Zero warnings]
    D --> H
    E --> H
    F --> H
    G --> H
Loading

Reviews (6): Last reviewed commit: "chore: merge origin/main into chore/rust..." | Re-trigger Greptile

…urce 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.
@carlos-alm

Copy link
Copy Markdown
Contributor Author

Fixed — simplified the stale struct-pattern syntax in find_binding's match arms: LocalSource::CallReturn { .. } and LocalSource::Destructured { .. } are now plain unit patterns (LocalSource::CallReturn / LocalSource::Destructured) to match the updated enum definition. See commit 33423f0.

@carlos-alm

Copy link
Copy Markdown
Contributor Author

@greptileai

@carlos-alm

Copy link
Copy Markdown
Contributor Author

Addressed Claude's feedback: the stale struct-pattern syntax in find_binding's match arms was fixed in commit 33423f0LocalSource::CallReturn { .. } and LocalSource::Destructured { .. } are now plain unit variants to match the updated fieldless enum definition. The other observations (mixed PR scope, hook minor concerns) are noted; the relevant scope concerns were mitigated by having the hooks changes land in a separate PR (#1483) while the Rust dead-code changes remain in this one.

carlos-alm and others added 2 commits June 12, 2026 22:42
Resolves add/add conflicts in .claude/hooks/snapshot-pre-bash.sh and
.claude/hooks/track-bash-writes.sh by taking main's version, which
includes the concurrent-safe per-command hash keying introduced in #1483.
@carlos-alm

Copy link
Copy Markdown
Contributor Author

Resolved merge conflict from the #1483 overlap: both branches added the same two hook scripts (.claude/hooks/snapshot-pre-bash.sh and .claude/hooks/track-bash-writes.sh) independently, causing an add/add conflict. Resolved by taking main's version from #1483, which includes the concurrent-safe per-command-hash keying. The Rust dead-code changes are unaffected. See merge commit a6e50da.

@carlos-alm

Copy link
Copy Markdown
Contributor Author

@greptileai

@carlos-alm carlos-alm merged commit dc22b03 into main Jun 13, 2026
28 checks passed
@carlos-alm carlos-alm deleted the chore/rust-dead-code-1456 branch June 13, 2026 06:31
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore(native): clean up pre-existing Rust dead-code warnings

1 participant