Skip to content

Rust: Adjust jump-to-def for paths with generic arguments #20248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Aug 19, 2025

Before

M1::S2::<S>::new(S);
//  ^^^^^^^ -> jump to S2

After

M1::S2::<S>::new(S);
//  ^^ -> jump to S2

@hvitved hvitved marked this pull request as ready for review August 19, 2025 08:24
@github-actions github-actions bot added the Rust Pull requests that update Rust code label Aug 19, 2025
@hvitved hvitved requested a review from a team as a code owner August 19, 2025 08:24
@Copilot Copilot AI review requested due to automatic review settings August 19, 2025 08:24
Copy link
Contributor

@Copilot 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 refines jump-to-definition behavior for Rust paths containing generic arguments by adjusting the target location from the entire path segment to just the identifier portion. The change ensures that when users invoke jump-to-definition on paths like M1::S2::<S>::new(S), they navigate to the precise identifier S2 rather than the entire segment including generic arguments.

  • Changes the target element for path-based jump-to-definition from PathSegment to NameRef
  • Updates the constructor logic to use the segment's identifier instead of the segment itself
  • Adds test cases with generic struct definitions and usage to validate the improved behavior

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
rust/ql/test/library-tests/definitions/main.rs Adds test struct S2<T> with generic parameter and usage example with generic arguments
rust/ql/test/library-tests/definitions/Definitions.expected Updates expected test results with new definition mappings including generic type references
rust/ql/lib/codeql/rust/internal/Definitions.qll Modifies PathUse class to target NameRef instead of PathSegment for more precise jump-to-definition

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@hvitved hvitved added the no-change-note-required This PR does not need a change note label Aug 19, 2025
@hvitved hvitved requested a review from aibaars August 19, 2025 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant