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(rust): widen type_use captures to wrapper shapes (#2386)

Aman90143a48e4ed
diff --git a/packages/core/src/repowise/core/ingestion/queries/rust.scm b/packages/core/src/repowise/core/ingestion/queries/rust.scm
index 4b3911944..2cbf657fb 100644
--- a/packages/core/src/repowise/core/ingestion/queries/rust.scm
+++ b/packages/core/src/repowise/core/ingestion/queries/rust.scm
@@ -336,30 +336,17 @@
; edges. The dead-code reference the old captures existed to provide is
; preserved, because type_use is a file-level use edge.
;
-; Each pattern captures the bare ``type_identifier`` rather than the enclosing
-; type node, keeping this a 1:1 move; the Rust head extractor in
-; parser_helpers.py unwraps ``&T`` / ``Box<T>`` / ``dyn T`` / ``std::io::Error``
-; for the day a capture widens, and filters the 55 rust builtins.
-
-; Type reference in function parameter: fn foo(x: MyType)
-(parameter
- type: (type_identifier) @param.type
-)
-
-; Type reference via &dyn: fn foo(x: &dyn MyTrait)
+; Each pattern captures the parameter/return type node itself (whatever shape
+; it is), not just a bare ``type_identifier``; the Rust head extractor in
+; parser_helpers.py unwraps ``&T`` / ``Box<T>`` / ``dyn T`` / ``impl T`` /
+; ``std::io::Error`` down to the head identifier, and filters the 55 rust
+; builtins, so a wrapper capture cannot mint a wrong edge -- it resolves to
+; the same head name a bare capture would, or to nothing.
+
+; Type reference in function parameter: fn foo(x: MyType), fn foo(x: &Foo),
+; fn foo(x: &dyn MyTrait), fn foo(x: impl MyTrait), fn foo(x: std::io::Error)
(parameter
- type: (reference_type
- type: (dynamic_type
- (type_identifier) @param.type
- )
- )
-)
-
-; Type reference via impl Trait: fn foo(x: impl MyTrait)
-(parameter
- type: (abstract_type
- (type_identifier) @param.type
- )
+ type: (_) @param.type
)
; Trait bound in generic parameter: fn foo<T: MyTrait>()
@@ -368,9 +355,10 @@
(type_identifier) @param.type
)
-; Return type reference: fn foo() -> MyType
+; Return type reference: fn foo() -> MyType, fn foo() -> &Foo,
+; fn foo() -> std::io::Error
(function_item
- return_type: (type_identifier) @param.type
+ return_type: (_) @param.type
)
; dyn Trait in type arguments: Box<dyn MyTrait>, Arc<dyn MyTrait>
diff --git a/tests/unit/ingestion/test_rust_type_use.py b/tests/unit/ingestion/test_rust_type_use.py
index 0dadd5a55..15c12b774 100644
--- a/tests/unit/ingestion/test_rust_type_use.py
+++ b/tests/unit/ingestion/test_rust_type_use.py
@@ -124,6 +124,50 @@ class TestRustTypePositionsAreNotCalls:
assert "Report" not in targets
+class TestRustWrapperShapesReachTheResolver:
+ """Query-level coverage for issue #2298: `&Foo`, `Box<Foo>` and
+ `std::io::Error` in parameter and return position were previously
+ invisible to `type_use` because the query captured only a bare
+ `type_identifier`; the head extractor already unwrapped these shapes,
+ the query just never offered them."""
+
+ def test_reference_parameter(self) -> None:
+ body = "fn take(x: &MyType) {}\n"
+ assert "MyType" in _type_names(body)
+ assert "MyType" not in _call_targets(body)
+
+ def test_boxed_parameter(self) -> None:
+ body = "fn take(x: Box<MyType>) {}\n"
+ assert "MyType" in _type_names(body)
+ assert "MyType" not in _call_targets(body)
+
+ def test_scoped_parameter(self) -> None:
+ body = "fn take(x: std::io::Error) {}\n"
+ assert "Error" in _type_names(body)
+ assert "Error" not in _call_targets(body)
+
+ def test_reference_return_type(self) -> None:
+ body = "fn make() -> &MyType { todo!() }\n"
+ assert "MyType" in _type_names(body)
+ assert "MyType" not in _call_targets(body)
+
+ def test_boxed_return_type(self) -> None:
+ body = "fn make() -> Box<MyType> { todo!() }\n"
+ assert "MyType" in _type_names(body)
+ assert "MyType" not in _call_targets(body)
+
+ def test_scoped_return_type(self) -> None:
+ body = "fn make() -> std::io::Error { todo!() }\n"
+ assert "Error" in _type_names(body)
+ assert "Error" not in _call_targets(body)
+
+ def test_the_generic_constructor_itself_is_not_captured(self) -> None:
+ # "Box" is a builtin the head extractor filters -- only the type
+ # argument inside it should reach the resolver.
+ body = "fn take(x: Box<MyType>) {}\n"
+ assert "Box" not in _type_names(body)
+
+
# ---------------------------------------------------------------------------
# Head extractor: shapes the C#-shaped default could not read
# ---------------------------------------------------------------------------