Rust: Fix variable access overlap#20727
Merged
hvitved merged 4 commits intogithub:mainfrom Oct 31, 2025
Merged
Conversation
3978004 to
5a24674
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug in variable access resolution where a single variable access could incorrectly resolve to multiple variable declarations. The fix adjusts the scope resolution logic to prevent this overlap by ensuring that if a candidate is itself a VariableScope, it's not also treated as being enclosed by a scope.
Key Changes
- Modified scope resolution logic in
VariableImpl.qllto prevent double-counting of variable scopes - Added a new test case (
match_pattern15) demonstrating the fix - Added consistency query infrastructure to detect variable resolution issues
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll | Fixed scope resolution to prevent a variable access from resolving to multiple variables |
| rust/ql/test/library-tests/variables/main.rs | Added test case match_pattern15 demonstrating the overlap issue |
| rust/ql/test/library-tests/variables/variables.expected | Updated test expectations with new variable declarations and accesses |
| rust/ql/test/library-tests/variables/Ssa.expected | Updated SSA analysis expectations following the fix |
| rust/ql/lib/codeql/rust/internal/VariableConsistency.qll | Added query predicate to detect multiple variable targets |
| rust/ql/consistency-queries/VariableConsistency.ql | Added consistency query to list variable inconsistencies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
geoffw0
reviewed
Oct 31, 2025
Contributor
geoffw0
left a comment
There was a problem hiding this comment.
LGTM, quick question about the consistency query...
50412da to
6d64800
Compare
geoffw0
approved these changes
Oct 31, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes an issue where a variable access could resolve to multiple variables (see test code for example).
DCA looks good.