title: Cannot move out of borrowed content when trying to transfer ownership
body: <p>I'm writing a linked list to wrap my head around Rust lifetimes, ownership and references. I have the following code:</p>
  
  <pre><code>pub struct LinkedList {
      head: Option&lt;Box&lt;LinkedListNode&gt;&gt;,
  }
  
  pub struct LinkedListNode {
      next: Option&lt;Box&lt;LinkedListNode&gt;&gt;,
  }
  
  impl LinkedList {
      pub fn new() -&gt; LinkedList {
          LinkedList { head: None }
      }
  
      pub fn prepend_value(&amp;mut self) {
          let mut new_node = LinkedListNode { next: None };
  
          match self.head {
              Some(ref head) =&gt; new_node.next = Some(*head),
              None =&gt; new_node.next = None,
          };
  
          self.head = Some(Box::new(new_node));
      }
  }
  
  fn main() {}
  </code></pre>
  
  <p>But I am getting the following compilation error: </p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0507]: cannot move out of borrowed content
    --&gt; src/main.rs:18:52
     |
  18 |             Some(ref head) =&gt; new_node.next = Some(*head),
     |                                                    ^^^^^ cannot move out of borrowed content
  </code></pre>
  
  <p>Newer versions of Rust have a slightly different error:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0507]: cannot move out of `*head` which is behind a shared reference
    --&gt; src/main.rs:18:52
     |
  18 |             Some(ref head) =&gt; new_node.next = Some(*head),
     |                                                    ^^^^^ move occurs because `*head` has type `std::boxed::Box&lt;LinkedListNode&gt;`, which does not implement the `Copy` trait
  </code></pre>
  
  <p>I'm thinking that the <code>head</code> node must currently be owned by <code>self</code>, which is the linked list. When I assign it to <code>new_node.next</code>, there is probably a change of ownership that will happen. </p>
  
  <p>I would rather not clone the value if possible as that seems wasteful. I don't want to just "borrow" it for the duration of the function. I really want to transfer its ownership. </p>
  
  <p>How do I do that?</p>
  
  <p>I have already looked at <a href="https://stackoverflow.com/questions/28194335/error-cannot-move-out-of-borrowed-content-on-mut-self">cannot move out of borrowed content when unwrapping a member variable in a &amp;mut self method</a> and <a href="https://stackoverflow.com/questions/28158738/cannot-move-out-of-borrowed-content">Cannot move out of borrowed content / cannot move out of behind a shared reference</a>.</p>
  
  <p>I tried removing the match arm as suggested in the accepted answer in one of those questions and defining <code>next</code> in the creation of the new <code>LinkedListNode</code>, but I get the same error message.</p>
  
  <p>I have successfully added an <code>append</code> method which takes a <code>LinkedListNode</code> to add to the end of the list.</p>