#E0107: shared value handed over
The value is handed to another owner while other code can still reach it (a lock, a thread-local, a Sync object, or another argument of the same call). Hand over a .clone(), or a value nothing else holds.
nabi
let m = Mutex::new([1, 2, 3]);
let (tx, rx) = channel::<List<i32>>();
using g = m.lock() {
try! tx.send(g.get());
}
error[E0107]: `g.get()` can't be sent through a channel: the `Mutex` behind `g` still holds it --> main.nabi:4:18 | 4 | try! tx.send(g.get()); | ^^^^^^^ | ------- taken out of the lock here | = help: hand over a deep copy (`g.get_clone()`), or take it out of the lock first (`g.set(..)` a new value)
Send a copy:
nabi
let m = Mutex::new([1, 2, 3]);
let (tx, rx) = channel::<List<i32>>();
using g = m.lock() {
try! tx.send(g.get_clone());
}
println(f"{(rx.recv() ?? []).len()}");
3
Related: E0105 value used after it was handed over, E0106 value used after its lock was released
Found a mistake? Edit this page on GitHub. Last updated