title: How to loop twice over the same vector?
body: <p>I am trying to update elements of a vector knowing where each other is, <em>i.e.</em> test all pairs of elements (unordered), while changing them. So I started naively writing this:</p>
  
  <pre class="lang-rust prettyprint-override"><code>for x in &amp;mut v {
      for y in &amp;mut v {
          // ...
      }
  }
  </code></pre>
  
  <p>But I cannot mutably borrow the vector twice, plus, I could simply avoid a lot of iterations, writing this:</p>
  
  <pre class="lang-rust prettyprint-override"><code>for x in 0..v.len() - 1 {
      for y in x..v.len() - 1 {
          let mut xc = &amp;mut v[x];
          let yc = &amp;v[y];
          // ...
      }
  }
  </code></pre>
  
  <p>This doesn't work, because I borrow an immutable and a mutable reference! How can I write this basic kind of loop? (I do need the mutability for at least one of the elements.)</p>