Skip to content

Commit 15eda88

Browse files
committed
Rust: Canonical paths for blanket implementations
1 parent da815b7 commit 15eda88

3 files changed

Lines changed: 102 additions & 75 deletions

File tree

rust/ql/lib/codeql/rust/internal/PathResolution.qll

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,12 @@ final class ImplItemNode extends ImplOrTraitItemNode instanceof Impl {
874874
*/
875875
predicate isBlanketImplementation() { exists(this.getBlanketImplementationTypeParam()) }
876876

877-
override predicate hasCanonicalPath(Crate c) { this.resolveSelfTy().hasCanonicalPathPrefix(c) }
877+
override predicate hasCanonicalPath(Crate c) {
878+
this.resolveSelfTy().hasCanonicalPathPrefix(c)
879+
or
880+
this.isBlanketImplementation() and
881+
c.getASourceFile().getFile() = this.getFile()
882+
}
878883

879884
/**
880885
* Holds if `(c1, c2)` forms a pair of crates for the type and trait
@@ -920,7 +925,12 @@ final class ImplItemNode extends ImplOrTraitItemNode instanceof Impl {
920925
result = "<"
921926
or
922927
i = 1 and
923-
result = this.getSelfCanonicalPath(c)
928+
(
929+
result = this.getSelfCanonicalPath(c)
930+
or
931+
this.isBlanketImplementation() and
932+
result = "_"
933+
)
924934
or
925935
if exists(this.getTraitPath())
926936
then

rust/ql/test/library-tests/dataflow/models/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ fn test_trait_model<T: Ord>(x: T) {
504504
sink(x8); // $ hasValueFlow=29
505505

506506
let x9 = <()>::flow_through3(source(30));
507-
sink(x9); // $ MISSING: hasValueFlow=30
507+
sink(x9); // $ hasValueFlow=30
508508
}
509509

510510
mod external_file;

0 commit comments

Comments
 (0)