title: Why does type inference not work well with reference types?
body: <p>I wrote a code similar to below:</p>
  
  <pre class="lang-rust prettyprint-override"><code>fn foo() {
      let x = &amp;1;
      let y = 2;
      let z: u32 = x * y + 42_u32;
  }
  </code></pre>
  
  <p>and I got an error:</p>
  
  <pre><code>error[E0277]: cannot add `u32` to `i32`
    --&gt; src/main.rs:11:24
     |
  11 |     let z: u32 = x * y + 42_u32;
     |                        ^ no implementation for `i32 + u32`
     |
     = help: the trait `std::ops::Add&lt;u32&gt;` is not implemented for `i32`
  </code></pre>
  
  <p>But when I dereference <code>x</code>, it just works fine.<br>
  During some experiments, the following codes were compiled too.</p>
  
  <pre class="lang-rust prettyprint-override"><code>let z: u32 = x + y * 42_u32;
  </code></pre>
  
  <pre class="lang-rust prettyprint-override"><code>let z: u32 = 42_u32 + x + y;
  </code></pre>
  
  <p>I wonder why Rust's type inference does this.<br>
  Is the order of type inference affected by the order of operations?<br>
  If so, why does it make type inference impossible in this situation?</p>