Skip to content

Rust: Path resolution for crate::{self as foo} #19816

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 Jun 18, 2025

For example, use std::{self as ztd} introduces ztd as an alias for std.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Jun 18, 2025
@hvitved hvitved marked this pull request as ready for review June 19, 2025 08:19
@Copilot Copilot AI review requested due to automatic review settings June 19, 2025 08:19
@hvitved hvitved requested a review from a team as a code owner June 19, 2025 08:19
@hvitved hvitved requested a review from paldepind June 19, 2025 08:19
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

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} in main.rs.
  • Extended PathResolution.qll to treat Crate nodes as valid targets when resolving self.

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 existing proc_macro entries.
| main.rs:632:7:632:16 | proc_macro | file://:0:0:0:0 | Crate([email protected]) |

rust/ql/lib/codeql/rust/internal/PathResolution.qll:208

  • [nitpick] The new if block for including this instanceof Crate is indented more deeply than the surrounding clauses; aligning its indentation with the other conditions would improve readability and maintain consistency.
    if

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant