Rust: Take where clauses into account in path resolution

This commit is contained in:
Tom Hvitved
2025-04-02 10:45:18 +02:00
parent cc85a09b39
commit e26695fc51
3 changed files with 18 additions and 10 deletions

View File

@@ -581,9 +581,21 @@ private class BlockExprItemNode extends ItemNode instanceof BlockExpr {
}
class TypeParamItemNode extends ItemNode instanceof TypeParam {
private WherePred getAWherePred() {
exists(ItemNode declaringItem |
this = resolveTypeParamPathTypeRepr(result.getTypeRepr()) and
result = declaringItem.getADescendant() and
this = declaringItem.getADescendant()
)
}
pragma[nomagic]
Path getABoundPath() {
result = super.getTypeBoundList().getABound().getTypeRepr().(PathTypeRepr).getPath()
exists(TypeBoundList tbl | result = tbl.getABound().getTypeRepr().(PathTypeRepr).getPath() |
tbl = super.getTypeBoundList()
or
tbl = this.getAWherePred().getTypeBoundList()
)
}
pragma[nomagic]
@@ -605,11 +617,7 @@ class TypeParamItemNode extends ItemNode instanceof TypeParam {
Stages::PathResolutionStage::ref() and
exists(this.getABoundPath())
or
exists(ItemNode declaringItem, WherePred wp |
this = resolveTypeParamPathTypeRepr(wp.getTypeRepr()) and
wp = declaringItem.getADescendant() and
this = declaringItem.getADescendant()
)
exists(this.getAWherePred())
}
/**

View File

@@ -568,7 +568,7 @@ mod m24 {
T: TraitA // $ item=I111 item=I1151
{
fn call_trait_a(&self) {
self.data.trait_a_method(); // $ MISSING: item=I110
self.data.trait_a_method(); // $ item=I110
} // I116
}
@@ -580,8 +580,8 @@ mod m24 {
T: TraitA, // $ item=I111 item=I1161
{
fn call_both(&self) {
self.data.trait_a_method(); // $ MISSING: item=I110
self.data.trait_b_method(); // $ MISSING: item=I112
self.data.trait_a_method(); // $ item=I110
self.data.trait_b_method(); // $ item=I112
} // I117
}

View File

@@ -623,7 +623,7 @@ mod function_trait_bounds_2 {
where
T1: Into<T2>,
{
x.into()
x.into() // $ method=into
}
pub fn f() {