Skip to content

Commit 1486f8a

Browse files
committed
Rust: fix multiplePositions consistency check
1 parent 5718ef4 commit 1486f8a

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

rust/ql/lib/codeql/rust/elements/internal/ArrayRepeatExprImpl.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ module Impl {
2727
this.getRepeatLength().toAbbreviatedString() + "]"
2828
}
2929

30-
override Expr getRepeatOperand() { result = this.getExpr(0) }
30+
override Expr getExpr(int index) { none() }
3131

32-
override Expr getRepeatLength() { result = this.getExpr(1) }
32+
override Expr getRepeatOperand() { result = super.getExpr(0) }
33+
34+
override Expr getRepeatLength() { result = super.getExpr(1) }
3335
}
3436
}

rust/ql/lib/codeql/rust/internal/AstConsistency.qll

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,12 @@ query predicate multipleChildren(Element parent, int index, Element child1, Elem
6060
}
6161

6262
/**
63-
* Holds if `child` has multiple positions amongst the `accessor` children
64-
* of `parent`.
65-
*
66-
* Children are allowed to have multiple positions for _different_ accessors,
67-
* for example in an array repeat expression `[1; 10]`, `1` has positions for
68-
* both `getRepeatOperand()` and `getExpr()`.
63+
* Holds if `child` has multiple positions amongst the children of `parent`.
6964
*/
70-
query predicate multiplePositions(Element parent, int pos1, int pos2, string accessor, Element child) {
71-
child = getChildAndAccessor(parent, pos1, accessor) and
72-
child = getChildAndAccessor(parent, pos2, accessor) and
73-
pos1 != pos2
65+
query predicate multiplePositions(Element parent, int pos1, int pos2, Element child) {
66+
child = getChildAndAccessor(parent, pos1, _) and
67+
child = getChildAndAccessor(parent, pos2, _) and
68+
pos1 < pos2
7469
}
7570

7671
/**
@@ -97,5 +92,5 @@ int getAstInconsistencyCounts(string type) {
9792
result = count(Element e | multipleChildren(_, _, e, _) | e)
9893
or
9994
type = "Multiple positions" and
100-
result = count(Element e | multiplePositions(_, _, _, _, e) | e)
95+
result = count(Element e | multiplePositions(_, _, _, e) | e)
10196
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| gen_array_repeat_expr.rs:5:5:5:11 | [1; 10] | getNumberOfExprs: | 2 | getNumberOfAttrs: | 0 | getRepeatOperand: | gen_array_repeat_expr.rs:5:6:5:6 | 1 | getRepeatLength: | gen_array_repeat_expr.rs:5:9:5:10 | 10 |
1+
| gen_array_repeat_expr.rs:5:5:5:11 | [1; 10] | getNumberOfExprs: | 0 | getNumberOfAttrs: | 0 | getRepeatOperand: | gen_array_repeat_expr.rs:5:6:5:6 | 1 | getRepeatLength: | gen_array_repeat_expr.rs:5:9:5:10 | 10 |
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
| gen_array_repeat_expr.rs:5:5:5:11 | [1; 10] | 0 | gen_array_repeat_expr.rs:5:6:5:6 | 1 |
2-
| gen_array_repeat_expr.rs:5:5:5:11 | [1; 10] | 1 | gen_array_repeat_expr.rs:5:9:5:10 | 10 |

0 commit comments

Comments
 (0)