Skip to content

Commit c8f25db

Browse files
committed
wip3
1 parent e4646e3 commit c8f25db

File tree

1 file changed

+30
-83
lines changed

1 file changed

+30
-83
lines changed

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

Lines changed: 30 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,35 +1790,20 @@ private module AssocFunctionResolution {
17901790
FunctionPosition selfPos, DerefChain derefChain, TypePath strippedTypePath, Type strippedType,
17911791
int n
17921792
) {
1793-
(
1794-
this.supportsAutoDerefAndBorrow() and
1795-
selfPos.isSelf()
1796-
or
1797-
// needed for the `hasNoCompatibleTarget` check in
1798-
// `ArgSatisfiesBlanketLikeConstraintInput::hasBlanketCandidate`
1799-
derefChain.isEmpty()
1800-
) and
1793+
this.supportsAutoDerefAndBorrow() and
1794+
selfPos.isSelf() and
18011795
strippedType =
18021796
this.getComplexStrippedSelfType(selfPos, derefChain, TNoBorrowKind(), strippedTypePath) and
18031797
n = -1
18041798
or
1799+
this.hasNoCompatibleTargetNoBorrowToIndex(selfPos, derefChain, strippedTypePath, strippedType,
1800+
n - 1) and
18051801
exists(Type t |
1806-
this.hasNoCompatibleTargetNoBorrowToIndexRec(selfPos, derefChain, strippedTypePath,
1807-
strippedType, n, t) and
1802+
t = getNthLookupType(strippedType, n) and
18081803
this.hasNoCompatibleTargetCheck(selfPos, derefChain, TNoBorrowKind(), strippedTypePath, t)
18091804
)
18101805
}
18111806

1812-
pragma[nomagic]
1813-
private predicate hasNoCompatibleTargetNoBorrowToIndexRec(
1814-
FunctionPosition selfPos, DerefChain derefChain, TypePath strippedTypePath, Type strippedType,
1815-
int n, Type t
1816-
) {
1817-
this.hasNoCompatibleTargetNoBorrowToIndex(selfPos, derefChain, strippedTypePath, strippedType,
1818-
n - 1) and
1819-
t = getNthLookupType(strippedType, n)
1820-
}
1821-
18221807
/**
18231808
* Holds if the candidate receiver type represented by `derefChain` does not
18241809
* have a matching call target at `selfPos`.
@@ -1841,32 +1826,30 @@ private module AssocFunctionResolution {
18411826
this.supportsAutoDerefAndBorrow() and
18421827
selfPos.isSelf()
18431828
or
1844-
// needed for the `hasNoCompatibleTarget` check in
1829+
// needed for the `hasNoCompatibleNonBlanketTarget` check in
18451830
// `ArgSatisfiesBlanketLikeConstraintInput::hasBlanketCandidate`
1846-
derefChain.isEmpty()
1831+
exists(ImplItemNode i, FunctionPosition selfPosAdj |
1832+
derefChain.isEmpty() and
1833+
blanketLikeCandidate(this, _, _, selfPosAdj, i, _, _, _) and
1834+
i.isBlanketImplementation() and
1835+
if this.hasReceiver()
1836+
then selfPosAdj = selfPos.getFunctionCallAdjusted()
1837+
else selfPosAdj = selfPos
1838+
)
18471839
) and
18481840
strippedType =
18491841
this.getComplexStrippedSelfType(selfPos, derefChain, TNoBorrowKind(), strippedTypePath) and
18501842
n = -1
18511843
or
1844+
this.hasNoCompatibleNonBlanketTargetNoBorrowToIndex(selfPos, derefChain, strippedTypePath,
1845+
strippedType, n - 1) and
18521846
exists(Type t |
1853-
this.hasNoCompatibleNonBlanketTargetNoBorrowToIndexRec(selfPos, derefChain,
1854-
strippedTypePath, strippedType, n, t) and
1847+
t = getNthLookupType(strippedType, n) and
18551848
this.hasNoCompatibleNonBlanketTargetCheck(selfPos, derefChain, TNoBorrowKind(),
18561849
strippedTypePath, t)
18571850
)
18581851
}
18591852

1860-
pragma[nomagic]
1861-
private predicate hasNoCompatibleNonBlanketTargetNoBorrowToIndexRec(
1862-
FunctionPosition selfPos, DerefChain derefChain, TypePath strippedTypePath, Type strippedType,
1863-
int n, Type t
1864-
) {
1865-
this.hasNoCompatibleNonBlanketTargetNoBorrowToIndex(selfPos, derefChain, strippedTypePath,
1866-
strippedType, n - 1) and
1867-
t = getNthLookupType(strippedType, n)
1868-
}
1869-
18701853
/**
18711854
* Holds if the candidate receiver type represented by `derefChain` does not have
18721855
* a matching non-blanket call target at `selfPos`.
@@ -1893,24 +1876,15 @@ private module AssocFunctionResolution {
18931876
strippedTypePath) and
18941877
n = -1
18951878
or
1879+
this.hasNoCompatibleTargetSharedBorrowToIndex(selfPos, derefChain, strippedTypePath,
1880+
strippedType, n - 1) and
18961881
exists(Type t |
1897-
this.hasNoCompatibleTargetSharedBorrowToIndexRec(selfPos, derefChain, strippedTypePath,
1898-
strippedType, n, t) and
1882+
t = getNthLookupType(strippedType, n) and
18991883
this.hasNoCompatibleNonBlanketLikeTargetCheck(selfPos, derefChain, TSomeBorrowKind(false),
19001884
strippedTypePath, t)
19011885
)
19021886
}
19031887

1904-
pragma[nomagic]
1905-
private predicate hasNoCompatibleTargetSharedBorrowToIndexRec(
1906-
FunctionPosition selfPos, DerefChain derefChain, TypePath strippedTypePath, Type strippedType,
1907-
int n, Type t
1908-
) {
1909-
this.hasNoCompatibleTargetSharedBorrowToIndex(selfPos, derefChain, strippedTypePath,
1910-
strippedType, n - 1) and
1911-
t = getNthLookupType(strippedType, n)
1912-
}
1913-
19141888
/**
19151889
* Holds if the candidate receiver type represented by `derefChain`, followed
19161890
* by a shared borrow, does not have a matching call target at `selfPos`.
@@ -1934,24 +1908,15 @@ private module AssocFunctionResolution {
19341908
this.getComplexStrippedSelfType(selfPos, derefChain, TSomeBorrowKind(true), strippedTypePath) and
19351909
n = -1
19361910
or
1911+
this.hasNoCompatibleTargetMutBorrowToIndex(selfPos, derefChain, strippedTypePath,
1912+
strippedType, n - 1) and
19371913
exists(Type t |
1938-
this.hasNoCompatibleTargetMutBorrowToIndexRec(selfPos, derefChain, strippedTypePath,
1939-
strippedType, n, t) and
1914+
t = getNthLookupType(strippedType, n) and
19401915
this.hasNoCompatibleNonBlanketLikeTargetCheck(selfPos, derefChain, TSomeBorrowKind(true),
19411916
strippedTypePath, t)
19421917
)
19431918
}
19441919

1945-
pragma[nomagic]
1946-
private predicate hasNoCompatibleTargetMutBorrowToIndexRec(
1947-
FunctionPosition selfPos, DerefChain derefChain, TypePath strippedTypePath, Type strippedType,
1948-
int n, Type t
1949-
) {
1950-
this.hasNoCompatibleTargetMutBorrowToIndex(selfPos, derefChain, strippedTypePath,
1951-
strippedType, n - 1) and
1952-
t = getNthLookupType(strippedType, n)
1953-
}
1954-
19551920
/**
19561921
* Holds if the candidate receiver type represented by `derefChain`, followed
19571922
* by a `mut` borrow, does not have a matching call target at `selfPos`.
@@ -1976,24 +1941,15 @@ private module AssocFunctionResolution {
19761941
strippedTypePath) and
19771942
n = -1
19781943
or
1944+
this.hasNoCompatibleNonBlanketTargetSharedBorrowToIndex(selfPos, derefChain, strippedTypePath,
1945+
strippedType, n - 1) and
19791946
exists(Type t |
1980-
this.hasNoCompatibleNonBlanketTargetSharedBorrowToIndexRec(selfPos, derefChain,
1981-
strippedTypePath, strippedType, n, t) and
1947+
t = getNthLookupType(strippedType, n) and
19821948
this.hasNoCompatibleNonBlanketTargetCheck(selfPos, derefChain, TSomeBorrowKind(false),
19831949
strippedTypePath, t)
19841950
)
19851951
}
19861952

1987-
pragma[nomagic]
1988-
private predicate hasNoCompatibleNonBlanketTargetSharedBorrowToIndexRec(
1989-
FunctionPosition selfPos, DerefChain derefChain, TypePath strippedTypePath, Type strippedType,
1990-
int n, Type t
1991-
) {
1992-
this.hasNoCompatibleNonBlanketTargetSharedBorrowToIndex(selfPos, derefChain, strippedTypePath,
1993-
strippedType, n - 1) and
1994-
t = getNthLookupType(strippedType, n)
1995-
}
1996-
19971953
/**
19981954
* Holds if the candidate receiver type represented by `derefChain`, followed
19991955
* by a shared borrow, does not have a matching non-blanket call target at `selfPos`.
@@ -2019,24 +1975,15 @@ private module AssocFunctionResolution {
20191975
this.getComplexStrippedSelfType(selfPos, derefChain, TSomeBorrowKind(true), strippedTypePath) and
20201976
n = -1
20211977
or
1978+
this.hasNoCompatibleNonBlanketTargetMutBorrowToIndex(selfPos, derefChain, strippedTypePath,
1979+
strippedType, n - 1) and
20221980
exists(Type t |
2023-
this.hasNoCompatibleNonBlanketTargetMutBorrowToIndexRec(selfPos, derefChain,
2024-
strippedTypePath, strippedType, n, t) and
1981+
t = getNthLookupType(strippedType, n) and
20251982
this.hasNoCompatibleNonBlanketTargetCheck(selfPos, derefChain, TSomeBorrowKind(true),
20261983
strippedTypePath, t)
20271984
)
20281985
}
20291986

2030-
pragma[nomagic]
2031-
private predicate hasNoCompatibleNonBlanketTargetMutBorrowToIndexRec(
2032-
FunctionPosition selfPos, DerefChain derefChain, TypePath strippedTypePath, Type strippedType,
2033-
int n, Type t
2034-
) {
2035-
this.hasNoCompatibleNonBlanketTargetMutBorrowToIndex(selfPos, derefChain, strippedTypePath,
2036-
strippedType, n - 1) and
2037-
t = getNthLookupType(strippedType, n)
2038-
}
2039-
20401987
/**
20411988
* Holds if the candidate receiver type represented by `derefChain`, followed
20421989
* by a `mut` borrow, does not have a matching non-blanket call target at `selfPos`.
@@ -2486,7 +2433,7 @@ private module AssocFunctionResolution {
24862433
// this is to account for codebases that use the (unstable) specialization feature
24872434
// (https://rust-lang.github.io/rfcs/1210-impl-specialization.html), as well as
24882435
// cases where our blanket implementation filtering is not precise enough.
2489-
(afcc.hasNoCompatibleNonBlanketTarget() or not impl.isBlanketImplementation())
2436+
if impl.isBlanketImplementation() then afcc.hasNoCompatibleNonBlanketTarget() else any()
24902437
|
24912438
borrow.isNoBorrow()
24922439
or

0 commit comments

Comments
 (0)