fix: use implementing type name for Rust trait impl methods#329
Merged
askpt merged 1 commit intoMay 21, 2026
Merged
Conversation
When a method is defined in `impl Trait for Type`, the analyzer was incorrectly using the trait name (e.g. `Display`) as the qualifier instead of the implementing type (e.g. `Point`). This made CodeLens labels confusing: `Display::fmt` instead of `Point::fmt`. Fix getFunctionName() to search for the type_identifier that appears after the `for` keyword in impl_item nodes. For inherent impls (`impl Type`) the behaviour is unchanged. Also adds 4 new unit tests (103 passing, up from 100): - trait impl naming in unit.test.ts (3 tests) - trait impl naming in rustAnalyzer.test.ts (1 test) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Rust method qualification for trait implementations so that methods defined in impl Trait for Type are labeled with the implementing type (e.g., Point::fmt) rather than the trait name (e.g., Display::fmt), improving the CodeLens/function naming produced by the Rust metrics analyzer.
Changes:
- Update Rust function naming logic to prefer the type identifier that appears after the
forkeyword inimpl Trait for Typeblocks. - Add unit/integration tests to cover trait impl qualification, inherent impl qualification (unchanged), and mixed impl scenarios.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/metricsAnalyzer/languages/rustAnalyzer.ts |
Adjusts getFunctionName() to select the implementing type (after for) for trait impl methods. |
src/unit/unit.test.ts |
Adds unit tests validating correct naming for trait impls, inherent impls, and mixed impl ordering/complexity. |
src/test/metricsAnalyzer/languages/rustAnalyzer.test.ts |
Adds Rust analyzer test covering the impl Trait for Type naming behavior. |
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.
Caution
Security scanning requires review for Repo Assist
Details
The threat detection results could not be parsed. The workflow output should be reviewed before merging.
Review the workflow run logs for details.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
When a method is defined in
impl Trait for Type, the Rust analyzer was using the trait name as the qualifier instead of the implementing type. For example:Before: CodeLens showed
Display::fmtAfter: CodeLens shows
Point::fmt✅Root Cause
getFunctionName()usedArray.find()on theimpl_item's children to find the firsttype_identifier. Forimpl Trait for Type, the trait name comes first, so it was returned instead of the implementing type.Fix
For
impl_itemnodes containing aforkeyword, search for the type identifier afterfor. For inherentimpl Typeblocks, the existing behavior is unchanged.Tests
Added 4 new unit tests covering:
impl Trait for Type→ImplementingType::methodimpl Type→Type::method(unchanged)Test Status: compile ✅ lint ✅ 103/103 unit tests passing (up from 100)
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
releaseassets.githubusercontent.comSee Network Configuration for more information.