Skip to content

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

Merged
hvitved merged 1 commit into
github:aibaars/rust-extract-libsfrom
hvitved:rust-extract-libs-follow-up
May 19, 2025
Merged

Rust: Follow-up work to make path resolution and type inference tests pass again#19519
hvitved merged 1 commit into
github:aibaars/rust-extract-libsfrom
hvitved:rust-extract-libs-follow-up

Conversation

@hvitved

@hvitvedhvitved commented May 19, 2025

Copy link
Copy Markdown
Contributor

#19506 follow-up.

@github-actionsgithub-actionsBot 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
CopilotAI review requested due to automatic review settings May 19, 2025 13:04
@hvitved
hvitved requested a review from a team as a code ownerMay 19, 2025 13:04
@hvitved
hvitved requested a review from aibaarsMay 19, 2025 13:04

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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
FileDescription
rust/ql/test/library-tests/type-inference/type-inference.qlAdded source/macro filters to inferType and related predicates
rust/ql/test/library-tests/type-inference/type-inference.expectedUpdated expected test outputs to real stdlib Result and Arguments paths
rust/ql/test/library-tests/path-resolution/path-resolution.qlApplied source/macro filters to resolvePath queries
rust/ql/test/library-tests/path-resolution/path-resolution.expectedUpdated expected module paths to real stdlib locations
rust/ql/test/TestUtils.qllExpanded toBeTested to only include source AST nodes
rust/ql/lib/utils/test/PathResolutionInlineExpectationsTest.qllAdded source/macro filters to inline-expectations test helpers
rust/ql/lib/codeql/rust/internal/TypeInference.qllAdjusted hard-coded debug line number
rust/ql/lib/codeql/rust/internal/PathResolution.qllReplaced getModuleNode with getSourceFile, removed outdated isRoot
rust/ql/lib/codeql/rust/frameworks/stdlib/Stdlib.qllRefactored OptionEnum/ResultEnum to use getASuccessor
rust/ql/lib/codeql/rust/elements/internal/MacroCallImpl.qllIntroduced isInMacroExpansion and getATokenTreeNode
rust/ql/lib/codeql/rust/elements/internal/LocationImpl.qllRenamed/extended location predicates (startsBefore, etc.)
rust/ql/lib/codeql/rust/elements/internal/LocatableImpl.qllChanged fromSource to delegate to File.fromSource()
rust/ql/lib/codeql/rust/elements/internal/AstNodeImpl.qllHooked isInMacroExpansion into new MacroCallImpl predicates
rust/ql/lib/codeql/files/FileSystem.qllStrengthened 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

result.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
filepath.matches("%/main.rs") and
startline = 28
startline = 948

CopilotAIMay 19, 2025

Copy link

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()

CopilotAIMay 19, 2025

Copy link

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.
| 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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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-libsMay 19, 2025
@hvitved
hvitved deleted the rust-extract-libs-follow-up branch May 19, 2025 19:11
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RustPull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@hvitved@aibaars