fix(dead-code): stop false-flagging Rust modules/impl-blocks/trait-defaults as dead (closes #228) - #282
Merged
Merged
Conversation
|
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>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Root cause
_detect_dead_from_registryinscripts/deadcode_engine.pyflags every backend node withref_count == 0 && status == "dead". Three Rust structural/implicit node kinds always haveref_count == 0in the raw call graph because they never appear as a CALLS target, yet they are never dead:mod foo { ... },type == "module") — a namespace referenced by path, not called. Previously onlymod testswas exempted.impl X(type == "impl",fn == "impl_X", idfile.rs:LINE:impl:X). The block is a container; only its methods should be analyzed individually.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 testsinline-test case was already fixed earlier; this closes the residual gap.)Fix (only
scripts/deadcode_engine.py)type in ("module", "impl")inside the dead branch — structural containers, never callable._RUST_TRAIT_DEFAULT_METHODSwhitelist; 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_scanharness oftest_graph_accuracy_golden.py) with a fixture containing amod, animplwith a used method, animpl Default { fn default() }, and a genuinely-dead standalonefn orphan_helper.The control assertion
test_genuinely_dead_fn_is_flaggedprovesorphan_helperIS 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 viagit stash) and is unrelated to this change.🤖 Generated with Claude Code