Skip to content

Commit e71b3d7

Browse files
committed
Rust: Debug preds
1 parent cbf4c8c commit e71b3d7

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

rust/ql/lib/codeql/rust/internal/TypeInference.qll

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@ private module Input2 implements InputSig2 {
215215
constraint = object.getTrait()
216216
)
217217
}
218+
219+
private predicate testConditionSatisfiesConstraint(
220+
TypeAbstraction abs, TypeMention condition, TypeMention constraint
221+
) {
222+
conditionSatisfiesConstraint(abs, condition, constraint) and
223+
constraint.resolveType().(TraitType).getTrait().getName().getText() = "TryFuture"
224+
}
218225
}
219226

220227
private module M2 = Make2<Input2>;
@@ -2638,8 +2645,9 @@ private module Debug {
26382645
private Locatable getRelevantLocatable() {
26392646
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
26402647
result.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
2641-
filepath.matches("%/sqlx.rs") and
2642-
startline = [56 .. 60]
2648+
filepath.matches("%/path_utils.rs") and
2649+
startline = [72 .. 75]
2650+
// startline = [91 .. 97]
26432651
)
26442652
}
26452653

@@ -2670,6 +2678,14 @@ private module Debug {
26702678
t = inferCallExprBaseType(n, path)
26712679
}
26722680

2681+
predicate debugInferCallExprBaseMatchingType(AstNode n, TypePath path, Type t) {
2682+
n = getRelevantLocatable() and
2683+
exists(CallExprBaseMatchingInput::Access a, CallExprBaseMatchingInput::AccessPosition apos |
2684+
n = a.getNodeAt(apos) and
2685+
t = CallExprBaseMatching::inferAccessType(a, apos, path)
2686+
)
2687+
}
2688+
26732689
predicate debugTypeMention(TypeMention tm, TypePath path, Type type) {
26742690
tm = getRelevantLocatable() and
26752691
tm.resolveTypeAt(path) = type

shared/typeinference/codeql/typeinference/internal/TypeInference.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,13 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
784784
)
785785
}
786786

787+
predicate debugConditionSatisfiesConstraintTypeAt(
788+
TypeAbstraction abs, TypeMention condition, TypeMention constraint, TypePath path, Type t
789+
) {
790+
conditionSatisfiesConstraintTypeAt(abs, condition, constraint, path, t) and
791+
constraint.toString().matches("%AsRef%")
792+
}
793+
787794
/**
788795
* Holds if its possible for a type with `conditionRoot` at the root to
789796
* satisfy a constraint with `constraintRoot` at the root through `abs`,

0 commit comments

Comments
 (0)