diff --git a/rust/ql/lib/codeql/rust/printast/PrintAst.qll b/rust/ql/lib/codeql/rust/printast/PrintAst.qll index b485efe8022b3..32a29a95755ca 100644 --- a/rust/ql/lib/codeql/rust/printast/PrintAst.qll +++ b/rust/ql/lib/codeql/rust/printast/PrintAst.qll @@ -4,17 +4,23 @@ import PrintAstNode +pragma[nomagic] +private predicate orderBy( + PrintAstNode n, string filepath, int startline, int startcolumn, int endline, int endcolumn +) { + n.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) +} + cached private int getOrder(PrintAstNode node) { - node = - rank[result](PrintAstNode n, Location loc | - loc = n.getLocation() - | - n - order by - loc.getFile().getAbsolutePath(), loc.getStartLine(), loc.getStartColumn(), loc.getEndLine(), - loc.getEndColumn() - ) + exists(string filepath | + node = + rank[result](PrintAstNode n, int startline, int startcolumn, int endline, int endcolumn | + orderBy(n, filepath, startline, startcolumn, endline, endcolumn) + | + n order by startline, startcolumn, endline, endcolumn + ) + ) } /** Holds if `node` belongs to the output tree, and its property `key` has the given `value`. */ diff --git a/rust/ql/lib/codeql/rust/printast/PrintAstNode.qll b/rust/ql/lib/codeql/rust/printast/PrintAstNode.qll index db5afa9b708c3..cc8d2304be2fd 100644 --- a/rust/ql/lib/codeql/rust/printast/PrintAstNode.qll +++ b/rust/ql/lib/codeql/rust/printast/PrintAstNode.qll @@ -67,9 +67,7 @@ class PrintAstNode extends TPrintAstNode { abstract Locatable getAstNode(); } -private string prettyPrint(Locatable e) { - result = "[" + concat(e.getPrimaryQlClasses(), ", ") + "] " + e -} +private string prettyPrint(Locatable e) { result = "[" + e.getPrimaryQlClasses() + "] " + e } private class Unresolved extends Locatable { Unresolved() { this != this.resolve() }