Skip to content

Rust: Add Operation class #19454

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 6 commits into
base: main
Choose a base branch
from
Open

Rust: Add Operation class #19454

wants to merge 6 commits into from

Conversation

geoffw0
Copy link
Contributor

@geoffw0 geoffw0 commented May 2, 2025

Unify various classes representing operations under a single Operation class, providing a single consistent interface (with getOperatorName() and getAnOperand()) for reasoning about them.

The idea is to get things in order before I follow up with another PR that will add new subclasses, allowing us to find things like the dereference expression (*) and comparison operations more easily.

@Copilot Copilot AI review requested due to automatic review settings May 2, 2025 15:54
@geoffw0 geoffw0 requested a review from a team as a code owner May 2, 2025 15:54
@geoffw0 geoffw0 added the Rust Pull requests that update Rust code label May 2, 2025
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 introduces a unified Operation class in the Rust QL library, letting all unary, binary, assignment, and logical expressions share a consistent interface with getOperatorName() and getAnOperand().

  • Defined OperationImpl::Operation and aliased it as Operation
  • Updated PrefixExpr and BinaryExpr implementations to mix in Operation
  • Added imports of Operation in query modules and extended tests to exercise the new API

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

File Description
rust/ql/lib/codeql/rust/elements/Operation.qll Added the abstract Operation class and alias
rust/ql/lib/codeql/rust/elements/internal/PrefixExprImpl.qll Extended PrefixExpr to implement Operation
rust/ql/lib/codeql/rust/elements/internal/BinaryExprImpl.qll Extended BinaryExpr to implement Operation
rust/ql/test/library-tests/operations/test.rs Expanded inline tests for various operators
Comments suppressed due to low confidence (1)

rust/ql/test/library-tests/operations/test.rs:54

  • No inline expectation is provided for the ? try operator. Consider adding an expectation comment, for example: // $ Operation Op=? Operands=1 PrefixExpr to validate its classification and operands.
res?;

@geoffw0
Copy link
Contributor Author

geoffw0 commented May 6, 2025

DCA shows nothing interesting, which is what we'd expect for a change like this.

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