Rust

Fix Rust E0382 "borrow of moved value" — Borrow Instead of Moving, Return the Value, or Clone on Purpose

The value left, and the original name stayed behind empty. This guide separates the ways a value leaves — a call, an assignment, a loop, a closure, a single field — and matches each one to its repair: lend the value instead of giving it away, take the value back as a return, lift a field out with a replacement left behind, and copy or share ownership only when that is the design you actually want.

Written November 22, 2026 · Tested with Rust 1.99.0 · 39 min read

By the end of this guide
  • The rule underneath: a move transfers the one ownership, a borrow does not
  • The first failure: a String moved into a function, then used
  • The second failure: the loop that consumes its collection
  • The third failure: the value moved into a closure

Written November 22, 2026

Tested with Rust 1.99.0

What this guide is

Error E0382 has one sentence at its center: a variable was used after its contents have been moved elsewhere. That is the wording of the error codes index, and every part of it carries diagnostic weight. The contents moved — ownership passed to a function, to another binding, into a loop, or into a closure. The variable stayed — the name is still in scope and still looks usable. And the use came afterward — a later read, method call, or print reached for a binding that no longer owns anything, and the compiler refused at that later line, not at the line where the value left.

That ordering is the whole repair. E0382 is never really about the line the diagnostic underlines as the borrow; it is about the earlier line where the value moved, and whether that move needed to happen at all. Most moves that end in E0382 were accidental: a function took its parameter by value when it only needed to look, a loop consumed a collection the code still needed, a closure captured a string by moving it. In each case the fix is decided at the move site: lend the value instead of giving it away, take it back as a return, replace what was lifted out of a structure, or — only when two owners are genuinely the design — copy it or share it under a reference count.

This guide works through the error in the order that separates its causes: the rule underneath, the canonical function-call failure, the loop and closure forms, and the partial-move form — this error's diagnostic core, where moving one field out of a struct leaves the other fields usable and the moved field and the whole value unusable, along a boundary that is exact and worth learning precisely. Then the fixes, in reach order, the two traps, a decision table, and a checklist.

Build every program in this guide with rustc --edition 2021. In the compiler transcripts below, the full file path in the location line is shortened to the file name; every other character is exactly as the compiler printed it.

The rule underneath: a move transfers the one ownership, a borrow does not

Rust's ownership system gives every value exactly one owner at a time. When code assigns a value to a new binding, passes it to a function by value, returns it, or captures it in a move closure, ownership transfers: the value now belongs to the destination, and the source binding is left invalid. This transfer is called a move. The error codes index states the consequence directly: outside of workarounds like Rc, a value cannot be owned by more than one variable. A move is not a copy that leaves the original intact; it is a handover that empties the original name.

The smallest demonstration needs no function at all. Assigning one binding to another moves the value, and the first name is dead from that line onward:

Rust
fn main() {
    let s1 = String::from("hello");
    let s2 = s1;
    println!("s1 = {s1}, s2 = {s2}");
}
Terminal
$ rustc --edition 2021 fail_assign.rs -o fail_assign
error[E0382]: borrow of moved value: `s1`
 --> fail_assign.rs:4:21
  |
2 |     let s1 = String::from("hello");
  |         -- move occurs because `s1` has type `String`, which does not implement the `Copy` trait
3 |     let s2 = s1;
  |              -- value moved here
4 |     println!("s1 = {s1}, s2 = {s2}");
  |                     ^^ value borrowed here after move
  |
help: consider cloning the value if the performance cost is acceptable
  |
3 |     let s2 = s1.clone();
  |                ++++++++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0382`.

Read the three positions the diagnostic names, because they recur in every form of this error. The first note gives the reason: the type does not implement the Copy trait, so assignment moves instead of copying. The second marks where the value moved. The third marks where the emptied binding was used — the compiler calls that use a borrow, which is why the error is titled borrow of moved value even when the later code never writes an explicit reference: printing, reading a field, calling a method that takes &self, and passing the binding as a borrowed argument are all borrows, and all of them need a live value behind the name.

Why does the language work this way? A String owns a heap buffer. If assignment copied the binding while both names believed they owned that buffer, the end of the scope would drop the same allocation twice. The move rule makes the transfer explicit: after let s2 = s1;, exactly one name, s2, is responsible for the buffer, and the compiler enforces that accounting by refusing every later use of s1. The Book's ownership chapter presents the same example and names the outcome a move. The refusal is the double-free, prevented at compile time and reported at the exact line that would have caused it.

The exemption: Copy types are copied, not moved

Some types never produce this error, and the diagnostic's first note tells you why: they implement Copy. The standard library documentation defines Copy as the trait for types whose values can be duplicated simply by copying bits. For a Copy type, assignment and passing by value copy the bits and leave the source fully usable; there is no ownership to transfer because there is nothing behind the value that needs a single responsible owner — no heap allocation, no file handle, no destructor with work to do. The integers, floating-point numbers, bool, char, tuples whose elements are all Copy, and arrays whose element type is Copy all behave this way:

Rust
fn main() {
    let x = 5;
    let y = x;
    println!("x = {x}, y = {y}");
    let a = [1, 2, 3];
    let b = a;
    println!("a = {a:?}, b = {b:?}");
}
Terminal
$ rustc --edition 2021 ok_copy.rs -o ok_copy
$ ./ok_copy
x = 5, y = 5
a = [1, 2, 3], b = [1, 2, 3]

Both bindings print, for both values. Nothing moved, because for these types copying the bits is a complete duplication: y is not a second owner of something x owns; it is an independent value that happens to hold the same bits. The Copy documentation draws the contrast with Clone carefully. Copies happen implicitly, as part of an assignment or a call, and a copy is an inexpensive bitwise duplication whose behavior cannot be customized. Clones are always explicit — code must call .clone() — and a clone may run arbitrary code and may be expensive. Copy is also a subtrait of Clone: every Copy type is Clone, with the requirement that cloning a Copy value is equivalent to copying it. A type of your own can be Copy only when every one of its fields is Copy, a condition the fixes section demonstrates and the traps section violates on purpose, so the compiler can show what it says.

One refinement matters for reading real code. Shared references themselves are Copy: passing a &T copies the reference; it neither moves the value behind it nor consumes the reference. Mutable references are not Copy — assigning a &mut T to a new binding moves it, because two live copies of the one exclusive borrow would break its exclusivity (a function call may instead implicitly reborrow it, leaving the original usable after the call).

A borrow is not a move

A reference lets code use a value without taking ownership of it. The Book's borrowing chapter introduces the reference precisely as the answer to this error's canonical shape: a function that takes a String by value consumes it, so the caller loses it; a function that takes &String borrows it, and the caller's binding stays valid after the call. Writing &s creates a reference that refers to the value of s but does not own it, so the value is not dropped when the reference stops being used, and the owning binding is untouched.

Keep the three operations separate and most E0382 diagnostics read themselves. A move transfers ownership and empties the source. A copy duplicates the bits and leaves both sides valid, only for Copy types. A borrow lends access and changes no ownership at all. When the compiler reports a borrow of a moved value, the code needed the third operation, or the second, and performed the first.

One more behavior is worth knowing before the failures: a moved-out binding declared mut can be given a fresh value, and is valid again from that assignment onward — the move emptied the name; it did not retire it. This is rarely the fix for a real E0382, since code that needs the original value is not helped by a different one, but it explains an error that disappears when a line is added. When a fix seems to work by accident, check whether it refilled the binding or actually prevented the move; only the second is a repair.

The first failure: a String moved into a function, then used

The canonical form of E0382 passes a value to a function that takes it by value, then uses the caller's binding afterward. Nothing in the function is wrong; nothing in the later use is wrong. The composition is wrong, because the call transferred ownership that the later line still expected to have:

Rust
fn consume(s: String) -> usize { s.len() }
fn main() {
    let s = String::from("hello");
    let n = consume(s);
    println!("n = {n}, s = {s}");
}
Terminal
$ rustc --edition 2021 fail_canonical.rs -o fail_canonical
error[E0382]: borrow of moved value: `s`
 --> fail_canonical.rs:5:29
  |
3 |     let s = String::from("hello");
  |         - move occurs because `s` has type `String`, which does not implement the `Copy` trait
4 |     let n = consume(s);
  |                     - value moved here
5 |     println!("n = {n}, s = {s}");
  |                             ^ value borrowed here after move
  |
note: consider changing this parameter type in function `consume` to borrow instead if owning the value isn't necessary
 --> fail_canonical.rs:1:15
  |
1 | fn consume(s: String) -> usize { s.len() }
  |    -------    ^^^^^^ this parameter takes ownership of the value
  |    |
  |    in this function
help: consider cloning the value if the performance cost is acceptable
  |
4 |     let n = consume(s.clone());
  |                      ++++++++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0382`.

This diagnostic offers two repairs, and they are not equally good. The note proposes changing the parameter to borrow — the correct first answer whenever the function does not need to own the value, and here it plainly does not: consume reads a length and drops the string. The help proposes cloning at the call site — that always compiles, and it pays for a full duplication so one copy can be thrown away by a function that never needed a copy. The compiler lists the clone because it is a mechanical edit requiring no knowledge of the function's contract. You have that knowledge. Read the note before the help, and fix the signature rather than the call.

The same shape appears with the error codes index's own example, which uses a plain struct rather than a function call. A struct type that is not Copy moves on assignment even when every field inside it is a small integer, because Copy is a property of the whole type, granted by an implementation, never inferred from the fields:

Rust
struct MyStruct { s: u32 }
fn main() {
    let x = MyStruct { s: 5 };
    let y = x;
    println!("{}", x.s);
}
Terminal
$ rustc --edition 2021 fail_struct_move.rs -o fail_struct_move
error[E0382]: borrow of moved value: `x`
 --> fail_struct_move.rs:5:20
  |
3 |     let x = MyStruct { s: 5 };
  |         - move occurs because `x` has type `MyStruct`, which does not implement the `Copy` trait
4 |     let y = x;
  |             - value moved here
5 |     println!("{}", x.s);
  |                    ^^^ value borrowed here after move
  |
note: if `MyStruct` implemented `Clone`, you could clone the value
 --> fail_struct_move.rs:1:1
  |
1 | struct MyStruct { s: u32 }
  | ^^^^^^^^^^^^^^^ consider implementing `Clone` for this type
...
4 |     let y = x;
  |             - you could clone this value

warning: unused variable: `y`
 --> fail_struct_move.rs:4:9
  |
4 |     let y = x;
  |         ^ help: if this is intentional, prefix it with an underscore: `_y`
  |
  = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default

error: aborting due to 1 previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0382`.

Two lessons live in this second transcript. First, a field read is a borrow of the whole binding for this error: printing x.s after the move fails even though the field is a u32, a Copy type, because the path to the field goes through a binding that owns nothing anymore. Partial access does not rescue a total move — contrast the partial-move section below, where the move itself is partial and the answer is different. Second, the compiler's suggestions follow the information it has: with no parameter to borrow, it suggests Clone, the repair it can point at without redesigning the type. The repair to reach for first is the one it cannot propose from this evidence alone: this struct, holding one u32, is a candidate for Copy itself. Compiler suggestions are evidence about the error, not a ranking of the fixes.

The second failure: the loop that consumes its collection

A for loop over a collection by value moves the collection before the first iteration. The loop is not borrowing the elements one at a time; it is consuming the collection through its iterator, and consumption is ownership. The failure surfaces only when code after the loop reaches for the collection — a length check, a second pass, a print — which is why this form so often surprises: the loop itself looks innocent, and the error lands on an unrelated-looking line below it:

Rust
fn main() {
    let v = vec![String::from("a"), String::from("b")];
    for x in v {
        println!("x = {x}");
    }
    println!("v has {} items", v.len());
}
Terminal
$ rustc --edition 2021 fail_loop.rs -o fail_loop
error[E0382]: borrow of moved value: `v`
 --> fail_loop.rs:6:32
  |
2 |     let v = vec![String::from("a"), String::from("b")];
  |         - move occurs because `v` has type `Vec<String>`, which does not implement the `Copy` trait
3 |     for x in v {
  |              - `v` moved due to this implicit call to `.into_iter()`
...
6 |     println!("v has {} items", v.len());
  |                                ^ value borrowed here after move
  |
note: the `for` loop is desugared into a call to `std::iter::IntoIterator::into_iter`, which takes ownership of the receiver `self`, which moves `v`
 --> /rustc/b940084d7eb6a299eb4bfeb8e34901bc051e7ac4/library/core/src/iter/traits/collect.rs:312:17
help: consider iterating over a slice of the `Vec<String>`'s content to avoid moving into the `for` loop
  |
3 |     for x in &v {
  |              +

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0382`.

The note explains the mechanism exactly: the loop desugars into a call to into_iter, which takes the receiver by value, which moves v. Iteration by value is a real feature with real uses — when the loop is the collection's last use, consuming it element by element is the honest expression of that, and each element arrives owned, ready to be stored elsewhere or transformed without cloning. The error arises only when the program's intent disagrees with that consumption: the code meant to visit the elements, not to spend the collection. Visiting is a borrow, and the help shows its spelling. Writing &v in the loop header, or calling .iter(), lends the collection to the loop; each element arrives as a reference; and the collection is intact afterward:

Rust
fn main() {
    let v = vec![String::from("a"), String::from("b")];
    for x in &v {
        println!("x = {x}");
    }
    println!("v has {} items", v.len());
    for x in v.iter() {
        println!("again x = {x}");
    }
    println!("v still has {} items", v.len());
}
Terminal
$ rustc --edition 2021 ok_loop_borrow.rs -o ok_loop_borrow
$ ./ok_loop_borrow
x = a
x = b
v has 2 items
again x = a
again x = b
v still has 2 items

The diagnostic question for the loop form is about the program, not the syntax: is this loop the collection's final use, or a visit among several? If it is final, keep for x in v and delete or move the later use. If it is a visit, borrow. What never helps is cloning the collection before the loop so the original survives: that pays for a full duplication to preserve a value the program only ever wanted to read.

The third failure: the value moved into a closure

A closure marked move takes ownership of every value it captures, and the enclosing binding is emptied at the closure's definition, not at its call. This form confuses because the two lines look symmetric — the closure prints the string, then the outer code prints it — and because closures without move borrow their captures, so the keyword is doing all the damage in a place the eye slides over:

Rust
fn main() {
    let s = String::from("hello");
    let f = move || println!("inside: {s}");
    f();
    println!("outside: {s}");
}
Terminal
$ rustc --edition 2021 fail_closure.rs -o fail_closure
error[E0382]: borrow of moved value: `s`
 --> fail_closure.rs:5:25
  |
2 |     let s = String::from("hello");
  |         - move occurs because `s` has type `String`, which does not implement the `Copy` trait
3 |     let f = move || println!("inside: {s}");
  |             -------                    - variable moved due to use in closure
  |             |
  |             value moved into closure here
4 |     f();
5 |     println!("outside: {s}");
  |                         ^ value borrowed here after move
  |
help: consider cloning the value before moving it into the closure
  |
3 ~     let value = s.clone();
4 ~     let f = move || println!("inside: {value}");
  |

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0382`.

The thread form is the same failure: std::thread::spawn requires a move closure, because the new thread may outlive the frame that created it, and a vector moved into a spawned thread produces the identical diagnostic, with the compiler suggesting a clone before the move. When the parent needs the data afterward, clone before the move when the thread needs its own copy, share under Arc when both sides need the same value, or return what the parent needs through the join handle. What does not exist is a borrow across spawn.

For an ordinary closure, first ask whether move is needed at all. A closure that only reads a captured value borrows it by default, and removing an unneeded move ends the error with no other change. move earns its place when the closure must outlive the current scope — and in exactly those cases the outer code's later use is usually the design error: a value cannot both leave inside a closure and stay for later use.

The partial-move form: one field leaves, and the boundary is exact

The most instructive form of this error moves only part of a value. Moving a field out of a struct leaves the struct partially moved, and from that point the compiler tracks the fields individually, with exact verdicts: some uses still compile, some fail with E0382, and one fails with a different message entirely. Probing that boundary, rather than guessing it, is the skill this section teaches.

Start with the use that survives. Moving the name field out of a struct leaves the other field fully usable:

Rust
struct User { name: String, id: u32 }
fn main() {
    let u = User { name: String::from("Ada"), id: 7 };
    let n = u.name;
    println!("n = {n}");
    println!("u.id = {}", u.id);
}
Terminal
$ rustc --edition 2021 ok_partial_otherfield.rs -o ok_partial_otherfield
$ ./ok_partial_otherfield
n = Ada
u.id = 7

This program compiles and prints both lines. Reading u.id after u.name has moved is not an error, because id never moved: the compiler's accounting is per field, not per struct, once a partial move has happened. Code may keep working with every field that stayed, for as long as it likes, in any order. This is what makes partial moves useful rather than merely tolerated: destructuring a struct into the pieces a computation needs, spending some pieces and keeping others, is ordinary Rust, and the compiler supports it field by field.

Now the use that fails with E0382. Reaching for the moved field itself, by its full path, is a borrow of a moved value — the field is a value, it moved, and its old path is empty in exactly the binding sense from the first section:

Rust
struct User { name: String, id: u32 }
fn main() {
    let u = User { name: String::from("Ada"), id: 7 };
    let n = u.name;
    println!("n = {n}, name again = {}", u.name);
}
Terminal
$ rustc --edition 2021 fail_partial_movedfield.rs -o fail_partial_movedfield
error[E0382]: borrow of moved value: `u.name`
 --> fail_partial_movedfield.rs:5:42
  |
4 |     let n = u.name;
  |             ------ value moved here
5 |     println!("n = {n}, name again = {}", u.name);
  |                                          ^^^^^^ value borrowed here after move
  |
  = note: move occurs because `u.name` has type `String`, which does not implement the `Copy` trait

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0382`.

Note the diagnostic's precision: the moved value is named u.name, not u. The compiler is telling you its accounting is at field granularity. A Copy field never triggers this — reading u.id copies the integer and moves nothing, which is why the surviving program above could both move name and read id without any special permission. The fields divide by trait, not by position: the non-Copy fields are the ones that can be moved out, and each one, once moved, is individually dead.

The third use fails differently, and the difference is the section's sharpest lesson. Using the whole struct after a partial move — passing it to a function, returning it, moving it into another binding — is refused, but not as a borrow of a moved value. The compiler calls it a use of a partially moved value:

Rust
struct User { name: String, id: u32 }
fn show(u: User) { println!("{} {}", u.name, u.id); }
fn main() {
    let u = User { name: String::from("Ada"), id: 7 };
    let n = u.name;
    println!("n = {n}");
    show(u);
}
Terminal
$ rustc --edition 2021 fail_partial_wholeuse.rs -o fail_partial_wholeuse
error[E0382]: use of partially moved value: `u`
 --> fail_partial_wholeuse.rs:7:10
  |
5 |     let n = u.name;
  |             ------ value partially moved here
6 |     println!("n = {n}");
7 |     show(u);
  |          ^ value used here after partial move
  |
  = note: partial move occurs because `u.name` has type `String`, which does not implement the `Copy` trait

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0382`.

The error code is still E0382, but the message separates the cases, and a reader who knows the separation diagnoses faster. Borrow of moved value, naming a field: that field was spent, and the fix concerns that field — borrow it next time, clone it, or take it with a replacement. Use of partially moved value, naming the whole binding: the code tried to treat a dismantled struct as a whole one, and the fix is structural — either the dismantling was premature and the whole-value use should come first, or the dismantling is the design and the whole-value use must be rewritten in terms of the fields that remain, or the moved field must be put back. A partially moved struct can in fact be made whole again: assign a new value to the moved field, and the binding is complete from that line onward, eligible for whole-value uses again. The take fix in the next section relies on exactly this: it moves a field out while simultaneously leaving a valid replacement in its place, so the struct never sits dismantled at all.

Hold the three verdicts together and the partial-move rule is one sentence: after a field moves out, the remaining fields are yours, the moved field is gone, and the whole is unavailable until the moved field is restored. Every E0382 involving a struct field is one of those three clauses being violated, and the diagnostic's wording tells you which one before you read a line of the code.

Fix 1: borrow instead of moving — change the parameter to a reference

The first fix to reach for is the one the canonical diagnostic itself notes: if the receiving code does not need to own the value, it should not take ownership. Change the parameter from the owned type to a reference to it, and pass a reference at the call. The caller's binding never empties, because nothing moved; the function reads through the borrow and hands the value back by never having taken it:

Rust
fn measure(s: &str) -> usize { s.len() }
fn main() {
    let s = String::from("hello");
    let n = measure(&s);
    println!("n = {n}, s = {s}");
    let m = measure("world");
    println!("m = {m}");
}
Terminal
$ rustc --edition 2021 fix_borrow.rs -o fix_borrow
$ ./fix_borrow
n = 5, s = hello
m = 5

Two details in this program generalize. The parameter is &str, not &String. A function that only reads string data should accept the slice type, because a &String dereferences to a &str automatically at the call, and the &str signature also accepts string literals and slices of larger strings — the second call in the program, passing "world" directly, is one the &String version would refuse. The error codes index makes the same repair with &String in its own example, passing &s1 to a function that calculates a length; the &str form here is that repair carried one step further, to the signature most read-only string functions should have. And the call passes &s, making the borrow visible at the exact site where the move used to happen. When you apply this fix, the diff tells the story at both ends: the signature stops claiming ownership, and the call site stops giving it.

Borrowing applies at every move site, not only at parameters: a loop borrows with &v or .iter(), a closure by dropping an unneeded move, a field by binding let n = &u.name;. The selecting question is always the same: does the receiving code need to own this value, or only to look at it? If it only needs to look, the move was a mistake in the signature, the loop header, or the capture. Reach for this fix first because it costs nothing at runtime and usually makes the API more honest for every future caller.

Fix 2: return the value, or restructure so ownership round-trips

Sometimes the receiver genuinely needs ownership: it transforms the value, extends it, stores it, or builds on it in ways a borrow cannot express. Then the move is correct, and the error is in the caller's expectation that the original binding would survive. The repair is to make the ownership round-trip explicit: the function takes the value and returns it — transformed, or alongside what it computed — and the caller rebinds the result. Shadowing the old name with the returned value is the idiomatic spelling, because there is only ever one live owner and the name now refers to it:

Rust
fn shout(mut s: String) -> String { s.push('!'); s }
fn main() {
    let s = String::from("hello");
    let s = shout(s);
    println!("s = {s}");
}
Terminal
$ rustc --edition 2021 fix_return.rs -o fix_return
$ ./fix_return
s = hello!

The Book's ownership chapter shows the primitive form of this pattern — a function that takes a string and returns it alongside a computed length, forcing the caller into an awkward tuple — and presents it precisely as the clumsiness that borrowing exists to replace. That history sets this fix's place in the order. Returning the value is not the general answer to E0382; borrowing is. Returning is the answer for the narrower case where ownership really must cross: the function consumes the value as raw material and produces the value the program continues with. A builder that finishes a struct, a parser that takes a buffer and returns a document, a transform that cannot be expressed as a mutation through &mut because it replaces the value wholesale — these round-trip honestly, and the signature says so. When neither borrowing nor a &mut mutation fits and ownership must move, return it, and let the call site's rebinding show the transfer completing.

The restructure variant moves code instead of values: if the caller needs the value afterward for one final read, do that read before the call and extract what the later code needs — a length, a flag, a summary — into owned results. This is the right form when the API is not yours to change: the library function keeps taking ownership, and your code arranges to need nothing from the value after surrendering it.

Fix 3: clone, priced honestly

Cloning duplicates the value so that both sides own one. It always works when the type implements Clone, it is the repair the compiler's help proposes at nearly every E0382 site, and it is third in this guide's order rather than first for one reason: it pays. The Clone documentation is explicit that cloning is always an explicit act and may or may not be expensive — for a String or a Vec, a clone allocates a new heap buffer and copies every element, a cost proportional to data the borrowing fix handles for free:

Rust
fn consume(s: String) -> usize { s.len() }
fn main() {
    let s = String::from("hello");
    let n = consume(s.clone());
    println!("n = {n}, s = {s}");
}
Terminal
$ rustc --edition 2021 fix_clone.rs -o fix_clone
$ ./fix_clone
n = 5, s = hello

This program is correct and, for this callee, wasteful: consume measures the clone and drops it, so the program allocated a second string to throw it away. The same program with a callee that stores the string, sends it to another thread, or returns it as part of a larger structure is a different judgment — there, two owners are the actual design, and the clone is how the program says so. The discipline is not never clone; it is never clone by default. A clone added to silence E0382 should be able to answer three questions: what was duplicated, how large can it grow, and why did the design need two owners rather than one owner and a borrow? When the answers are clear, clone without guilt. When they are not, the clone is hiding the signature mistake that Fix 1 corrects for free.

One refinement repays knowing when the same destination is cloned into repeatedly: clone_from reuses the destination's existing allocation where the type supports it. With a String destination that reserved capacity 32, after dest.clone_from(&source), the destination holds the source's text and still reports capacity 32, because clone_from fills the reserved buffer rather than replacing it. The Clone documentation notes that many types implement clone_from to reuse the destination's resources. In a loop that refreshes a working string from a series of sources, that is the difference between one allocation and one per iteration.

Fix 4: take or replace the field, so the struct is never dismantled

The partial-move section ended with a struct sitting dismantled: a field gone, the whole unusable. Often the program's real intent is narrower — it needs the field's value out, and it is content for the field to hold a replacement, frequently the type's default. std::mem::take performs exactly that exchange in one operation. Its documentation defines it as replacing the destination with the default value and returning the previous value, and its own motivating example is this guide's situation: taking ownership of a struct field by replacing it with an empty value, in code where cloning is not even available:

Rust
struct Bag { items: Vec<String>, label: String }
fn main() {
    let mut bag = Bag { items: vec![String::from("pen")], label: String::from("desk") };
    let items = std::mem::take(&mut bag.items);
    println!("items = {items:?}, bag.items = {:?}, bag.label = {}", bag.items, bag.label);
    let mut name = String::from("Ada");
    let old = std::mem::take(&mut name);
    println!("old = {old}, name now = {name:?}");
}
Terminal
$ rustc --edition 2021 fix_take.rs -o fix_take
$ ./fix_take
items = ["pen"], bag.items = [], bag.label = desk
old = Ada, name now = ""

Read the output as the ownership ledger it is. items holds the vector that was in the struct; bag.items is a valid empty vector left behind by take; bag.label is untouched — so bag remains a whole, usable struct, because no partial move persisted past the operation. The second half shows take on a plain binding: the old string moves out and the binding holds the default empty string. take requires Default, which String, Vec, and most collections implement; where the replacement should be a specific value rather than the default, std::mem::replace performs the same exchange with the replacement supplied. A moved-out field can also be healed by plain assignment, as this program does after its take:

Rust
struct User { name: String, id: u32 }
fn main() {
    let mut u = User { name: String::from("Ada"), id: 7 };
    let n = std::mem::take(&mut u.name);
    println!("n = {n}, u.name = {:?}, u.id = {}", u.name, u.id);
    u.name = String::from("Grace");
    println!("u = {} {}", u.name, u.id);
}
Terminal
$ rustc --edition 2021 ok_partial_reinit.rs -o ok_partial_reinit
$ ./ok_partial_reinit
n = Ada, u.name = "", u.id = 7
u = Grace 7

After the take, u.name reads as the empty string the default left behind — proof the field is present and the struct is whole at every line. After the assignment, the struct carries the new name. Compare the dismantled struct of the previous section, where u.name could not even be read: the difference between a partial move and a take is the difference between a field removed and a field exchanged.

Fix 5: derive Copy when copying is what the type means

For a small struct of plain data, the deepest fix is to remove the type from the move system altogether by making it Copy. Mechanically, every field must be Copy, and Clone must be implemented alongside, because Copy requires it; deriving both is the standard spelling. Semantically, bitwise duplication must be a faithful duplication: a point, a pair of counters, a small identifier — values with no heap allocation, no handle, and no identity that duplication would counterfeit:

Rust
#[derive(Debug, Copy, Clone)]
struct Point { x: i32, y: i32 }
fn main() {
    let p1 = Point { x: 1, y: 2 };
    let p2 = p1;
    println!("p1 = ({}, {}), p2 = ({}, {})", p1.x, p1.y, p2.x, p2.y);
}
Terminal
$ rustc --edition 2021 fix_copy2.rs -o fix_copy2
$ ./fix_copy2
p1 = (1, 2), p2 = (1, 2)

Assignment now copies, and both names print. The error codes index demonstrates the same derivation on a two-integer point: because the type stores only integers, opting out of ownership semantics with Copy lets the code assign it and keep using the original. The Copy documentation adds the judgment that should gate this fix: a type should be Copy when duplicating it is cheap and meaningless to observe. The moment a type acquires a field that owns something — the next section's trap — the derivation stops compiling, and that refusal is the type system protecting the semantics, not obstructing them.

Fix 6: share ownership with Rc when one owner is the wrong model

The last fix changes the ownership model itself. Occasionally a value genuinely has several owners with no natural ranking: a shared configuration read by many components, a node referenced from several places in a graph-shaped structure, a string several closures each need to hold. Rc, the single-threaded reference-counted pointer, makes the sharing explicit: the value lives as long as any Rc pointing at it, and cloning an Rc copies the pointer and raises the count rather than duplicating the value:

Rust
use std::rc::Rc;
fn main() {
    let s = Rc::new(String::from("shared"));
    let a = Rc::clone(&s);
    let b = Rc::clone(&s);
    println!("a = {a}, b = {b}, s = {s}, count = {}", Rc::strong_count(&s));
}
Terminal
$ rustc --edition 2021 fix_rc.rs -o fix_rc
$ ./fix_rc
a = shared, b = shared, s = shared, count = 3

The count of 3 is the design made visible: three owners, one string, no moves that empty anyone. The error codes index reaches for the same tool, pairing Rc with RefCell where mutable shared ownership is truly required; the RefCell half adds runtime-checked mutation and is a further step, to take only when mutation is genuinely part of the sharing. Plain Rc sharing is read-only through the pointer, and most shared-ownership designs share data for reading. Across threads the corresponding type is Arc. Reach for this fix last, because it answers a different question: Fixes 1 through 5 assume one owner was right and the move was mishandled; this fix is for when one owner was never the design — and a reader should be able to say, in one sentence, why the value has several owners before the first Rc appears.

The traps: cloning everything, and Copy on a type that owns heap data

Trap
Two responses to E0382 silence the error while damaging the program, and both are tempting because both are small edits at the error site.

The first is cloning by default: meeting every move error with a .clone() until the compiler stops complaining. The program slowly fills with duplications nobody chose — strings copied so a length can be read, collections copied so a loop can visit them. At runtime, every clone of a heap type allocates and copies in proportion to the data, on paths borrowing serves at zero cost. In the code, the clones erase the information ownership was carrying: a signature that takes ownership now falsely claims it needs to, and the next reader cannot tell which copies are design and which are scar tissue. The compiler's help proposes cloning because it is the repair it can guarantee; treating that guarantee as guidance is the trap.

The second trap is reaching for Copy as an escape hatch: a struct keeps producing move errors, so a derive line is added to make the errors stop. For a struct that owns heap data, the language refuses outright, and the refusal is worth seeing, because it demonstrates that Copy is a semantic claim the compiler audits, not a switch:

Rust
#[derive(Debug, Copy, Clone)]
struct Named { name: String, id: u32 }
fn main() {
    let a = Named { name: String::from("Ada"), id: 7 };
    let b = a;
    println!("{a:?} {b:?}");
}
Terminal
$ rustc --edition 2021 fail_copy_heap.rs -o fail_copy_heap
error[E0204]: the trait `Copy` cannot be implemented for this type
 --> fail_copy_heap.rs:2:8
  |
1 | #[derive(Debug, Copy, Clone)]
  |                 ---- in this derive macro expansion
2 | struct Named { name: String, id: u32 }
  |        ^^^^^   ------------ this field does not implement `Copy`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0204`.

The error is E0204, not E0382, and it names the offending field: String does not implement Copy, so nothing containing a String can. A bitwise copy of a Named would copy the pointer, length, and capacity of its String field, producing two values that each believe they own one heap buffer — the exact state the move rule exists to prevent, recreated inside a single assignment. When this error greets an attempted derive, the type is telling you it owns something; the correct responses are the ones already ranked: borrow the type, clone it deliberately, or share it under a count.

Which fix for which error

What the diagnostic shows What is actually happening First fix to reach for
Parameter takes ownership; note suggests borrowing instead The callee only reads the value, but its signature claims ownership Fix 1 — change the parameter to &T, or &str for string data
Assignment to a second binding, first binding used later One value, two intended owners, no sharing mechanism chosen Decide: borrow from the second binding, or Fix 3 — clone if two owners are the design
for loop over the collection, collection used afterward into_iter consumed the collection the code meant to visit Borrow in the loop header — &v or .iter(); keep the consuming loop only if it is the last use
move closure or thread::spawn, outer binding used afterward The closure took ownership the enclosing code still expected Drop an unneeded move; otherwise clone before the move, share with Rc or Arc, or return the value through the handle
Borrow of moved value naming a field, such as u.name That field was moved out; the rest of the struct is intact Work with the remaining fields, borrow the field next time, or Fix 4 — take the field with a replacement
Use of partially moved value naming the whole binding A dismantled struct was used as a whole value Reorder the whole-value use before the dismantling, rewrite it over the remaining fields, or restore the moved field
Small plain-data struct moves when it should copy The type never opted into Copy though every field is Copy Fix 5 — derive Copy and Clone, after the semantic check that duplication is unobservable
Several components each need to hold the value One owner was never the design Fix 6 — Rc for shared ownership on one thread, Arc across threads
Callee must own and transform the value; caller needs the result Ownership has to cross and come back changed Fix 2 — return the value and rebind it at the call site

Checklist

  • Read all three positions in the diagnostic before editing: the note giving the type's reason, the line where the value moved, and the line where the emptied binding was used. The move line selects the fix; the use line only reports the damage.
  • Ask of every move site whether the receiver needs to own the value or only to look at it. Looking is a borrow, and borrowing is the first fix at parameters, loop headers, closure captures, and field reads alike.
  • Prefer the diagnostic's note over its help. A note proposing a borrow describes your function's contract; a help proposing a clone describes a mechanical edit, and the two are not ranked equally.
  • In loops, decide whether the loop is the collection's last use or a visit. Last use: consume it proudly and remove the later code. A visit: borrow with &v or .iter(), and never clone a collection just to look at its elements.
  • With closures, check whether move is required before paying for it. An unneeded move removed is the cheapest fix in this guide; a needed one means the outer use, not the closure, is the design error.
  • Diagnose partial moves by the diagnostic's wording. A moved field named in the error is gone individually; the other fields remain usable; the whole binding is unavailable until the moved field is restored or the field is taken with a replacement.
  • Use std::mem::take or replace when a field must come out and the struct must stay whole: the replacement left behind is what separates an exchange from a dismantling.
  • Price every clone before keeping it: what was duplicated, how large it can grow, how often the path runs, and why two owners are the design. A clone that cannot answer is a borrow that was not tried.
  • Derive Copy only when every field is Copy and duplication is semantically invisible. If the derive fails with E0204, the type owns something; do not argue with it — borrow, clone, or share the type instead.
  • Reach for Rc or Arc only with a one-sentence account of why the value has several owners. Shared ownership chosen by default is single ownership with extra counting.
  • After the fix, reread the code for the question the error was asking: after this line, who owns the value, and does every later use agree with that answer?

Sources

  • Rust Project, Error codes index: E0382 — for the definition of E0382 as a variable used after its contents have been moved elsewhere, for the index's own examples of the assignment, borrowing, cloning, Copy, and Rc with RefCell repairs, and for the statement that a value cannot be owned by more than one variable outside of workarounds like Rc.
  • Rust Project, The Rust Programming Language: What Is Ownership? — for move semantics on assignment, for the contrast between a move and a copy for stack-only data, and for the take-and-return pattern this guide's Fix 2 narrows to the cases where ownership must round-trip.
  • Rust Project, The Rust Programming Language: References and Borrowing — for the reference as the answer to a function consuming its argument, for &s creating a reference that refers to a value without owning it, and for the value not being dropped when a non-owning reference stops being used.
  • Rust Project, std::marker::Copy — for Copy as duplication by copying bits, for move semantics as the default for non-Copy bindings, for the contrast between implicit, inexpensive copies and explicit, possibly expensive clones, and for implementing Copy by deriving it when every member is Copy.
  • Rust Project, std::clone::Clone — for cloning as an always explicit duplication that may run arbitrary code, for Copy requiring Clone with cloning equivalent to copying, and for clone_from reusing the destination's resources where a type implements it to do so.
  • Rust Project, std::mem::take — for take replacing a destination with its default value and returning the previous value, and for its worked example of taking ownership of a struct field where cloning is unavailable.
  • Rust Project, std::rc::Rc — for Rc as the single-threaded reference-counting pointer behind Fix 6, whose clones share one value under a strong count rather than duplicating it.

Keep Exploring