diff --git a/rust/ql/lib/codeql/rust/frameworks/stdlib/Stdlib.qll b/rust/ql/lib/codeql/rust/frameworks/stdlib/Stdlib.qll index 00e03053654d..ec0e38f57399 100644 --- a/rust/ql/lib/codeql/rust/frameworks/stdlib/Stdlib.qll +++ b/rust/ql/lib/codeql/rust/frameworks/stdlib/Stdlib.qll @@ -250,6 +250,19 @@ class IndexTrait extends Trait { } } +/** + * The [`IndexMut` trait][1]. + * + * [1]: https://doc.rust-lang.org/std/ops/trait.IndexMut.html + */ +class IndexMutTrait extends Trait { + pragma[nomagic] + IndexMutTrait() { this.getCanonicalPath() = "core::ops::index::IndexMut" } + + /** Gets the `index_mut` function. */ + Function getIndexMutFunction() { result = this.(TraitItemNode).getAssocItem("index_mut") } +} + /** * The [`Box` struct][1]. * diff --git a/rust/ql/lib/codeql/rust/internal/TypeInference.qll b/rust/ql/lib/codeql/rust/internal/TypeInference.qll index 602f964df0f0..488a391150a0 100644 --- a/rust/ql/lib/codeql/rust/internal/TypeInference.qll +++ b/rust/ql/lib/codeql/rust/internal/TypeInference.qll @@ -1786,8 +1786,8 @@ private module MethodResolution { override Trait getTrait() { if this.isInMutableContext() - then result.getCanonicalPath() = "core::ops::index::IndexMut" - else result.getCanonicalPath() = "core::ops::index::Index" + then result instanceof IndexMutTrait + else result instanceof IndexTrait } }