Skip to content

Commit 756bfef

Browse files
committed
wip2
1 parent d208a61 commit 756bfef

1 file changed

Lines changed: 66 additions & 95 deletions

File tree

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

Lines changed: 66 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,6 @@ private module AssocFunctionResolution {
15371537
AssocFunctionCall afc, FunctionPosition selfPos, ImplOrTraitItemNode i,
15381538
AssocFunctionType selfType, TypePath strippedTypePath, Type strippedType
15391539
) {
1540-
not i.toString().matches("%RangeChecker%") and
15411540
exists(
15421541
string name, int arity, TypeOption typeQualifier, TypeOption traitQualifier,
15431542
boolean hasReceiver, boolean hasNoTrait, boolean isImplTrait
@@ -1803,6 +1802,13 @@ private module AssocFunctionResolution {
18031802
result != TUnknownType()
18041803
}
18051804

1805+
private Type testgetComplexStrippedSelfType(
1806+
FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow, TypePath strippedTypePath
1807+
) {
1808+
result = this.getComplexStrippedSelfType(selfPos, derefChain, borrow, strippedTypePath) and
1809+
this = Debug::getRelevantLocatable()
1810+
}
1811+
18061812
pragma[nomagic]
18071813
Type getComplexStrippedSelfType(
18081814
FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow, TypePath strippedTypePath
@@ -1833,8 +1839,8 @@ private module AssocFunctionResolution {
18331839
FunctionPosition selfPos, DerefChain derefChain, TypePath strippedTypePath, Type strippedType,
18341840
int n
18351841
) {
1836-
hasNoCompatibleTargetNoBorrowToIndex(this, selfPos, derefChain, _, strippedTypePath,
1837-
strippedType, n)
1842+
Foo<hasNoCompatibleTargetNoBorrowToIndex/4>::hasNoCompatibleTargetCheck(this, selfPos,
1843+
derefChain, _, strippedTypePath, strippedType, n)
18381844
}
18391845

18401846
/**
@@ -1855,8 +1861,8 @@ private module AssocFunctionResolution {
18551861
FunctionPosition selfPos, DerefChain derefChain, TypePath strippedTypePath, Type strippedType,
18561862
int n
18571863
) {
1858-
hasNoCompatibleNonBlanketTargetNoBorrowToIndex(this, selfPos, derefChain, _, strippedTypePath,
1859-
strippedType, n)
1864+
Foo<hasNoCompatibleNonBlanketTargetNoBorrowToIndex/4>::hasNoCompatibleNonBlanketTargetCheck(this,
1865+
selfPos, derefChain, _, strippedTypePath, strippedType, n)
18601866
}
18611867

18621868
/**
@@ -1879,8 +1885,10 @@ private module AssocFunctionResolution {
18791885
FunctionPosition selfPos, DerefChain derefChain, TypePath strippedTypePath, Type strippedType,
18801886
int n
18811887
) {
1882-
hasNoCompatibleTargetSharedBorrowToIndex(this, selfPos, derefChain, _, strippedTypePath,
1883-
strippedType, n)
1888+
// hasNoCompatibleTargetSharedBorrowToIndex(this, selfPos, derefChain, _, strippedTypePath,
1889+
// strippedType, n)
1890+
Foo<hasNoCompatibleTargetSharedBorrowToIndex/4>::hasNoCompatibleNonBlanketLikeTargetCheck(this,
1891+
selfPos, derefChain, _, strippedTypePath, strippedType, n)
18841892
}
18851893

18861894
/**
@@ -1902,8 +1910,8 @@ private module AssocFunctionResolution {
19021910
FunctionPosition selfPos, DerefChain derefChain, TypePath strippedTypePath, Type strippedType,
19031911
int n
19041912
) {
1905-
hasNoCompatibleTargetMutBorrowToIndex(this, selfPos, derefChain, _, strippedTypePath,
1906-
strippedType, n)
1913+
Foo<hasNoCompatibleTargetMutBorrowToIndex/4>::hasNoCompatibleNonBlanketLikeTargetCheck(this,
1914+
selfPos, derefChain, _, strippedTypePath, strippedType, n)
19071915
}
19081916

19091917
/**
@@ -1925,21 +1933,8 @@ private module AssocFunctionResolution {
19251933
FunctionPosition selfPos, DerefChain derefChain, TypePath strippedTypePath, Type strippedType,
19261934
int n
19271935
) {
1928-
hasNoCompatibleNonBlanketTargetSharedBorrowToIndex(this, selfPos, derefChain, _,
1929-
strippedTypePath, strippedType, n)
1930-
// this.hasNoCompatibleTargetNoBorrow(selfPos, derefChain) and
1931-
// strippedType =
1932-
// this.getComplexStrippedSelfType(selfPos, derefChain, TSomeBorrowKind(false),
1933-
// strippedTypePath) and
1934-
// n = -1
1935-
// or
1936-
// this.hasNoCompatibleNonBlanketTargetSharedBorrowToIndex(selfPos, derefChain, strippedTypePath,
1937-
// strippedType, n - 1) and
1938-
// exists(Type t |
1939-
// t = getNthLookupType(this, strippedType, n) and
1940-
// this.hasNoCompatibleNonBlanketTargetCheck(selfPos, derefChain, TSomeBorrowKind(false),
1941-
// strippedTypePath, t)
1942-
// )
1936+
Foo<hasNoCompatibleNonBlanketTargetSharedBorrowToIndex/4>::hasNoCompatibleNonBlanketTargetCheck(this,
1937+
selfPos, derefChain, _, strippedTypePath, strippedType, n)
19431938
}
19441939

19451940
/**
@@ -1963,20 +1958,8 @@ private module AssocFunctionResolution {
19631958
FunctionPosition selfPos, DerefChain derefChain, TypePath strippedTypePath, Type strippedType,
19641959
int n
19651960
) {
1966-
hasNoCompatibleNonBlanketTargetMutBorrowToIndex(this, selfPos, derefChain, _,
1967-
strippedTypePath, strippedType, n)
1968-
// this.hasNoCompatibleNonBlanketTargetSharedBorrow(selfPos, derefChain) and
1969-
// strippedType =
1970-
// this.getComplexStrippedSelfType(selfPos, derefChain, TSomeBorrowKind(true), strippedTypePath) and
1971-
// n = -1
1972-
// or
1973-
// this.hasNoCompatibleNonBlanketTargetMutBorrowToIndex(selfPos, derefChain, strippedTypePath,
1974-
// strippedType, n - 1) and
1975-
// exists(Type t |
1976-
// t = getNthLookupType(this, strippedType, n) and
1977-
// this.hasNoCompatibleNonBlanketTargetCheck(selfPos, derefChain, TSomeBorrowKind(true),
1978-
// strippedTypePath, t)
1979-
// )
1961+
Foo<hasNoCompatibleNonBlanketTargetMutBorrowToIndex/4>::hasNoCompatibleNonBlanketTargetCheck(this,
1962+
selfPos, derefChain, _, strippedTypePath, strippedType, n)
19801963
}
19811964

19821965
/**
@@ -2092,14 +2075,14 @@ private module AssocFunctionResolution {
20922075
}
20932076
}
20942077

2095-
pragma[nomagic]
2078+
bindingset[derefChain]
20962079
private predicate hasNoCompatibleNonBlanketTargetNoBorrowToIndex(
2097-
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow,
2098-
TypePath strippedTypePath, Type strippedType, int n
2080+
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow
20992081
) {
21002082
(
21012083
afc.supportsAutoDerefAndBorrow() and
2102-
afc.hasReceiverAtPos(selfPos)
2084+
afc.hasReceiverAtPos(selfPos) and
2085+
exists(derefChain)
21032086
or
21042087
// needed for the `hasNoCompatibleNonBlanketTarget` check in
21052088
// `ArgSatisfiesBlanketLikeConstraintInput::hasBlanketCandidate`
@@ -2109,98 +2092,86 @@ private module AssocFunctionResolution {
21092092
i.isBlanketImplementation()
21102093
)
21112094
) and
2112-
borrow = TNoBorrowKind() and
2113-
strippedType = afc.getComplexStrippedSelfType(selfPos, derefChain, borrow, strippedTypePath) and
2114-
n = -1
2115-
or
2116-
Foo<hasNoCompatibleNonBlanketTargetNoBorrowToIndex/7>::hasNoCompatibleNonBlanketTargetCheck(afc,
2117-
selfPos, derefChain, borrow, strippedTypePath, strippedType, n)
2095+
borrow = TNoBorrowKind()
21182096
}
21192097

21202098
pragma[nomagic]
21212099
private predicate hasNoCompatibleNonBlanketTargetSharedBorrowToIndex(
2122-
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow,
2123-
TypePath strippedTypePath, Type strippedType, int n
2100+
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow
21242101
) {
21252102
afc.hasNoCompatibleTargetNoBorrow(selfPos, derefChain) and
2126-
borrow = TSomeBorrowKind(false) and
2127-
strippedType = afc.getComplexStrippedSelfType(selfPos, derefChain, borrow, strippedTypePath) and
2128-
n = -1
2129-
or
2130-
Foo<hasNoCompatibleNonBlanketTargetSharedBorrowToIndex/7>::hasNoCompatibleNonBlanketTargetCheck(afc,
2131-
selfPos, derefChain, borrow, strippedTypePath, strippedType, n)
2103+
borrow = TSomeBorrowKind(false)
21322104
}
21332105

21342106
pragma[nomagic]
21352107
private predicate hasNoCompatibleNonBlanketTargetMutBorrowToIndex(
2136-
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow,
2137-
TypePath strippedTypePath, Type strippedType, int n
2108+
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow
21382109
) {
21392110
afc.hasNoCompatibleNonBlanketTargetSharedBorrow(selfPos, derefChain) and
2140-
borrow = TSomeBorrowKind(true) and
2141-
strippedType = afc.getComplexStrippedSelfType(selfPos, derefChain, borrow, strippedTypePath) and
2142-
n = -1
2143-
or
2144-
Foo<hasNoCompatibleNonBlanketTargetMutBorrowToIndex/7>::hasNoCompatibleNonBlanketTargetCheck(afc,
2145-
selfPos, derefChain, borrow, strippedTypePath, strippedType, n)
2111+
borrow = TSomeBorrowKind(true)
21462112
}
21472113

2148-
pragma[nomagic]
2114+
bindingset[derefChain]
21492115
private predicate hasNoCompatibleTargetNoBorrowToIndex(
2150-
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow,
2151-
TypePath strippedTypePath, Type strippedType, int n
2116+
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow
21522117
) {
21532118
afc.supportsAutoDerefAndBorrow() and
21542119
afc.hasReceiverAtPos(selfPos) and
2155-
borrow = TNoBorrowKind() and
2156-
strippedType = afc.getComplexStrippedSelfType(selfPos, derefChain, borrow, strippedTypePath) and
2157-
n = -1
2158-
or
2159-
Foo<hasNoCompatibleTargetNoBorrowToIndex/7>::hasNoCompatibleTargetCheck(afc, selfPos,
2160-
derefChain, borrow, strippedTypePath, strippedType, n)
2120+
exists(derefChain) and
2121+
borrow = TNoBorrowKind()
21612122
}
21622123

21632124
pragma[nomagic]
21642125
private predicate hasNoCompatibleTargetSharedBorrowToIndex(
2165-
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow,
2166-
TypePath strippedTypePath, Type strippedType, int n
2126+
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow
21672127
) {
21682128
afc.hasNoCompatibleTargetNoBorrow(selfPos, derefChain) and
2169-
borrow = TSomeBorrowKind(false) and
2170-
strippedType = afc.getComplexStrippedSelfType(selfPos, derefChain, borrow, strippedTypePath) and
2171-
n = -1
2172-
or
2173-
Foo<hasNoCompatibleTargetSharedBorrowToIndex/7>::hasNoCompatibleNonBlanketLikeTargetCheck(afc,
2174-
selfPos, derefChain, borrow, strippedTypePath, strippedType, n)
2129+
borrow = TSomeBorrowKind(false)
21752130
}
21762131

21772132
pragma[nomagic]
21782133
private predicate hasNoCompatibleTargetMutBorrowToIndex(
2179-
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow,
2180-
TypePath strippedTypePath, Type strippedType, int n
2134+
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow
21812135
) {
21822136
afc.hasNoCompatibleTargetSharedBorrow(selfPos, derefChain) and
2183-
borrow = TSomeBorrowKind(true) and
2184-
strippedType = afc.getComplexStrippedSelfType(selfPos, derefChain, borrow, strippedTypePath) and
2185-
n = -1
2186-
or
2187-
Foo<hasNoCompatibleTargetMutBorrowToIndex/7>::hasNoCompatibleNonBlanketLikeTargetCheck(afc,
2188-
selfPos, derefChain, borrow, strippedTypePath, strippedType, n)
2137+
borrow = TSomeBorrowKind(true)
21892138
}
21902139

2140+
bindingset[derefChain]
21912141
private signature predicate fooSig(
2192-
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow,
2193-
TypePath strippedTypePath, Type strippedType, int n
2142+
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow
21942143
);
21952144

2196-
private module Foo<fooSig/7 foo> {
2145+
private module Foo<fooSig/4 foo> {
2146+
pragma[nomagic]
2147+
private predicate foo(
2148+
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow,
2149+
TypePath strippedTypePath, Type strippedType, int n
2150+
) {
2151+
foo(afc, selfPos, derefChain, borrow) and
2152+
strippedType = afc.getComplexStrippedSelfType(selfPos, derefChain, borrow, strippedTypePath) and
2153+
n = -1
2154+
}
2155+
2156+
pragma[nomagic]
2157+
private predicate bar(
2158+
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow,
2159+
TypePath strippedTypePath, Type strippedType, int n, Type t
2160+
) {
2161+
(
2162+
foo(afc, selfPos, derefChain, borrow, strippedTypePath, strippedType, n - 1) or
2163+
hasNoCompatibleNonBlanketLikeTargetCheck(afc, selfPos, derefChain, borrow, strippedTypePath,
2164+
strippedType, n - 1)
2165+
) and
2166+
t = getNthLookupType(afc, strippedType, n)
2167+
}
2168+
21972169
predicate hasNoCompatibleNonBlanketLikeTargetCheck(
21982170
AssocFunctionCall afc, FunctionPosition selfPos, DerefChain derefChain, BorrowKind borrow,
21992171
TypePath strippedTypePath, Type strippedType, int n
22002172
) {
2201-
foo(afc, selfPos, derefChain, borrow, strippedTypePath, strippedType, n - 1) and
22022173
exists(Type t |
2203-
t = getNthLookupType(afc, strippedType, n) and
2174+
bar(afc, selfPos, derefChain, borrow, strippedTypePath, strippedType, n, t) and
22042175
forall(ImplOrTraitItemNode i |
22052176
nonBlanketLikeCandidate(afc, selfPos, i, _, strippedTypePath, t)
22062177
|
@@ -4111,7 +4082,7 @@ private module Debug {
41114082
exists(string filepath, int startline, int startcolumn, int endline, int endcolumn |
41124083
result.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) and
41134084
filepath.matches("%/main.rs") and
4114-
startline = 103
4085+
startline = 1986
41154086
)
41164087
}
41174088

0 commit comments

Comments
 (0)