Skip to content

Commit 5c604fc

Browse files
committed
Rust: Fix bad join
Before ``` Evaluated relational algebra for predicate TypeInference::MethodResolution::MethodCall.getTrait/0#dispred#fc13ba6e@914858bt with tuple counts: 153112 ~2% {2} r1 = SCAN `Operation::Operation.isOverloaded/3#f0e64084` OUTPUT In.0, In.1 153112 ~2% {2} | STREAM DEDUP 18807 ~0% {2} r2 = JOIN `TypeInference::getCallExprTraitQualifier/1#c084fe9f` WITH TypeInference::MethodResolution::MethodCallCallExpr#6eae461f ON FIRST 1 OUTPUT Lhs.0, Lhs.1 65859035 ~3% {3} r3 = JOIN `_IndexExpr::Generated::IndexExpr#9975e37a_TypeInference::MethodResolution::MethodCallIndexExpr.isInM__#shared` WITH Trait::Generated::Trait#ecf50173 CARTESIAN PRODUCT OUTPUT Rhs.0, _, Lhs.0 65859035 ~0% {3} | REWRITE WITH Out.1 := "core::ops::index::Index" 11191 ~0% {2} | JOIN WITH `Addressable::Addressable.getCanonicalPath/0#dispred#6044348f#bb` ON FIRST 2 OUTPUT Lhs.2, Lhs.0 671 ~0% {1} r4 = JOIN IndexExpr::Generated::IndexExpr#9975e37a WITH `TypeInference::MethodResolution::MethodCallIndexExpr.isInMutableContext/0#dispred#8c8ad425` ON FIRST 1 OUTPUT Lhs.0 3948835 ~2% {3} | JOIN WITH Trait::Generated::Trait#ecf50173 CARTESIAN PRODUCT OUTPUT Rhs.0, _, Lhs.0 3948835 ~2% {3} | REWRITE WITH Out.1 := "core::ops::index::IndexMut" 671 ~1% {2} | JOIN WITH `Addressable::Addressable.getCanonicalPath/0#dispred#6044348f#bb` ON FIRST 2 OUTPUT Lhs.2, Lhs.0 183781 ~0% {2} r5 = r1 UNION r2 UNION r3 UNION r4 return r5 ``` After ``` Evaluated relational algebra for predicate TypeInference::MethodResolution::MethodCall.getTrait/0#dispred#fc13ba6e@1b4a55e3 with tuple counts: 153112 ~2% {2} r1 = SCAN `Operation::Operation.isOverloaded/3#f0e64084` OUTPUT In.0, In.1 153112 ~2% {2} | STREAM DEDUP 11191 ~0% {2} r2 = JOIN `_IndexExpr::Generated::IndexExpr#9975e37a_TypeInference::MethodResolution::MethodCallIndexExpr.isInM__#shared` WITH Stdlib::IndexTrait#e80543a5 CARTESIAN PRODUCT OUTPUT Lhs.0, Rhs.0 18807 ~0% {2} r3 = JOIN `TypeInference::getCallExprTraitQualifier/1#c084fe9f` WITH TypeInference::MethodResolution::MethodCallCallExpr#6eae461f ON FIRST 1 OUTPUT Lhs.0, Lhs.1 671 ~0% {1} r4 = JOIN IndexExpr::Generated::IndexExpr#9975e37a WITH `TypeInference::MethodResolution::MethodCallIndexExpr.isInMutableContext/0#dispred#8c8ad425` ON FIRST 1 OUTPUT Lhs.0 671 ~1% {2} | JOIN WITH Stdlib::IndexMutTrait#4d6c31bd CARTESIAN PRODUCT OUTPUT Lhs.0, Rhs.0 183781 ~0% {2} r5 = r1 UNION r2 UNION r3 UNION r4 return r5 ```
1 parent 802c465 commit 5c604fc

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

rust/ql/lib/codeql/rust/frameworks/stdlib/Stdlib.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,19 @@ class IndexTrait extends Trait {
250250
}
251251
}
252252

253+
/**
254+
* The [`IndexMut` trait][1].
255+
*
256+
* [1]: https://doc.rust-lang.org/std/ops/trait.IndexMut.html
257+
*/
258+
class IndexMutTrait extends Trait {
259+
pragma[nomagic]
260+
IndexMutTrait() { this.getCanonicalPath() = "core::ops::index::IndexMut" }
261+
262+
/** Gets the `index_mut` function. */
263+
Function getIndexMutFunction() { result = this.(TraitItemNode).getAssocItem("index_mut") }
264+
}
265+
253266
/**
254267
* The [`Box` struct][1].
255268
*

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,8 +1786,8 @@ private module MethodResolution {
17861786

17871787
override Trait getTrait() {
17881788
if this.isInMutableContext()
1789-
then result.getCanonicalPath() = "core::ops::index::IndexMut"
1790-
else result.getCanonicalPath() = "core::ops::index::Index"
1789+
then result instanceof IndexMutTrait
1790+
else result instanceof IndexTrait
17911791
}
17921792
}
17931793

0 commit comments

Comments
 (0)