Skip to content

Commit e26695f

Browse files
committed
Rust: Take where clauses into account in path resolution
1 parent cc85a09 commit e26695f

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
@@ -581,9 +581,21 @@ private class BlockExprItemNode extends ItemNode instanceof BlockExpr {
581581
}
582582

583583
class TypeParamItemNode extends ItemNode instanceof TypeParam {
584+
private WherePred getAWherePred() {
585+
exists(ItemNode declaringItem |
586+
this = resolveTypeParamPathTypeRepr(result.getTypeRepr()) and
587+
result = declaringItem.getADescendant() and
588+
this = declaringItem.getADescendant()
589+
)
590+
}
591+
584592
pragma[nomagic]
585593
Path getABoundPath() {
586-
result = super.getTypeBoundList().getABound().getTypeRepr().(PathTypeRepr).getPath()
594+
exists(TypeBoundList tbl | result = tbl.getABound().getTypeRepr().(PathTypeRepr).getPath() |
595+
tbl = super.getTypeBoundList()
596+
or
597+
tbl = this.getAWherePred().getTypeBoundList()
598+
)
587599
}
588600

589601
pragma[nomagic]
@@ -605,11 +617,7 @@ class TypeParamItemNode extends ItemNode instanceof TypeParam {
605617
Stages::PathResolutionStage::ref() and
606618
exists(this.getABoundPath())
607619
or
608-
exists(ItemNode declaringItem, WherePred wp |
609-
this = resolveTypeParamPathTypeRepr(wp.getTypeRepr()) and
610-
wp = declaringItem.getADescendant() and
611-
this = declaringItem.getADescendant()
612-
)
620+
exists(this.getAWherePred())
613621
}
614622

615623
/**

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)