title: Cannot move out of borrowed content / cannot move out of behind a shared reference
body: <p>I don't understand the error <code>cannot move out of borrowed content</code>. I have received it many times and I have always solved it, but I've never understood why.</p>
  
  <p>For example:</p>
  
  <pre><code>for line in self.xslg_file.iter() {
      self.buffer.clear();
  
      for current_char in line.into_bytes().iter() {
          self.buffer.push(*current_char as char);
      }
  
      println!("{}", line);
  }
  </code></pre>
  
  <p>produces the error:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0507]: cannot move out of borrowed content
    --&gt; src/main.rs:31:33
     |
  31 |             for current_char in line.into_bytes().iter() {
     |                                 ^^^^ cannot move out of borrowed content
  </code></pre>
  
  <p>In newer versions of Rust, the error is</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0507]: cannot move out of `*line` which is behind a shared reference
    --&gt; src/main.rs:31:33
     |
  31 |             for current_char in line.into_bytes().iter() {
     |                                 ^^^^ move occurs because `*line` has type `std::string::String`, which does not implement the `Copy` trait
  </code></pre>
  
  <p>I solved it by cloning <code>line</code>:</p>
  
  <pre><code>for current_char in line.clone().into_bytes().iter() {
  </code></pre>
  
  <p>I don't understand the error even after reading other posts like:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/28034646/cant-borrow-file-from-mut-self-error-msg-cannot-move-out-of-borrowed-content">Can&#39;t borrow File from &amp;mut self (error msg: cannot move out of borrowed content)</a></li>
  <li><a href="https://stackoverflow.com/questions/28008585/changing-a-node-in-a-tree-in-rust">Changing a node in a tree in Rust</a></li>
  </ul>
  
  <p>What is the origin of this kind of error?</p>