Skip to content

Rust: Generate canonical paths for builtins #19732

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

Merged
merged 2 commits into from
Jun 12, 2025

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Jun 11, 2025

For builtins, like str, we model them as belonging to the core crate when computing canonical paths.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label Jun 11, 2025
@hvitved hvitved force-pushed the rust/builtin-canonical-paths branch from 6eb5bd6 to 69e549f Compare June 11, 2025 19:15
@hvitved hvitved marked this pull request as ready for review June 12, 2025 07:03
@Copilot Copilot AI review requested due to automatic review settings June 12, 2025 07:03
@hvitved hvitved requested a review from a team as a code owner June 12, 2025 07:03
@hvitved hvitved requested a review from redsun82 June 12, 2025 07:03
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 extends canonical path resolution to include Rust built-in types (e.g., str) by modeling them in the core crate and updates related tests.

  • Extend PathResolution.qll to recognize builtins under core
  • Update test queries to import PathResolution and Builtins and cover a trim example
  • Adjust expected outputs to include the generated <core::str>::trim path

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
rust/ql/lib/codeql/rust/internal/PathResolution.qll Include BuiltinType under core in hasChild to support builtins
rust/ql/test/extractor-tests/canonical_path/canonical_paths.ql Import new modules and extend canonicalPath predicate for trim
rust/ql/test/extractor-tests/canonical_path/canonical_paths.expected Add expected <core::str>::trim entry
rust/ql/test/extractor-tests/canonical_path/canonical_paths.qlref Add query and post-process directives
rust/ql/test/extractor-tests/canonical_path_disabled/canonical_paths.qlref Add query and post-process directives for disabled tests
rust/ql/test/extractor-tests/canonical_path_disabled/canonical_paths.expected Add expected <core::str>::trim entry for disabled tests

@@ -1,8 +1,20 @@
import rust
import TestUtils
private import codeql.rust.internal.PathResolution
private import codeql.rust.frameworks.stdlib.Bultins
Copy link
Preview

Copilot AI Jun 12, 2025

Choose a reason for hiding this comment

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

The module name Bultins appears misspelled; it should likely be Builtins to match the framework's naming.

Copilot uses AI. Check for mistakes.

Comment on lines +378 to +379
this.getName() = "core" and
child instanceof Builtins::BuiltinType
Copy link
Preview

Copilot AI Jun 12, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider adding parentheses around the this.getName() = "core" and child instanceof Builtins::BuiltinType clause to make grouping explicit and improve readability.

Suggested change
this.getName() = "core" and
child instanceof Builtins::BuiltinType
(this.getName() = "core" and
child instanceof Builtins::BuiltinType)

Copilot uses AI. Check for mistakes.

Copy link
Contributor

@redsun82 redsun82 left a comment

Choose a reason for hiding this comment

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

LGTM!

@hvitved hvitved merged commit d667f7d into github:main Jun 12, 2025
16 checks passed
@hvitved hvitved deleted the rust/builtin-canonical-paths branch June 12, 2025 08:47
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.

2 participants