Rust: Extend jump-to-def query with method calls#19809
Merged
hvitved merged 1 commit intogithub:mainfrom Jun 18, 2025
Merged
Conversation
aae01b9 to
5cd7295
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the jump-to-definition query in the Rust CodeQL library to handle method calls and to restrict path-based definitions to individual segments (e.g., only M2 in M1::M2).
- Introduces a new
MethodUseclass to resolve method call identifiers - Refines
PathUseto work onPathSegmentnodes and include call disambiguation - Updates test suite to verify method and segmented-path resolutions
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| rust/ql/test/library-tests/definitions/main.rs | Adds a nested module with S::method and corresponding use in main for testing method-resolution |
| rust/ql/test/library-tests/definitions/Definitions.expected | Updates expected definitions output to include new path-segment and method entries |
| rust/ql/lib/codeql/rust/internal/Definitions.qll | Extends PathUse to PathSegment, adds call-aware logic, and introduces MethodUse for method call resolution |
Comments suppressed due to low confidence (2)
rust/ql/lib/codeql/rust/internal/Definitions.qll:143
- [nitpick] The method name getCall() is somewhat vague; consider renaming it to getAssociatedCallExpr() or similar to clarify its purpose.
private CallExpr getCall() { result.getFunction().(PathExpr).getPath() = path }
rust/ql/lib/codeql/rust/internal/Definitions.qll:138
- [nitpick] Add a brief comment above this class explaining that it handles individual path segments (including calls) for jump-to-definition resolutions, to aid future readers.
private class PathUse extends Use instanceof PathSegment {
Comment on lines
+146
to
+149
| // Our call resolution logic may disambiguate some calls, so only use those | ||
| result.asItemNode() = this.getCall().getStaticTarget() | ||
| or | ||
| not exists(this.getCall()) and |
There was a problem hiding this comment.
Consider caching the result of getCall() in a local variable or predicate to avoid traversing the AST twice in getDefinition, improving performance.
Suggested change
| // Our call resolution logic may disambiguate some calls, so only use those | |
| result.asItemNode() = this.getCall().getStaticTarget() | |
| or | |
| not exists(this.getCall()) and | |
| // Cache the result of getCall() to avoid traversing the AST twice | |
| CallExpr cachedCall = this.getCall(); | |
| // Our call resolution logic may disambiguate some calls, so only use those | |
| result.asItemNode() = cachedCall.getStaticTarget() | |
| or | |
| not exists(cachedCall) and |
paldepind
approved these changes
Jun 18, 2025
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.
Also fixes jump-to-def for paths so only the path segment is used, for example in
M1::M2only theM2segment jumps to theM2module, not the entireM1::M2path).