diff --git a/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll index f03ca55b555..6f89be71660 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll @@ -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 diff --git a/rust/ql/test/library-tests/variables/CONSISTENCY/VariableConsistency.expected b/rust/ql/test/library-tests/variables/CONSISTENCY/VariableConsistency.expected deleted file mode 100644 index b3f21ae1271..00000000000 --- a/rust/ql/test/library-tests/variables/CONSISTENCY/VariableConsistency.expected +++ /dev/null @@ -1,2 +0,0 @@ -| main.rs:367:20:367:20 | x | main.rs:364:9:364:9 | x | -| main.rs:367:20:367:20 | x | main.rs:366:18:366:18 | x | diff --git a/rust/ql/test/library-tests/variables/Ssa.expected b/rust/ql/test/library-tests/variables/Ssa.expected index 89e1411259a..4b9764b21c9 100644 --- a/rust/ql/test/library-tests/variables/Ssa.expected +++ b/rust/ql/test/library-tests/variables/Ssa.expected @@ -283,7 +283,6 @@ read | main.rs:349:16:349:16 | x | main.rs:349:16:349:16 | x | main.rs:352:19:352:19 | x | | main.rs:354:20:354:20 | x | main.rs:354:20:354:20 | x | main.rs:357:19:357:19 | x | | main.rs:364:9:364:9 | x | main.rs:364:9:364:9 | x | main.rs:365:11:365:11 | x | -| main.rs:364:9:364:9 | x | main.rs:364:9:364:9 | x | main.rs:367:20:367:20 | x | | main.rs:366:18:366:18 | x | main.rs:366:18:366:18 | x | main.rs:367:20:367:20 | x | | main.rs:373:5:373:6 | a8 | main.rs:373:5:373:6 | a8 | main.rs:379:15:379:16 | a8 | | main.rs:375:9:375:10 | b3 | main.rs:375:9:375:10 | b3 | main.rs:380:15:380:16 | b3 | @@ -581,7 +580,6 @@ adjacentReads | main.rs:334:9:334:9 | x | main.rs:334:9:334:9 | x | main.rs:335:11:335:11 | x | main.rs:343:15:343:15 | x | | main.rs:348:9:348:9 | x | main.rs:348:9:348:9 | x | main.rs:350:7:350:7 | x | main.rs:355:7:355:7 | x | | main.rs:348:9:348:9 | x | main.rs:348:9:348:9 | x | main.rs:355:7:355:7 | x | main.rs:359:19:359:19 | x | -| main.rs:364:9:364:9 | x | main.rs:364:9:364:9 | x | main.rs:365:11:365:11 | x | main.rs:367:20:367:20 | x | | main.rs:391:13:391:15 | a10 | main.rs:391:13:391:15 | a10 | main.rs:395:15:395:17 | a10 | main.rs:404:9:404:11 | a10 | | main.rs:392:13:392:14 | b4 | main.rs:392:13:392:14 | b4 | main.rs:396:15:396:16 | b4 | main.rs:405:9:405:10 | b4 | | main.rs:393:13:393:14 | c2 | main.rs:393:13:393:14 | c2 | main.rs:397:15:397:16 | c2 | main.rs:406:9:406:10 | c2 | diff --git a/rust/ql/test/library-tests/variables/main.rs b/rust/ql/test/library-tests/variables/main.rs index 855eabbe3f6..3ed78f601d6 100644 --- a/rust/ql/test/library-tests/variables/main.rs +++ b/rust/ql/test/library-tests/variables/main.rs @@ -364,7 +364,7 @@ fn match_pattern15() { let x = Some(0); // x1 match x { // $ read_access=x1 Some(x) // x2 - => x, // $ read_access=x2 $ SPURIOUS: read_access=x1 + => x, // $ read_access=x2 _ => 0 }; } diff --git a/rust/ql/test/library-tests/variables/variables.expected b/rust/ql/test/library-tests/variables/variables.expected index b033fd00f79..22c54b9740c 100644 --- a/rust/ql/test/library-tests/variables/variables.expected +++ b/rust/ql/test/library-tests/variables/variables.expected @@ -232,7 +232,6 @@ variableAccess | main.rs:357:19:357:19 | x | main.rs:354:20:354:20 | x | | main.rs:359:19:359:19 | x | main.rs:348:9:348:9 | x | | main.rs:365:11:365:11 | x | main.rs:364:9:364:9 | x | -| main.rs:367:20:367:20 | x | main.rs:364:9:364:9 | x | | main.rs:367:20:367:20 | x | main.rs:366:18:366:18 | x | | main.rs:379:15:379:16 | a8 | main.rs:373:5:373:6 | a8 | | main.rs:380:15:380:16 | b3 | main.rs:375:9:375:10 | b3 | @@ -462,7 +461,6 @@ variableReadAccess | main.rs:357:19:357:19 | x | main.rs:354:20:354:20 | x | | main.rs:359:19:359:19 | x | main.rs:348:9:348:9 | x | | main.rs:365:11:365:11 | x | main.rs:364:9:364:9 | x | -| main.rs:367:20:367:20 | x | main.rs:364:9:364:9 | x | | main.rs:367:20:367:20 | x | main.rs:366:18:366:18 | x | | main.rs:379:15:379:16 | a8 | main.rs:373:5:373:6 | a8 | | main.rs:380:15:380:16 | b3 | main.rs:375:9:375:10 | b3 |