Skip to content

Rust: Fix variable access overlap#20727

Merged
hvitved merged 4 commits intogithub:mainfrom
hvitved:rust/variable-overlap-fix
Oct 31, 2025
Merged

Rust: Fix variable access overlap#20727
hvitved merged 4 commits intogithub:mainfrom
hvitved:rust/variable-overlap-fix

Conversation

@hvitved
Copy link
Copy Markdown
Contributor

@hvitved hvitved commented Oct 30, 2025

Fixes an issue where a variable access could resolve to multiple variables (see test code for example).

DCA looks good.

@github-actions github-actions Bot added the Rust Pull requests that update Rust code label Oct 30, 2025
Comment thread rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll Fixed
@hvitved hvitved force-pushed the rust/variable-overlap-fix branch from 3978004 to 5a24674 Compare October 30, 2025 20:56
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Oct 31, 2025
@hvitved hvitved marked this pull request as ready for review October 31, 2025 07:15
@hvitved hvitved requested a review from a team as a code owner October 31, 2025 07:15
Copilot AI review requested due to automatic review settings October 31, 2025 07:15
Copy link
Copy Markdown
Contributor

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 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.qll to 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.

Comment thread rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll
Copy link
Copy Markdown
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

LGTM, quick question about the consistency query...

Comment thread rust/ql/consistency-queries/VariableConsistency.ql Outdated
Comment thread rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll
geoffw0
geoffw0 previously approved these changes Oct 31, 2025
Copy link
Copy Markdown
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

LGTM.

@hvitved hvitved merged commit f672f6b into github:main Oct 31, 2025
19 checks passed
@hvitved hvitved deleted the rust/variable-overlap-fix branch October 31, 2025 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants