title: Insertion sort algorithm gives overflow error
body: <p>When trying to run the insertion sort algorithm as shown below in Rust 1.15.</p>
  
  <pre><code>fn main() {
      println!("The sorted set is now: {:?}", insertion_sort(vec![5,2,4,6,1,3]));
  }
  
  fn insertion_sort(set: Vec&lt;i32&gt;) -&gt; Vec&lt;i32&gt; {
      let mut A = set.to_vec();
      for j in 1..set.len() {
          let key = A[j];
          let mut i = j - 1;
          while (i &gt;= 0) &amp;&amp; (A[i] &gt; key) {
              A[i + 1] = A[i];
              i = i - 1;
          }
          A[i + 1] = key;
      }
      A
  }
  </code></pre>
  
  <p>I get the error: </p>
  
  <pre class="lang-none prettyprint-override"><code>thread 'main' panicked at 'attempt to subtract with overflow', insertion_sort.rs:12
  note: Run with `RUST_BACKTRACE=1` for a backtrace
  </code></pre>
  
  <p>Why does an overflow happen here and how is the problem alleviated? </p>