mirror of
https://github.com/github/codeql.git
synced 2026-04-25 00:35:20 +02:00
Rust: Add more consistency checks
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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 |
|
||||
|
||||
@@ -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 |
|
||||
|
||||
Reference in New Issue
Block a user