title: Why is the value moved into the closure here rather than borrowed?
body: <p>The <a href="https://doc.rust-lang.org/book/error-handling.html#the-limits-of-combinators" rel="noreferrer">Error Handling chapter</a> of the Rust Book contains an example on how to use the combinators of <code>Option</code> and <code>Result</code>. A file is read and through application of a series of combinators the contents are parsed as an <code>i32</code> and returned in a <code>Result&lt;i32, String&gt;</code>.
  Now, I got confused when I looked at the code. There, in one closure to an and_then a local <code>String</code> value is created an subsequently passed as a return value to another combinator.</p>
  
  <p>Here is the code example:</p>
  
  <pre><code>use std::fs::File;
  use std::io::Read;
  use std::path::Path;
  
  fn file_double&lt;P: AsRef&lt;Path&gt;&gt;(file_path: P) -&gt; Result&lt;i32, String&gt; {
      File::open(file_path)
           .map_err(|err| err.to_string())
           .and_then(|mut file| {
                let mut contents = String::new(); // local value
                file.read_to_string(&amp;mut contents)
                    .map_err(|err| err.to_string())
                    .map(|_| contents) // moved without 'move'
           })
           .and_then(|contents| {
                contents.trim().parse::&lt;i32&gt;()
                        .map_err(|err| err.to_string())
           })
           .map(|n| 2 * n)
  }
  
  fn main() {
      match file_double("foobar") {
          Ok(n) =&gt; println!("{}", n),
          Err(err) =&gt; println!("Error: {}", err),
      }
  }
  </code></pre>
  
  <p>The value I am referring to is <code>contents</code>. It is created and later referenced in the <code>map</code> combinator applied to the <code>std::io::Result&lt;usize&gt;</code> return value of <code>Read::read_to_string</code>.
  The question: I thought that <strong>not</strong> marking the closure with <code>move</code> would borrow any referenced value by default, which would result in the borrow checker complaining, that <code>contents</code> does not live long enough. However, this code compiles just fine. That means, the <code>String</code> <code>contents</code> is moved into, and subequently out of, the closure. Why is this done without the explicit <code>move</code>?</p>