Skip to content

Rust: Follow-up work to make path resolution and type inference tests pass again #19519

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

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented May 19, 2025

#19506 follow-up.

@github-actions github-actions bot added the Rust Pull requests that update Rust code label May 19, 2025
@hvitved hvitved marked this pull request as ready for review May 19, 2025 13:04
@Copilot Copilot AI review requested due to automatic review settings May 19, 2025 13:04
@hvitved hvitved requested a review from a team as a code owner May 19, 2025 13:04
@hvitved hvitved requested a review from aibaars May 19, 2025 13:04
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 updates the Rust QL tests and library modules to filter out macro-generated AST nodes, enforce source-only elements, and reflect real standard-library paths in test expectations. Key changes include:

  • Adding fromSource() and isFromMacroExpansion() filters in type inference and path resolution tests
  • Updating expected outputs to point to the real core/result definitions in the Rust stdlib
  • Implementing new predicates (fromSource, startsBefore, startsStrictlyBefore, etc.) and adapting path-resolution and type-inference logic in the QL libraries

Reviewed Changes

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

Show a summary per file
File Description
rust/ql/test/library-tests/type-inference/type-inference.ql Added source/macro filters to inferType and related predicates
rust/ql/test/library-tests/type-inference/type-inference.expected Updated expected test outputs to real stdlib Result and Arguments paths
rust/ql/test/library-tests/path-resolution/path-resolution.ql Applied source/macro filters to resolvePath queries
rust/ql/test/library-tests/path-resolution/path-resolution.expected Updated expected module paths to real stdlib locations
rust/ql/test/TestUtils.qll Expanded toBeTested to only include source AST nodes
rust/ql/lib/utils/test/PathResolutionInlineExpectationsTest.qll Added source/macro filters to inline-expectations test helpers
rust/ql/lib/codeql/rust/internal/TypeInference.qll Adjusted hard-coded debug line number
rust/ql/lib/codeql/rust/internal/PathResolution.qll Replaced getModuleNode with getSourceFile, removed outdated isRoot
rust/ql/lib/codeql/rust/frameworks/stdlib/Stdlib.qll Refactored OptionEnum/ResultEnum to use getASuccessor
rust/ql/lib/codeql/rust/elements/internal/MacroCallImpl.qll Introduced isInMacroExpansion and getATokenTreeNode
rust/ql/lib/codeql/rust/elements/internal/LocationImpl.qll Renamed/extended location predicates (startsBefore, etc.)
rust/ql/lib/codeql/rust/elements/internal/LocatableImpl.qll Changed fromSource to delegate to File.fromSource()
rust/ql/lib/codeql/rust/elements/internal/AstNodeImpl.qll Hooked isInMacroExpansion into new MacroCallImpl predicates
rust/ql/lib/codeql/files/FileSystem.qll Strengthened File.fromSource() by requiring a relative path
Comments suppressed due to low confidence (1)

rust/ql/test/TestUtils.qll:17

  • The CrateElement predicate no longer includes this instanceof Crate, which may prevent actual Crate elements from being recognized. Consider restoring this instanceof Crate in the predicate.
this instanceof NamedCrate

@@ -1042,7 +1042,7 @@ private module Debug {
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
result.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
filepath.matches("%/main.rs") and
startline = 28
startline = 948
Copy link
Preview

Copilot AI May 19, 2025

Choose a reason for hiding this comment

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

[nitpick] Avoid hard-coding line numbers in production predicates. Consider computing this value dynamically or defining a named constant to explain its origin.

Copilot uses AI. Check for mistakes.

Comment on lines +16 to 21
f.getAPrecedingComment().getCommentText() = value and
f.fromSource()
or
not exists(f.getAPrecedingComment()) and
not any(f.getAPrecedingComment()).fromSource() and
// TODO: Default to canonical path once that is available
value = f.getName().getText()
Copy link
Preview

Copilot AI May 19, 2025

Choose a reason for hiding this comment

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

[nitpick] To make the OR conditions clearer, wrap each branch in parentheses. For example: (f.getAPrecedingComment().getCommentText() = value and f.fromSource()) or (not any(f.getAPrecedingComment()).fromSource() and value = f.getName().getText()).

Copilot uses AI. Check for mistakes.

@@ -597,7 +597,9 @@ inferType
| main.rs:658:19:658:22 | self | Fst | main.rs:656:10:656:12 | Fst |
| main.rs:658:19:658:22 | self | Snd | main.rs:656:15:656:17 | Snd |
| main.rs:659:43:659:82 | MacroExpr | | main.rs:656:15:656:17 | Snd |
| main.rs:659:50:659:81 | MacroExpr | | file:///Users/hvitved/.rustup/toolchains/1.85-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:549:1:584:1 | Arguments |
Copy link
Contributor

Choose a reason for hiding this comment

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

Here the home directory is leaking into expected test output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe those should be fixed when you merge latest main into your branch, which contains

.

@hvitved hvitved merged commit f7f434b into github:aibaars/rust-extract-libs May 19, 2025
4 of 8 checks passed
@hvitved hvitved deleted the rust-extract-libs-follow-up branch May 19, 2025 19:11
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