Skip to content

fix(resolution): Rust field receivers resolve by field type, not by name - #1587

Closed
Dshuishui wants to merge 1 commit into
colbymchenry:mainfrom
Dshuishui:fix/rust-field-receiver
Closed

fix(resolution): Rust field receivers resolve by field type, not by name#1587
Dshuishui wants to merge 1 commit into
colbymchenry:mainfrom
Dshuishui:fix/rust-field-receiver

Conversation

@Dshuishui

@Dshuishui Dshuishui commented Aug 22, 2026

Copy link
Copy Markdown

Fixes #1585.

A Rust method call on a field — self.inner.run() — resolves to whatever same-named method sits nearest, because the receiver is dropped and the call becomes a bare run. Rust has no implicit self, so every call on a field is written this way, and it is worst when the field's type is external (Vec, Arc<…>, another crate) — there the nearest project method is never the right answer.

This follows the shape of the Go field-chain fix (#1276): the receiver is kept, the field's declared type is read from the enclosing type's own declaration, and the method is validated on it. A field whose type cannot be established stays unresolved rather than being guessed.

Field types: Box/Rc/Arc resolve through to what they wrap; Option/Mutex/Vec keep their own methods; a generic type answers with its constructor; dyn Trait resolves to the trait; tuple structs index by position.

Verified by indexing ripgrep and tokio: self-recursive edges the source never had are roughly halved, and several hundred more edges move from the wrong type to the right one. Sampling the call sites that lost their edge and checking them by hand, the large majority were wrong before.

Deeper chains (self.a.b.method()), receivers rooted at a local, and method chains keep their existing behavior — each was implemented and measured, and each removed fewer wrong edges than it cost correct ones.

Coverage is also limited by generic impls qualifying their methods with the trait rather than the type (impl<T> Stream for Empty<T>Stream::poll_next). That is a separate bug, filed as #1588.

Other languages are unaffected — indexing TypeScript, Python and Erlang corpora before and after produces byte-identical nodes, edges and unresolved refs, with no change in indexing time.

The suite passes; the three new tests fail on main and pass here.

@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.

@Dshuishui

Copy link
Copy Markdown
Author

Closing in favour of #1599 — it covers this case and goes further than this PR did: the native kernel path (codegraph-kernel/src/rustlang.rs) and its parity fixture, which this PR left untouched, so byte-parity would not have held here.

Thanks for the quick turnaround on both reports.

@Dshuishui Dshuishui closed this Aug 23, 2026
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.

Rust: a method call on a typed field resolves to a same-named method on the wrong type

1 participant