title: Why does this closure argument need an explicit type?
body: <p>Consider the following working <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=85fa3c7dfb1f7cea5b40df9888e95d32" rel="nofollow noreferrer">code</a>:</p>
  
  <pre class="lang-rust prettyprint-override"><code>fn f() {
      let xs = vec![(0, 0)];
      let f = |j| xs[j];
      let y = f(0usize);
  }
  </code></pre>
  
  <p>The following <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=a2059bc39f19ead1e093597858bc7476" rel="nofollow noreferrer">variation</a> does not compile:</p>
  
  <pre class="lang-rust prettyprint-override"><code>fn f() {
      let xs = vec![(0, 0)];
      let f = |j| xs[j].0;
      let y = f(0usize);
  }
  </code></pre>
  
  <p>It fails as follows:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0282]: type annotations needed
   --&gt; src/lib.rs:3:17
    |
  3 |     let f = |j| xs[j].0;
    |                 ^^^^^ cannot infer type
    |
    = note: type must be known at this point
  </code></pre>
  
  <p>To fix it, one must annotate <code>j</code>:</p>
  
  <pre class="lang-rust prettyprint-override"><code>fn f() {
      let xs = vec![(0, 0)];
      let f = |j: usize| xs[j].0;
      let y = f(0usize);
  }
  </code></pre>
  
  <p>The <a href="https://doc.rust-lang.org/book/ch13-01-closures.html#closure-type-inference-and-annotation" rel="nofollow noreferrer">Rust book</a> says:</p>
  
  <blockquote>
    <p>Closures don’t require you to annotate the types of the parameters or
    the return value like fn functions do.</p>
  </blockquote>
  
  <p>Why must <code>j</code> be explicitly typed?</p>