Rust: Path resolution for crate::{self as foo}#19816
Merged
hvitved merged 2 commits intogithub:mainfrom Jun 20, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
Adds support for resolving paths introduced via crate::{self as foo} (e.g., use std::{self as ztd}) by updating tests and extending the QL path‐resolution logic.
- Updated expected outputs in library‐tests to include
std::{self as ztd}entries and adjust offsets. - Added an example import and usage of
std::{self as ztd}inmain.rs. - Extended
PathResolution.qllto treatCratenodes as valid targets when resolvingself.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| rust/ql/test/library-tests/path-resolution/path-resolution.expected | Adjusted several SourceFile offsets and inserted new lines for the ztd alias. |
| rust/ql/test/library-tests/path-resolution/main.rs | Added use std::{self as ztd} and example usage; reformatted impl AStruct block. |
| rust/ql/test/library-tests/path-resolution/CONSISTENCY/PathResolutionConsistency.expected | Shifted line numbers for proc_macro entries to match the updated main.rs. |
| rust/ql/lib/codeql/rust/internal/PathResolution.qll | Expanded the self‐resolution clause to include Crate instances. |
Comments suppressed due to low confidence (2)
rust/ql/test/library-tests/path-resolution/CONSISTENCY/PathResolutionConsistency.expected:6
- Consider adding consistency tests for the new
std::{self as ztd}alias to ensure the alias is resolved exactly once, similar to the existingproc_macroentries.
| main.rs:632:7:632:16 | proc_macro | file://:0:0:0:0 | Crate(proc_macro@0.0.0) |
rust/ql/lib/codeql/rust/internal/PathResolution.qll:208
- [nitpick] The new
ifblock for includingthis instanceof Crateis indented more deeply than the surrounding clauses; aligning its indentation with the other conditions would improve readability and maintain consistency.
if
paldepind
approved these changes
Jun 20, 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.
For example,
use std::{self as ztd}introducesztdas an alias forstd.