Skip to content

Commit 604e865

Browse files
committed
Rust: Take where clauses into account in path resolution
1 parent 9922024 commit 604e865

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

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

+14-6
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,21 @@ private class BlockExprItemNode extends ItemNode instanceof BlockExpr {
579579
}
580580

581581
private class TypeParamItemNode extends ItemNode instanceof TypeParam {
582+
private WherePred getAWherePred() {
583+
exists(ItemNode declaringItem |
584+
this = resolveTypeParamPathTypeRepr(result.getTypeRepr()) and
585+
result = declaringItem.getADescendant() and
586+
this = declaringItem.getADescendant()
587+
)
588+
}
589+
582590
pragma[nomagic]
583591
Path getABoundPath() {
584-
result = super.getTypeBoundList().getABound().getTypeRepr().(PathTypeRepr).getPath()
592+
exists(TypeBoundList tbl | result = tbl.getABound().getTypeRepr().(PathTypeRepr).getPath() |
593+
tbl = super.getTypeBoundList()
594+
or
595+
tbl = this.getAWherePred().getTypeBoundList()
596+
)
585597
}
586598

587599
pragma[nomagic]
@@ -602,11 +614,7 @@ private class TypeParamItemNode extends ItemNode instanceof TypeParam {
602614
predicate hasTraitBound() {
603615
exists(this.getABoundPath())
604616
or
605-
exists(ItemNode declaringItem, WherePred wp |
606-
this = resolveTypeParamPathTypeRepr(wp.getTypeRepr()) and
607-
wp = declaringItem.getADescendant() and
608-
this = declaringItem.getADescendant()
609-
)
617+
exists(this.getAWherePred())
610618
}
611619

612620
/**

rust/ql/test/library-tests/path-resolution/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ mod m24 {
568568
T: TraitA // $ item=I111 item=I1151
569569
{
570570
fn call_trait_a(&self) {
571-
self.data.trait_a_method(); // $ MISSING: item=I110
571+
self.data.trait_a_method(); // $ item=I110
572572
} // I116
573573
}
574574

@@ -580,8 +580,8 @@ mod m24 {
580580
T: TraitA, // $ item=I111 item=I1161
581581
{
582582
fn call_both(&self) {
583-
self.data.trait_a_method(); // $ MISSING: item=I110
584-
self.data.trait_b_method(); // $ MISSING: item=I112
583+
self.data.trait_a_method(); // $ item=I110
584+
self.data.trait_b_method(); // $ item=I112
585585
} // I117
586586
}
587587

rust/ql/test/library-tests/type-inference/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ mod function_trait_bounds_2 {
623623
where
624624
T1: Into<T2>,
625625
{
626-
x.into()
626+
x.into() // $ method=into
627627
}
628628

629629
pub fn f() {

0 commit comments

Comments
 (0)