title: Option<Receiver> Moved in Previous Loop Iteration
body: <p>I'm spawning a thread that does some work. Sometimes I want this thread to die after the work is finished, other times I want it to wait for more work to do. To do this I pass in an <code>Option&lt;Receiver&lt;T&gt;&gt;</code>. If <code>Option&lt;Receiver&lt;T&gt;&gt;</code> is <code>None</code> the thread should die, else it should wait to receive more work.</p>
  
  <pre><code>fn foo(rx: Option&lt;Receiver&lt;usize&gt;&gt;) {
      thread::spawn(move || {
          loop {
              do_some_work();
              if let Some(r) = rx {
                  match r.recv() {
                      Ok(x)  =&gt; {}
                      Err(_) =&gt; panic!("Oh no!"),
                  }
              } else {
                  break; //Die
              }
          }
      });
  }
  </code></pre>
  
  <p>(<a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=daf93b80174e754b2202ef7c02ef993a" rel="nofollow noreferrer">link to playground</a>)</p>
  
  <p>The compiler says:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0382]: use of moved value
    --&gt; src/lib.rs:10:25
     |
  10 |             if let Some(r) = rx {
     |                         ^ value moved here, in previous iteration of loop
     |
     = note: move occurs because value has type `std::sync::mpsc::Receiver&lt;usize&gt;`, which does not implement the `Copy` trait
  </code></pre>
  
  <p>However if the <code>Receiver</code> is not enclosed in an <code>Option</code> everything is fine.</p>
  
  <pre><code>fn foo(rx: Receiver&lt;usize&gt;) {
      thread::spawn(move || {
          loop {
              do_some_work();
              match rx.recv() {
                  Ok(x)  =&gt; {}
                  Err(_) =&gt; panic!("Oh no!"),
              }
          }
      });
  }
  </code></pre>