Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions rust/ql/consistency-queries/VariableConsistency.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @name Variable inconsistencies
* @description Lists the variable inconsistencies in the database. This query is intended for internal use.
* @kind table
* @id rust/diagnostics/variable-consistency
*/

import codeql.rust.internal.VariableConsistency
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,12 @@ module Impl {
VariableAccessCand cand, VariableScope scope, string name, int nestLevel, int ord
) {
name = cand.getName() and
scope = [cand.(VariableScope), getEnclosingScope(cand)] and
(
scope = cand
or
not cand instanceof VariableScope and
scope = getEnclosingScope(cand)
) and
ord = getPreOrderNumbering(scope, cand) and
nestLevel = 0
or
Expand Down
10 changes: 10 additions & 0 deletions rust/ql/lib/codeql/rust/internal/VariableConsistency.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Provides logic for recognizing variable inconsistencies.
*/

private import rust

query predicate multipleVariableTargets(VariableAccess va, Variable v1) {
va = v1.getAnAccess() and
strictcount(va.getVariable()) > 1
}
2,040 changes: 1,031 additions & 1,009 deletions rust/ql/test/library-tests/variables/Cfg.expected

Large diffs are not rendered by default.

783 changes: 395 additions & 388 deletions rust/ql/test/library-tests/variables/Ssa.expected

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions rust/ql/test/library-tests/variables/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,15 @@ fn match_pattern14() {
}
}

fn match_pattern15() {
let x = Some(0); // x1
match x { // $ read_access=x1
Some(x) // x2
=> x, // $ read_access=x2
_ => 0
};
}

fn param_pattern1(
a8: &str, // a8
(
Expand Down Expand Up @@ -757,6 +766,7 @@ fn main() {
match_pattern12();
match_pattern13();
match_pattern14();
match_pattern15();
param_pattern1("a", ("b", "c"));
param_pattern2(Either::Left(45));
destruct_assignment();
Expand Down
Loading