-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Rust: Add ConstAccess class with getConst() predicate #20736
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: hvitved <[email protected]>
Co-authored-by: hvitved <[email protected]>
0b9321f to
3477763
Compare
3477763 to
0ca62ca
Compare
There was a problem hiding this 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 support for identifying and querying constant accesses in Rust code. It adds a new ConstAccess class that extends PathExpr to represent expressions that access constant declarations.
Key changes:
- Created a new
ConstAccessclass that uses path resolution to identify when a path expression refers to a constant - Added comprehensive test coverage including global constants, associated constants, and module constants
- Updated the extractor test expectations to reflect that constant accesses are now identified as
ConstAccessrather than justPathExpr
Reviewed Changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| rust/ql/lib/codeql/rust/elements/internal/ConstImpl.qll | Added ConstAccess class definition that extends PathExpr and resolves paths to constants |
| rust/ql/lib/codeql/rust/elements/ConstAccess.qll | Created public interface for the ConstAccess class |
| rust/ql/lib/rust.qll | Added import for the new ConstAccess element |
| rust/ql/.gitattributes | Removed linguist-generated marker from ConstImpl.qll to allow manual edits |
| rust/ql/.generated.list | Removed ConstImpl.qll entry as it's now manually maintained |
| rust/ql/test/library-tests/const_access/* | Added comprehensive test suite for constant access functionality |
| rust/ql/test/extractor-tests/macro-expansion/PrintAst.expected | Updated expected output to reflect ConstAccess classification |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * } | ||
| * ``` | ||
| */ | ||
| class ConstAccess extends PathExprImpl::PathExpr { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have expected ConstAccess to extend VariableAccess (and re-use the getVariable() method).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think keeping them separate is easier, and also makes more sense IMO (a "constant variable" is a bit of an oxymoron).
Adds
ConstAccessclass for identifying constant accesses in Rust code, analogous to the existingVariableAccessclass.Changes
ConstAccessclass inConstImpl.qllextendsPathExprBase, usesresolvePath()to resolve paths toConstitemsgetConst()predicate returns the constant being accessedrust/ql/test/library-tests/const_access/covers global, associated, and module constantsExample Usage
Example code patterns matched:
Implementation follows the same pattern as
resolveSelfTy()/resolveTraitTy()inPathResolution.qll.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
releases.bazel.build/usr/local/lib/node_modules/@bazel/bazelisk/bazelisk-linux_amd64 run //rust:install(dns block)/usr/local/lib/node_modules/@bazel/bazelisk/bazelisk-linux_amd64 run ast-generator:inject-sources(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
ConstAccessclass #20735✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.