title: Why does Rust fail to correctly infer the type?
body: <p>Why does this work fine:</p>
  <pre><code>let items = [1, 2, 3];
  let mut cumulator = 0;
  
  for next in items.iter() {
      cumulator += next;
  }
  
  println!(&quot;Final {}&quot;, cumulator);
  </code></pre>
  <p>But this fail?:</p>
  <pre><code>let items = [1, 2, 3];
  let mut cumulator = 0;
  
  for next in items.iter() {
      cumulator += next.pow(2);
  }
  
  println!(&quot;Final {}&quot;, cumulator);
  </code></pre>
  <p>Error on <code>.pow(2)</code>:</p>
  <pre><code>no method named `pow` found for reference `&amp;{integer}` in the current scope
  method not found in `&amp;{integer}`rustc (E0599)
  </code></pre>
  <p>My IDE identifies <code>next</code> as i32 and the first code example works fine. But the compiler has an issue the moment I reference <code>next.pow()</code> or any function on <code>next</code> . The compiler complains that <code>next</code> is an ambiguous integer type.</p>
  <p>Sure, I can fix this by either explicitly declaring the array as <code>i32[]</code>. Or I can also use an interim variable before <code>cumulator</code> which is also explicitly declared <code>i32</code>. But these seem unnecessary and a bit clunky.</p>
  <p>So why is compiler happy in the first case and not in the second?</p>