Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(dead-code): treat Rust impl blocks as uncallable and non-importable (#2418)

Rishabh Mishrab58c5f7f5c8a
diff --git a/packages/core/src/repowise/core/analysis/dead_code/analyzer.py b/packages/core/src/repowise/core/analysis/dead_code/analyzer.py
index e3fd1d0c8..462059fee 100644
--- a/packages/core/src/repowise/core/analysis/dead_code/analyzer.py
+++ b/packages/core/src/repowise/core/analysis/dead_code/analyzer.py
@@ -265,6 +265,7 @@ _UNIVERSAL_NON_IMPORTABLE: frozenset[str] = frozenset(
"type_alias",
"namespace",
"module",
+ "impl",
}
)
@@ -354,6 +355,7 @@ _UNCALLABLE_TYPE_KINDS: frozenset[str] = frozenset(
"interface",
"enum",
"type_alias",
+ "impl",
}
)
diff --git a/tests/unit/dead_code/test_unused_exports.py b/tests/unit/dead_code/test_unused_exports.py
index c74edd5d7..9d117bffc 100644
--- a/tests/unit/dead_code/test_unused_exports.py
+++ b/tests/unit/dead_code/test_unused_exports.py
@@ -276,3 +276,42 @@ def test_unused_export_not_rescued_for_index_stem():
)
names = {f.symbol_name for f in report.findings if f.kind == DeadCodeKind.UNUSED_EXPORT}
assert "stranded_export" in names
+
+
+def test_unused_export_rust_impl_non_importable():
+ """An impl block cannot be imported by name and must not be flagged as unused export."""
+ g = _build_graph(
+ nodes={
+ "src/lib.rs": {
+ "is_entry_point": False,
+ "is_test": False,
+ "is_api_contract": False,
+ "language": "rust",
+ "symbol_count": 1,
+ "symbols": [
+ {
+ "name": "MyStruct",
+ "kind": "impl",
+ "visibility": "public",
+ "language": "rust",
+ "decorators": [],
+ "start_line": 10,
+ "end_line": 25,
+ "complexity_estimate": 1,
+ },
+ ],
+ },
+ },
+ )
+ analyzer = DeadCodeAnalyzer(g, git_meta_map={})
+ report = analyzer.analyze(
+ {
+ "detect_unreachable_files": False,
+ "detect_unused_internals": False,
+ "detect_zombie_packages": False,
+ "min_confidence": 0.0,
+ }
+ )
+ names = {f.symbol_name for f in report.findings if f.kind == DeadCodeKind.UNUSED_EXPORT}
+ assert "MyStruct" not in names
+
diff --git a/tests/unit/dead_code/test_unused_internal.py b/tests/unit/dead_code/test_unused_internal.py
index 710e8489d..5b54209d1 100644
--- a/tests/unit/dead_code/test_unused_internal.py
+++ b/tests/unit/dead_code/test_unused_internal.py
@@ -339,3 +339,42 @@ def test_unused_internal_still_flagged_when_imports_dont_carry_name():
)
names = {f.symbol_name for f in report.findings if f.kind == DeadCodeKind.UNUSED_INTERNAL}
assert "_unused_helper" in names
+
+
+def test_unused_internal_rust_impl_uncallable():
+ """An impl block is an uncallable structural container; it must not be flagged as unused internal."""
+ g = _build_graph(
+ nodes={
+ "src/lib.rs": {
+ "is_entry_point": False,
+ "is_test": False,
+ "is_api_contract": False,
+ "language": "rust",
+ "symbol_count": 1,
+ "symbols": [
+ {
+ "name": "MyStruct",
+ "kind": "impl",
+ "visibility": "private",
+ "language": "rust",
+ "decorators": [],
+ "start_line": 10,
+ "end_line": 25,
+ "complexity_estimate": 1,
+ },
+ ],
+ },
+ },
+ )
+ analyzer = DeadCodeAnalyzer(g, git_meta_map={})
+ report = analyzer.analyze(
+ {
+ "detect_unreachable_files": False,
+ "detect_unused_exports": False,
+ "detect_zombie_packages": False,
+ "min_confidence": 0.0,
+ }
+ )
+ names = {f.symbol_name for f in report.findings if f.kind == DeadCodeKind.UNUSED_INTERNAL}
+ assert "MyStruct" not in names
+