From 16dcc5c27842bb90a4f008768faf7854900d8306 Mon Sep 17 00:00:00 2001 From: Simon Friis Vindum Date: Thu, 12 Dec 2024 11:23:22 +0100 Subject: [PATCH] Rust: Add variable capture consistency query --- rust/ql/consistency-queries/VariableCaptureConsistency.ql | 8 ++++++++ .../CONSISTENCY/VariableCaptureConsistency.expected | 5 +++++ .../CONSISTENCY/VariableCaptureConsistency.expected | 4 ++++ 3 files changed, 17 insertions(+) create mode 100644 rust/ql/consistency-queries/VariableCaptureConsistency.ql create mode 100644 rust/ql/test/library-tests/controlflow/CONSISTENCY/VariableCaptureConsistency.expected create mode 100644 rust/ql/test/library-tests/variables/CONSISTENCY/VariableCaptureConsistency.expected diff --git a/rust/ql/consistency-queries/VariableCaptureConsistency.ql b/rust/ql/consistency-queries/VariableCaptureConsistency.ql new file mode 100644 index 00000000000..894d654c029 --- /dev/null +++ b/rust/ql/consistency-queries/VariableCaptureConsistency.ql @@ -0,0 +1,8 @@ +/** + * @name Variable capture data flow inconsistencies + * @description Lists the variable capture data flow inconsistencies in the database. This query is intended for internal use. + * @kind table + * @id rust/diagnostics/variable-capture-data-flow-consistency + */ + +import codeql.rust.dataflow.internal.DataFlowImpl::VariableCapture::Flow::ConsistencyChecks diff --git a/rust/ql/test/library-tests/controlflow/CONSISTENCY/VariableCaptureConsistency.expected b/rust/ql/test/library-tests/controlflow/CONSISTENCY/VariableCaptureConsistency.expected new file mode 100644 index 00000000000..b768e7abeae --- /dev/null +++ b/rust/ql/test/library-tests/controlflow/CONSISTENCY/VariableCaptureConsistency.expected @@ -0,0 +1,5 @@ +variableAccessAstNesting +| test.rs:396:26:396:26 | b | test.rs:409:28:414:9 | { ... } | CapturedVariable access is not nested in the defining callable | +| test.rs:409:23:409:25 | foo | test.rs:409:28:414:9 | { ... } | CapturedVariable access is not nested in the defining callable | +consistencyOverview +| CapturedVariable access is not nested in the defining callable | 2 | diff --git a/rust/ql/test/library-tests/variables/CONSISTENCY/VariableCaptureConsistency.expected b/rust/ql/test/library-tests/variables/CONSISTENCY/VariableCaptureConsistency.expected new file mode 100644 index 00000000000..2cd30314cac --- /dev/null +++ b/rust/ql/test/library-tests/variables/CONSISTENCY/VariableCaptureConsistency.expected @@ -0,0 +1,4 @@ +variableAccessAstNesting +| variables.rs:436:13:436:13 | i | variables.rs:437:17:439:5 | { ... } | CapturedVariable access is not nested in the defining callable | +consistencyOverview +| CapturedVariable access is not nested in the defining callable | 1 |