Skip to content

fix: use implementing type name for Rust trait impl methods#329

Merged
askpt merged 1 commit into
mainfrom
repo-assist/improve-rust-trait-impl-naming-303f6017b354d3bf
May 21, 2026
Merged

fix: use implementing type name for Rust trait impl methods#329
askpt merged 1 commit into
mainfrom
repo-assist/improve-rust-trait-impl-naming-303f6017b354d3bf

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

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:

impl fmt::Display for Point {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { ... }
}

Before: CodeLens showed Display::fmt
After: CodeLens shows Point::fmt

Root Cause

getFunctionName() used Array.find() on the impl_item's children to find the first type_identifier. For impl Trait for Type, the trait name comes first, so it was returned instead of the implementing type.

Fix

For impl_item nodes containing a for keyword, search for the type identifier after for. For inherent impl Type blocks, the existing behavior is unchanged.

Tests

Added 4 new unit tests covering:

  • impl Trait for TypeImplementingType::method
  • impl TypeType::method (unchanged)
  • multiple trait/inherent impl methods in same file

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

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "releaseassets.githubusercontent.com"

See Network Configuration for more information.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@79c99dfd73f3b7ad8ab2b0f4944838018dbe4736

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>
@askpt askpt marked this pull request as ready for review May 21, 2026 19:50
@askpt askpt self-requested a review as a code owner May 21, 2026 19:50
Copilot AI review requested due to automatic review settings May 21, 2026 19:50
@askpt askpt changed the title [repo-assist] fix: use implementing type name for Rust trait impl methods fix: use implementing type name for Rust trait impl methods May 21, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 for keyword in impl Trait for Type blocks.
  • 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.

@askpt askpt merged commit fd1e8f9 into main May 21, 2026
15 checks passed
@askpt askpt deleted the repo-assist/improve-rust-trait-impl-naming-303f6017b354d3bf branch May 21, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants