本頁尚未翻譯,以下為英文原文。
#E0065: lock guard not released by using
A lock guard is released only when a using block ends. Bind the guard with using g = m.lock() { .. } instead of let, and do not discard it.
nabi
let m = Mutex::new(0);
let g = m.lock();
error[E0065]: `g` holds a `MutexGuard` that is never released: only `using` releases a lock guard, so bind it with `using g = .. { .. }` --> main.nabi:2:1 | 2 | let g = m.lock(); | ^^^
Bind the guard with using:
nabi
let m = Mutex::new(0);
using g = m.lock() { g.set(g.get() + 1) }
using g = m.lock() { println(f"{g.get()}") }
1
Related: E0066 using on a value without Drop, E0106 value used after its lock was released
Found a mistake? Edit this page on GitHub. Last updated