Skip to content

Commit 66a235c

Browse files
committed
wip
1 parent 9aad861 commit 66a235c

File tree

5 files changed

+32
-14
lines changed

5 files changed

+32
-14
lines changed

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

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,7 +2654,7 @@ private module NonMethodResolution {
26542654
* to `traitTp` being the special `Self` type parameter).
26552655
*/
26562656
pragma[nomagic]
2657-
private predicate functionResolutionDependsOnArgument(
2657+
private predicate functionResolutionDependsOnArgument0(
26582658
TraitItemNode trait, NonMethodFunction traitFunction, FunctionPosition pos, ImplItemNode impl,
26592659
NonMethodFunction implFunction, TypePath path, TypeParameter traitTp
26602660
) {
@@ -2668,6 +2668,19 @@ private module NonMethodResolution {
26682668
)
26692669
}
26702670

2671+
pragma[nomagic]
2672+
private predicate functionResolutionDependsOnArgument(
2673+
ImplItemNode impl, NonMethodFunction f, FunctionPosition pos, TypeParameter traitTp
2674+
) {
2675+
functionResolutionDependsOnArgument0(_, _, pos, impl, f, _, traitTp)
2676+
or
2677+
f = impl.getASuccessor(_) and
2678+
not impl.(Impl).hasTrait() and
2679+
traitTp = TTypeParamTypeParameter(impl.resolveSelfTy().getTypeParam(0)) and
2680+
pos.isSelf() and
2681+
not f.hasSelfParam()
2682+
}
2683+
26712684
pragma[nomagic]
26722685
private predicate functionInfoBlanketLikeRelevantPos(
26732686
NonMethodFunction f, string name, int arity, ImplItemNode impl, Trait trait,
@@ -2763,7 +2776,7 @@ private module NonMethodResolution {
27632776
result = this.getPathResolutionResolved() and
27642777
result = i.getASuccessor(_) and
27652778
not exists(this.resolveCallTargetViaPathResolution()) and
2766-
functionResolutionDependsOnArgument(_, _, _, i, result, _, _)
2779+
functionResolutionDependsOnArgument(i, result, _, _)
27672780
}
27682781

27692782
pragma[nomagic]
@@ -2811,7 +2824,7 @@ private module NonMethodResolution {
28112824
ItemNode resolveCallTargetViaPathResolution() {
28122825
not this.hasTrait() and
28132826
result = this.getPathResolutionResolved() and
2814-
not functionResolutionDependsOnArgument(_, _, _, _, result, _, _)
2827+
not functionResolutionDependsOnArgument(_, result, _, _)
28152828
}
28162829

28172830
/**
@@ -2917,7 +2930,7 @@ private module NonMethodResolution {
29172930
ArgsAreInstantiationsOfInputSig
29182931
{
29192932
predicate toCheck(ImplOrTraitItemNode i, Function f, TypeParameter traitTp, FunctionPosition pos) {
2920-
functionResolutionDependsOnArgument(_, _, pos, i, f, _, traitTp)
2933+
functionResolutionDependsOnArgument(i, f, pos, traitTp)
29212934
}
29222935

29232936
final class Call extends NonMethodCall {
@@ -2938,7 +2951,7 @@ private module NonMethodResolution {
29382951
ArgsAreInstantiationsOfInputSig
29392952
{
29402953
predicate toCheck(ImplOrTraitItemNode i, Function f, TypeParameter traitTp, FunctionPosition pos) {
2941-
functionResolutionDependsOnArgument(_, _, pos, i, f, _, traitTp)
2954+
functionResolutionDependsOnArgument(i, f, pos, traitTp)
29422955
or
29432956
// Also match against the trait function itself
29442957
FunctionOverloading::traitTypeParameterOccurrence(i, f, _, pos, _, traitTp) and
@@ -2950,12 +2963,19 @@ private module NonMethodResolution {
29502963
result = getArgType(this, pos, path, _)
29512964
}
29522965

2966+
// private predicate testhasTargetCand(
2967+
// ImplOrTraitItemNode i, Function f, TypeParameter traitTp, FunctionPosition pos
2968+
// ) {
2969+
// this = Debug::getRelevantLocatable() and
2970+
// this.hasTargetCand(i, f) and
2971+
// toCheck(i, f, traitTp, pos)
2972+
// }
29532973
predicate hasTargetCand(ImplOrTraitItemNode i, Function f) {
29542974
f = this.resolveCallTargetNonBlanketCand(i)
29552975
or
29562976
exists(TraitItemNode trait, NonMethodFunction resolved, ImplItemNode i1, Function f1 |
29572977
this.hasTraitResolved(trait, resolved) and
2958-
functionResolutionDependsOnArgument(trait, resolved, _, i1, f1, _, _) and
2978+
functionResolutionDependsOnArgument0(trait, resolved, _, i1, f1, _, _) and
29592979
not BlanketImplementation::isBlanketLike(i, _, _)
29602980
|
29612981
f = resolved and
@@ -2965,10 +2985,10 @@ private module NonMethodResolution {
29652985
i = i1 and
29662986
// Exclude functions where we cannot resolve all relevant type mentions
29672987
forall(TypeParameter traitTp |
2968-
functionResolutionDependsOnArgument(trait, resolved, _, i1, f1, _, traitTp)
2988+
functionResolutionDependsOnArgument0(trait, resolved, _, i1, f1, _, traitTp)
29692989
|
29702990
exists(FunctionPosition pos, TypePath path |
2971-
functionResolutionDependsOnArgument(trait, resolved, pos, i1, f1, path, traitTp) and
2991+
functionResolutionDependsOnArgument0(trait, resolved, pos, i1, f1, path, traitTp) and
29722992
exists(getAssocFunctionTypeAt(f, i, pos, path))
29732993
)
29742994
)

rust/ql/test/library-tests/path-resolution/CONSISTENCY/PathResolutionConsistency.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,3 @@ multipleResolvedTargets
44
| main.rs:369:9:371:16 | ...::f(...) |
55
| main.rs:450:9:454:16 | ...::f(...) |
66
| main.rs:455:9:459:16 | ...::f(...) |
7-
| main.rs:568:9:569:12 | ...::f1(...) |
8-
| main.rs:571:9:572:12 | ...::f1(...) |

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,10 @@ mod m16 {
566566
Assoc(); // $ item=S3i32AssocFunc
567567

568568
S3::<bool>:: // $ item=bool
569-
f1(); // $ item=S3boolf1 $ SPURIOUS: item=S3i32f1
569+
f1(); // $ item=S3boolf1
570570

571571
S3::<i32>:: // $ item=i32
572-
f1(); // $ item=S3i32f1 $ SPURIOUS: item=S3boolf1
572+
f1(); // $ item=S3i32f1
573573
}
574574
}
575575

rust/ql/test/library-tests/path-resolution/path-resolution.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,10 @@ resolvePath
324324
| main.rs:565:9:566:13 | ...::Assoc | main.rs:532:9:535:9 | fn Assoc |
325325
| main.rs:565:14:565:16 | i32 | {EXTERNAL LOCATION} | struct i32 |
326326
| main.rs:568:9:568:18 | S3::<...> | main.rs:525:5:525:22 | struct S3 |
327-
| main.rs:568:9:569:10 | ...::f1 | main.rs:550:20:553:9 | fn f1 |
328327
| main.rs:568:9:569:10 | ...::f1 | main.rs:557:21:560:9 | fn f1 |
329328
| main.rs:568:14:568:17 | bool | {EXTERNAL LOCATION} | struct bool |
330329
| main.rs:571:9:571:17 | S3::<...> | main.rs:525:5:525:22 | struct S3 |
331330
| main.rs:571:9:572:10 | ...::f1 | main.rs:550:20:553:9 | fn f1 |
332-
| main.rs:571:9:572:10 | ...::f1 | main.rs:557:21:560:9 | fn f1 |
333331
| main.rs:571:14:571:16 | i32 | {EXTERNAL LOCATION} | struct i32 |
334332
| main.rs:588:14:588:16 | Foo | main.rs:578:9:580:9 | trait Foo |
335333
| main.rs:588:22:588:22 | X | main.rs:586:9:586:21 | struct X |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
multipleResolvedTargets
2+
| test_cipher.rs:114:23:114:50 | ...::new(...) |

0 commit comments

Comments
 (0)