Skip to content

fix(dead-code): stop false-flagging Rust modules/impl-blocks/trait-defaults as dead (closes #228) - #282

Merged
Wolfvin merged 1 commit into
mainfrom
fix/issue-228-rust-impl-dead
Jul 14, 2026
Merged

fix(dead-code): stop false-flagging Rust modules/impl-blocks/trait-defaults as dead (closes #228)#282
Wolfvin merged 1 commit into
mainfrom
fix/issue-228-rust-impl-dead

Conversation

@Wolfvin

@Wolfvin Wolfvin commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Root cause

_detect_dead_from_registry in scripts/deadcode_engine.py flags every backend node with ref_count == 0 && status == "dead". Three Rust structural/implicit node kinds always have ref_count == 0 in the raw call graph because they never appear as a CALLS target, yet they are never dead:

  1. Module declarations (mod foo { ... }, type == "module") — a namespace referenced by path, not called. Previously only mod tests was exempted.
  2. Impl blocks — synthetic node impl X (type == "impl", fn == "impl_X", id file.rs:LINE:impl:X). The block is a container; only its methods should be analyzed individually.
  3. Trait-default methods (default, clone, fmt, drop, eq, hash, …) — invoked implicitly via derive macros, generic trait dispatch, and ..Default::default() spread, which the CALLS extractor cannot observe.

(The #[cfg(test)] mod tests inline-test case was already fixed earlier; this closes the residual gap.)

Fix (only scripts/deadcode_engine.py)

  • Skip any node with type in ("module", "impl") inside the dead branch — structural containers, never callable.
  • Add a targeted _RUST_TRAIT_DEFAULT_METHODS whitelist; skip Rust fns whose bare name is on it. Narrow by design — any standalone fn not on the list stays eligible.

Verification

New regression test tests/test_issue228_rust_impl_dead.py (mirrors the _run_scan harness of test_graph_accuracy_golden.py) with a fixture containing a mod, an impl with a used method, an impl Default { fn default() }, and a genuinely-dead standalone fn orphan_helper.

$ python -m pytest ../tests/test_issue228_rust_impl_dead.py -q
....                                                                     [100%]
4 passed

The control assertion test_genuinely_dead_fn_is_flagged proves orphan_helper IS still reported dead — the filter narrows false positives without disabling genuine detection.

Full dead-code suite (-k "dead or deadcode or issue228"): 56 passed, 1 failed. The single failure (test_confidence.py::...test_dead_code_json_output_has_schema_version) is pre-existing — it fails identically on the base commit (verified via git stash) and is unrelated to this change.

🤖 Generated with Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

…faults as dead (closes #228)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Wolfvin
Wolfvin merged commit cdedf59 into main Jul 14, 2026
1 of 7 checks passed
@sonarqubecloud

Copy link
Copy Markdown

@Wolfvin
Wolfvin deleted the fix/issue-228-rust-impl-dead branch July 14, 2026 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant