title: Lifetime mismatch when migrating a free function to a trait
body: <p>I implemented this small function which returns a reference to a value in a enum. This works fine:</p>
  
  <pre><code>pub enum Entry {
      COMMENT,
      NUM(Option&lt;String&gt;, f64),
      STR(Option&lt;String&gt;, String),
      VNUM(Option&lt;String&gt;, Vec&lt;f64&gt;),
      VSTR(Option&lt;String&gt;, Vec&lt;String&gt;),
  }
  
  pub fn get_value&lt;'b&gt;(k: &amp;str, entity: &amp;'b [Entry]) -&gt; Option&lt;&amp;'b str&gt; {
      entity
          .iter()
          .filter_map(|x| match x {
              &amp;Entry::STR(ref key, ref v) =&gt; if key.as_ref().unwrap().as_str() == k {
                  Some(v.as_str())
              } else {
                  None
              },
              _ =&gt; None,
          })
          .next()
  }
  fn main() {
      let v = vec![
          Entry::STR(Some("foo".to_string()), "bar".to_string()),
          Entry::NUM(Some("baz".to_string()), 1234f64),
      ];
      let x: Option&lt;&amp;str&gt; = get_value("foo", &amp;v);
  }
  </code></pre>
  
  <p>To imbue some polymorphism, I wanted to move this to a trait so that I can call it for different types</p>
  
  <pre><code>pub trait GetValue&lt;T&gt; {
      fn get_value&lt;'a&gt;(k: &amp;str, entity: &amp;'a [Entry]) -&gt; Option&lt;&amp;'a str&gt;;
  }
  
  impl&lt;'a&gt; GetValue&lt;&amp;'a str&gt; for &amp;'a [Entry] {
      fn get_value(k: &amp;str, entity: &amp;'a [Entry]) -&gt; Option&lt;&amp;'a str&gt; {
          entity
              .iter()
              .filter_map(|x| match x {
                  &amp;Entry::STR(ref key, ref v) =&gt; if key.as_ref().unwrap().as_str() == k {
                      Some(v.as_str())
                  } else {
                      None
                  },
                  _ =&gt; None,
              })
              .next()
      }
  }
  </code></pre>
  
  <p>but get the following errors despite not intentionally changing the lifetime specifications. What have I missed?</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0308]: method not compatible with trait
    --&gt; src/main.rs:14:5
     |
  14 |     fn get_value(k: &amp;str, entity: &amp;'a [Entry]) -&gt; Option&lt;&amp;'a str&gt; {
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
     |
     = note: expected type `fn(&amp;str, &amp;'a [Entry]) -&gt; std::option::Option&lt;&amp;'a str&gt;`
                found type `fn(&amp;str, &amp;'a [Entry]) -&gt; std::option::Option&lt;&amp;'a str&gt;`
  note: the lifetime 'a as defined on the method body at 14:5...
    --&gt; src/main.rs:14:5
     |
  14 |     fn get_value(k: &amp;str, entity: &amp;'a [Entry]) -&gt; Option&lt;&amp;'a str&gt; {
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  note: ...does not necessarily outlive the lifetime 'a as defined on the impl at 13:1
    --&gt; src/main.rs:13:1
     |
  13 | impl&lt;'a&gt; GetValue&lt;&amp;'a str&gt; for &amp;'a [Entry] {
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  
  error[E0308]: method not compatible with trait
    --&gt; src/main.rs:14:5
     |
  14 |     fn get_value(k: &amp;str, entity: &amp;'a [Entry]) -&gt; Option&lt;&amp;'a str&gt; {
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
     |
     = note: expected type `fn(&amp;str, &amp;'a [Entry]) -&gt; std::option::Option&lt;&amp;'a str&gt;`
                found type `fn(&amp;str, &amp;'a [Entry]) -&gt; std::option::Option&lt;&amp;'a str&gt;`
  note: the lifetime 'a as defined on the impl at 13:1...
    --&gt; src/main.rs:13:1
     |
  13 | impl&lt;'a&gt; GetValue&lt;&amp;'a str&gt; for &amp;'a [Entry] {
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  note: ...does not necessarily outlive the lifetime 'a as defined on the method body at 14:5
    --&gt; src/main.rs:14:5
     |
  14 |     fn get_value(k: &amp;str, entity: &amp;'a [Entry]) -&gt; Option&lt;&amp;'a str&gt; {
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  </code></pre>