title: max_by_key on Map doesn't allow destructuring of tuple into key-value pair
body: <p>I am learning Rust and fairly good with concept of ownership, borrow, and references. I have reached Ch.8 of the second edition of the Rust Book. </p>
  
  <p>I'm implementing the <code>mode</code> function using <code>map</code> <a href="https://doc.rust-lang.org/book/second-edition/ch08-03-hash-maps.html#summary" rel="noreferrer" title="exercise here">as given in an exercise</a>. I wrote following implementation using <code>Iterator::max_by_key</code>:</p>
  
  <pre><code>use std::collections::HashMap;
  
  fn main() {
      let vs = vec![0, 0, 1, 1, 3, 4, 5, 6, 3, 3, 3];
  
      let mut counts = HashMap::new();
      for num in vs {
          let count = counts.entry(num).or_insert(0);
          *count += 1;
      }
  
      // This works
      let u = counts.iter().max_by_key(|v| v.1);
  
      // This doesn't work
      let v = counts.iter().max_by_key(|(k, v)| v);
  }
  </code></pre>
  
  <p>I get following compiler error</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0495]: cannot infer an appropriate lifetime for pattern due to conflicting requirements
    --&gt; src/main.rs:16:43
     |
  16 |     let v = counts.iter().max_by_key(|(k, v)| v);
     |                                           ^
     |
  note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the body at 16:38...
    --&gt; src/main.rs:16:38
     |
  16 |     let v = counts.iter().max_by_key(|(k, v)| v);
     |                                      ^^^^^^^^^^
  note: ...so that reference does not outlive borrowed content
    --&gt; src/main.rs:16:43
     |
  16 |     let v = counts.iter().max_by_key(|(k, v)| v);
     |                                           ^
  note: but, the lifetime must be valid for the method call at 16:13...
    --&gt; src/main.rs:16:13
     |
  16 |     let v = counts.iter().max_by_key(|(k, v)| v);
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  note: ...so that a type/lifetime parameter is in scope here
    --&gt; src/main.rs:16:13
     |
  16 |     let v = counts.iter().max_by_key(|(k, v)| v);
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  </code></pre>
  
  <p>What does this error mean and why this is not allowed?</p>
  
  <p><em>Update 1:</em> <a href="https://stackoverflow.com/questions/40277917">Match tuple as input to map</a> solves my problem. If I were using a stable compiler I wouldn't have asked this question. Here I got unintended compile errors, so I'm not closing this as duplicate.</p>