title: Why does a &str not coerce to a &String when using Vec::contains?
body: <p>A friend asked me to explain the following quirk in Rust. I was unable to, hence this question:</p>
  
  <pre><code>fn main() {
      let l: Vec&lt;String&gt; = Vec::new();
      //let ret = l.contains(&amp;String::from(func())); // works
      let ret = l.contains(func());  // does not work
      println!("ret: {}", ret);
  }
  
  fn func() -&gt; &amp; 'static str {
      "hello"
  }
  </code></pre>
  
  <p><a href="https://play.rust-lang.org/?gist=de5aa44b610d166c2a55fb9f8910099a&amp;version=stable" rel="noreferrer">Example on the Rust Playground</a></p>
  
  <p>The compiler will complain like this:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0308]: mismatched types
   --&gt; src/main.rs:4:26
    |
  4 |     let ret = l.contains(func());  // does not work
    |                          ^^^^^^ expected struct `std::string::String`, found str
    |
    = note: expected type `&amp;std::string::String`
               found type `&amp;'static str`
  </code></pre>
  
  <p>In other words, <code>&amp;str</code> does not coerce with <code>&amp;String</code>.</p>
  
  <p>At first I thought it was to do with <code>'static</code>, however that is a red herring.</p>
  
  <p>The commented line fixes the example at the cost of an extra allocation.</p>
  
  <p>My questions:</p>
  
  <ul>
  <li>Why doesn't <code>&amp;str</code> coerce with <code>&amp;String</code>?</li>
  <li>Is there a way to make the call to <code>contains</code> work without the extra allocation?</li>
  </ul>