diff --git a/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll index 4b94546d8027..80c70f6f6fa7 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll @@ -378,7 +378,7 @@ module Impl { } } - private module DenseRankInput implements DenseRankInputSig3 { + private module DenseRankInput implements DenseRankInputSig2 { class C1 = VariableScope; class C2 = string; @@ -401,7 +401,7 @@ module Impl { * to a variable named `name` in the variable scope `scope`. */ private int rankVariableOrAccess(VariableScope scope, string name, VariableOrAccessCand v) { - result = DenseRank3::denseRank(scope, name, v) - 1 + v = DenseRank2::denseRank(scope, name, result + 1) } /** diff --git a/shared/util/codeql/util/DenseRank.qll b/shared/util/codeql/util/DenseRank.qll index d1ba4ae4b62c..0dccbbd48803 100644 --- a/shared/util/codeql/util/DenseRank.qll +++ b/shared/util/codeql/util/DenseRank.qll @@ -58,12 +58,12 @@ module DenseRank { rnk = rank[result](int rnk0 | rnk0 = getRank(_) | rnk0) } - /** Gets the dense rank of `r`. */ - int denseRank(Ranked r) { result = rankRank(r, getRank(r)) } + /** Gets the `Ranked` value for which the dense rank is `rnk`. */ + Ranked denseRank(int rnk) { rnk = rankRank(result, getRank(result)) } } -/** Provides the input to `DenseRank2`. */ -signature module DenseRankInputSig2 { +/** Provides the input to `DenseRank1`. */ +signature module DenseRankInputSig1 { /** A ranking context. */ bindingset[this] class C; @@ -77,7 +77,7 @@ signature module DenseRankInputSig2 { } /** Same as `DenseRank`, but allows for a context consisting of one element. */ -module DenseRank2 { +module DenseRank1 { private import Input private int rankRank(C c, Ranked r, int rnk) { @@ -85,17 +85,15 @@ module DenseRank2 { rnk = rank[result](int rnk0 | rnk0 = getRank(c, _) | rnk0) } - /** Gets the dense rank of `r` in the context provided by `c`. */ - int denseRank(C c, Ranked r) { - exists(int rnk | - result = rankRank(c, r, rnk) and - rnk = getRank(c, r) - ) - } + /** + * Gets the `Ranked` value for which the dense rank in the context provided by + * `c` is `rnk`. + */ + Ranked denseRank(C c, int rnk) { rnk = rankRank(c, result, getRank(c, result)) } } -/** Provides the input to `DenseRank3`. */ -signature module DenseRankInputSig3 { +/** Provides the input to `DenseRank2`. */ +signature module DenseRankInputSig2 { /** A ranking context. */ bindingset[this] class C1; @@ -113,7 +111,7 @@ signature module DenseRankInputSig3 { } /** Same as `DenseRank`, but allows for a context consisting of two elements. */ -module DenseRank3 { +module DenseRank2 { private import Input private int rankRank(C1 c1, C2 c2, Ranked r, int rnk) { @@ -121,11 +119,11 @@ module DenseRank3 { rnk = rank[result](int rnk0 | rnk0 = getRank(c1, c2, _) | rnk0) } - /** Gets the dense rank of `r` in the context provided by `c1` and `c2`. */ - int denseRank(C1 c1, C2 c2, Ranked r) { - exists(int rnk | - result = rankRank(c1, c2, r, rnk) and - rnk = getRank(c1, c2, r) - ) + /** + * Gets the `Ranked` value for which the dense rank in the context provided by + * `c1` and `c2` is `rnk`. + */ + Ranked denseRank(C1 c1, C2 c2, int rnk) { + rnk = rankRank(c1, c2, result, getRank(c1, c2, result)) } }