Skip to content

Commit 56574a1

Browse files
committed
Rust: SSA: restrict mutablyBorrowed to variables with a 'mut' modifier
1 parent 45db4ae commit 56574a1

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

rust/ql/lib/codeql/rust/dataflow/internal/SsaImpl.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ predicate capturedCallWrite(Expr call, BasicBlock bb, int i, Variable v) {
212212
/** Holds if `v` may be mutably borrowed in `e`. */
213213
private predicate mutablyBorrows(Expr e, Variable v) {
214214
e = any(MethodCallExpr mc).getReceiver() and
215-
e.(VariableAccess).getVariable() = v
215+
e.(VariableAccess).getVariable() = v and
216+
v.isMutable()
216217
or
217218
exists(RefExpr re | re = e and re.isMut() and re.getExpr().(VariableAccess).getVariable() = v)
218219
}

rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ module Impl {
161161
}
162162

163163
/** Hold is this variable is mutable. */
164-
predicate isMutable() { this.getPat().isMut() }
164+
predicate isMutable() { this.getPat().isMut() or this.getSelfParam().isMut() }
165165

166166
/** Hold is this variable is immutable. */
167167
predicate isImmutable() { not this.isMutable() }

0 commit comments

Comments
 (0)