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(dataflow): Rust single-segment, grouped and aliased use declarations are not variable reads (#3575)

Soham05Hanchate2739e2708d56
diff --git a/packages/core/src/repowise/core/analysis/health/dataflow/dialects/rust.py b/packages/core/src/repowise/core/analysis/health/dataflow/dialects/rust.py
index 6718078f2..8c48cbdeb 100644
--- a/packages/core/src/repowise/core/analysis/health/dataflow/dialects/rust.py
+++ b/packages/core/src/repowise/core/analysis/health/dataflow/dialects/rust.py
@@ -208,6 +208,8 @@ class RustDefUseDialect(BaseDefUseDialect):
if node is None:
return
t = node.type
+ if t == "use_declaration":
+ return
if t in _ASSIGN_KINDS:
self._targets(node.child_by_field_name("left"), defs, uses)
self._process(node.child_by_field_name("right"), defs, uses)
diff --git a/tests/unit/health/test_dataflow_langs.py b/tests/unit/health/test_dataflow_langs.py
index 7469b4984..6b2c87474 100644
--- a/tests/unit/health/test_dataflow_langs.py
+++ b/tests/unit/health/test_dataflow_langs.py
@@ -821,6 +821,46 @@ def test_rust_def_use_classification():
assert "new" not in uses
+ "import_stmt",
+ [
+ "use foo;",
+ "use foo as bar;",
+ "use Shape::{Circle, Square};",
+ "use std::fmt;",
+ "use Shape::*;",
+ ],
+)
+def test_rust_imports_are_not_variable_reads(import_stmt):
+ fn = _first(
+ "rust",
+ f"""
+ fn main() {{
+ {import_stmt}
+ let a = 1;
+ }}
+ """,
+ )
+
+ assert not _use_names(fn), (
+ f"Import {import_stmt!r} should not create variable reads; "
+ f"got {_use_names(fn)}"
+ )
+
+
+def test_rust_import_does_not_read_local_with_same_name():
+ fn = _first(
+ "rust",
+ """
+ fn main() {
+ let io = 1;
+ use std::{fs, io};
+ }
+ """,
+ )
+
+ assert "io" not in _use_names(fn)
+
def test_rust_while_let_binder_is_a_may_def():
fn = _first(
"rust",