title: Closures keep ownership of local variables for longer than expected
body: <pre><code>let array = [40];
  let mut var = 60;
  
  for element in array.iter().filter(|&amp;x| {*x &lt; var}) {
      var += 1; // Error
  }
  
  var += 1; // Fine again
  </code></pre>
  
  <p>To me this code seems completely legit, as the closure should be over by the time I actually access <code>var</code> outside of it.</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0506]: cannot assign to `var` because it is borrowed
   --&gt; src/main.rs:6:9
    |
  5 |     for element in array.iter().filter(|&amp;x| {*x &lt; var}) {
    |                                        ---- borrow of `var` occurs here
  6 |         var += 1; // Error
    |         ^^^^^^^^ assignment to borrowed `var` occurs here
  </code></pre>
  
  <p>Why is <code>var</code> still borrowed when calling <code>var += 1</code> even though the scope of the closure should be already over? The result is needed to get to <code>var += 1</code>. While it is possible to do something like this without <code>filter</code>, it causes my code to be a lot less clear, so I would like to keep using it.</p>