<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="struct Foo {
    bar: u32,
}

fn main() {
    let mut foo = Foo { bar: 10 };
    let foo2 = foo; // &lt;-- moved here

    foo.bar = 20; // &lt;-- but still works!

    println!(&quot;{}&quot;, foo.bar); // &lt;- failed because `foo` has been moved
}"><pre class="notranslate"><span class="pl-k">struct</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
    <span class="pl-c1">bar</span><span class="pl-kos">:</span> <span class="pl-smi">u32</span><span class="pl-kos">,</span>
<span class="pl-kos">}</span>

<span class="pl-k">fn</span> <span class="pl-en">main</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">let</span> <span class="pl-k">mut</span> foo = <span class="pl-smi">Foo</span> <span class="pl-kos">{</span> <span class="pl-c1">bar</span><span class="pl-kos">:</span> <span class="pl-c1">10</span> <span class="pl-kos">}</span><span class="pl-kos">;</span>
    <span class="pl-k">let</span> foo2 = foo<span class="pl-kos">;</span> <span class="pl-c">// &lt;-- moved here</span>

    foo<span class="pl-kos">.</span><span class="pl-c1">bar</span> = <span class="pl-c1">20</span><span class="pl-kos">;</span> <span class="pl-c">// &lt;-- but still works!</span>

    <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"{}"</span>, foo.bar<span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// &lt;- failed because `foo` has been moved</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Here is some sample code:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#[derive(Show)]
struct Pair { lft: u8, rgt: u8, }

fn main() {
    let mut p = Pair { lft: 1, rgt: 2 };
    let mut f = move |&amp;mut:| { p.lft = 3; p.rgt };
    p.rgt = 4;
    println!(&quot;f: {:?}&quot;, f());
    p.lft = 5;
    // println!(&quot;p: {:?}&quot;, p);
}"><pre class="notranslate"><span class="pl-c1">#<span class="pl-kos">[</span>derive<span class="pl-kos">(</span><span class="pl-v">Show</span><span class="pl-kos">)</span><span class="pl-kos">]</span></span>
<span class="pl-k">struct</span> <span class="pl-smi">Pair</span> <span class="pl-kos">{</span> <span class="pl-c1">lft</span><span class="pl-kos">:</span> <span class="pl-smi">u8</span><span class="pl-kos">,</span> <span class="pl-c1">rgt</span><span class="pl-kos">:</span> <span class="pl-smi">u8</span><span class="pl-kos">,</span> <span class="pl-kos">}</span>

<span class="pl-k">fn</span> <span class="pl-en">main</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">let</span> <span class="pl-k">mut</span> p = <span class="pl-smi">Pair</span> <span class="pl-kos">{</span> <span class="pl-c1">lft</span><span class="pl-kos">:</span> <span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-c1">rgt</span><span class="pl-kos">:</span> <span class="pl-c1">2</span> <span class="pl-kos">}</span><span class="pl-kos">;</span>
    <span class="pl-k">let</span> <span class="pl-k">mut</span> f = <span class="pl-k">move</span> |<span class="pl-c1">&amp;</span><span class="pl-k">mut</span><span class="pl-kos">:</span>| <span class="pl-kos">{</span> p<span class="pl-kos">.</span><span class="pl-c1">lft</span> = <span class="pl-c1">3</span><span class="pl-kos">;</span> p<span class="pl-kos">.</span><span class="pl-c1">rgt</span> <span class="pl-kos">}</span><span class="pl-kos">;</span>
    p<span class="pl-kos">.</span><span class="pl-c1">rgt</span> = <span class="pl-c1">4</span><span class="pl-kos">;</span>
    <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"f: {:?}"</span>, f<span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    p<span class="pl-kos">.</span><span class="pl-c1">lft</span> = <span class="pl-c1">5</span><span class="pl-kos">;</span>
    <span class="pl-c">// println!("p: {:?}", p);</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">This compiles without an error; running it prints <code class="notranslate">f: 2u8</code>.</p>
<p dir="auto">If you uncomment the last line, you get an error saying "error: use of moved value: <code class="notranslate">p</code>".  Likewise if you just attempt to print individual fields.</p>
<p dir="auto">While I do see the logic being used here ("we are not overwriting the value within the closure itself; we are writing into the uninitialized memory that resulted from moving <code class="notranslate">p</code> into the closure"), it seems potentially confusing.</p>
<p dir="auto">Is there any reason that we allowing these writes, which cannot be subsequently read?  It seems like a situation analogous to moving into a moved-away array (see <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="52510539" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rfcs/issues/533" data-hovercard-type="pull_request" data-hovercard-url="/rust-lang/rfcs/pull/533/hovercard" href="https://github.com/rust-lang/rfcs/pull/533">rust-lang/rfcs#533</a> )</p>