rust
ownership
ai_generated
true
error[E0382]: borrow of moved value: `x`
ID: rust/e0382-use-after-move
94%Fix Rate
96%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1 | active | — | — | — |
Root Cause
Value has been moved to another owner and cannot be used anymore.
genericWorkarounds
-
92% success Clone the value before moving if you need to use it again
let y = x.clone(); move_fn(x); use(y);
Sources: https://doc.rust-lang.org/book/ch04-01-what-is-ownership.html
-
95% success Use references instead of moves where possible
fn process(x: &MyType) instead of fn process(x: MyType)
Dead Ends
Common approaches that don't work:
-
Using unsafe to read the moved memory
95% fail
Undefined behavior; memory may have been freed or reused
-
Making everything Copy
60% fail
Not all types can be Copy (heap-allocated types like String, Vec)
Error Chain
Preceded by:
Frequently confused with: