title: Mutable vs. immutable borrows in closure?
body: <p>I can't figure out how to get the following to work.  I think I need the closure to borrow by <code>&amp;mut Vec</code>, but I don't know how to express that.  This is distilled from a larger function, but shows the same error.</p>
  <pre><code>fn main() {
      let mut v = vec![0; 10];
  
      let next = |i| (i + 1) % v.len();
  
      v[next(1usize)] = 1;
  
      v.push(13);
  
      v[next(2usize)] = 1;    
  }
  </code></pre>
  <p>Error:</p>
  <pre><code>error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable
   --&gt; a.rs:9:5
    |
  5 |     let next = |i| {
    |                --- immutable borrow occurs here
  6 |         (i + 1) % v.len()
    |                   - first borrow occurs due to use of `v` in closure
  ...
  9 |     v[next(1usize)] = 1;
    |     ^ ---- immutable borrow later used here
    |     |
    |     mutable borrow occurs here
  
  error: aborting due to previous error
  </code></pre>