Rust: Add more consistency checks

This commit is contained in:
Tom Hvitved
2025-03-07 08:38:37 +01:00
parent fcdffc4e73
commit 795ba25895
3 changed files with 35 additions and 0 deletions

View File

@@ -89,6 +89,26 @@ query predicate multiplePathResolutions(Path p, ItemNode i) {
strictcount(resolvePath(p)) > 1
}
/** Holds if `call` has multiple static call targets including `target`. */
query predicate multipleStaticCallTargets(CallExprBase call, Callable target) {
target = call.getStaticTarget() and
strictcount(call.getStaticTarget()) > 1
}
/** Holds if `fe` resolves to multiple record fields including `field`. */
query predicate multipleRecordFields(FieldExpr fe, RecordField field) {
field = fe.getRecordField() and
strictcount(fe.getRecordField()) > 1
}
/** Holds if `fe` resolves to multiple tuple fields including `field`. */
query predicate multipleTupleFields(FieldExpr fe, TupleField field) {
field = fe.getTupleField() and
strictcount(fe.getTupleField()) > 1
}
import codeql.rust.elements.internal.TypeInference::Consistency
/**
* Gets counts of abstract syntax tree inconsistencies of each type.
*/
@@ -117,4 +137,13 @@ int getAstInconsistencyCounts(string type) {
or
type = "Multiple path resolutions" and
result = count(Path p | multiplePathResolutions(p, _) | p)
or
type = "Multiple static call targets" and
result = count(CallExprBase call | multipleStaticCallTargets(call, _) | call)
or
type = "Multiple record fields" and
result = count(FieldExpr fe | multipleRecordFields(fe, _) | fe)
or
type = "Multiple tuple fields" and
result = count(FieldExpr fe | multipleTupleFields(fe, _) | fe)
}

View File

@@ -1,3 +1,6 @@
multiplePathResolutions
| main.rs:118:9:118:9 | f | main.rs:104:5:106:5 | fn f |
| main.rs:118:9:118:9 | f | main.rs:110:5:112:5 | fn f |
multipleStaticCallTargets
| main.rs:118:9:118:11 | f(...) | main.rs:104:5:106:5 | fn f |
| main.rs:118:9:118:11 | f(...) | main.rs:110:5:112:5 | fn f |

View File

@@ -4,5 +4,8 @@
| Multiple path resolutions | 0 |
| Multiple positions | 0 |
| Multiple primary QL classes | 0 |
| Multiple record fields | 0 |
| Multiple static call targets | 0 |
| Multiple toStrings | 0 |
| Multiple tuple fields | 0 |
| No location | 0 |