title: How to get mutable references to two array elements at the same time?
body: <pre><code>fn change(a: &amp;mut i32, b: &amp;mut i32) {
      let c = *a;
      *a = *b;
      *b = c;
  }
  
  fn main() {
      let mut v = vec![1, 2, 3];
      change(&amp;mut v[0], &amp;mut v[1]);
  }
  </code></pre>
  
  <p>When I compile the code above, it has the error:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0499]: cannot borrow `v` as mutable more than once at a time
   --&gt; src/main.rs:9:32
    |
  9 |         change(&amp;mut v[0], &amp;mut v[1]);
    |                     -          ^   - first borrow ends here
    |                     |          |
    |                     |          second mutable borrow occurs here
    |                     first mutable borrow occurs here
  </code></pre>
  
  <p>Why does the compiler prohibit it? <code>v[0]</code> and <code>v[1]</code> occupy different memory positions, so it's not dangerous to use these together. And what should I do if I come across this problem?</p>