title: Why can I compare a String to a &str using if, but not when using match?
body: <p>I'm trying to implement a function that reads command line arguments and compares them to hard-coded string literals.</p>
  
  <p>When I do the comparison with an <code>if</code> statement it works like a charm:</p>
  
  <pre><code>fn main() {
      let s = String::from("holla!");
  
      if s == "holla!" {
          println!("it worked!");
      }
  }
  </code></pre>
  
  <p>But using a <code>match</code> statement (which I guess would be more elegant):</p>
  
  <pre><code>fn main() {
      let s = String::from("holla!");
  
      match s {
          "holla!" =&gt; println!("it worked!"),
          _ =&gt; println!("nothing"),
      }
  }
  </code></pre>
  
  <p>I keep getting an error from the compiler that a <code>String</code> was expected but a <code>&amp;static str</code> was found:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0308]: mismatched types
   --&gt; src/main.rs:5:9
    |
  5 |         "holla!" =&gt; println!("it worked!"),
    |         ^^^^^^^^ expected struct `std::string::String`, found reference
    |
    = note: expected type `std::string::String`
               found type `&amp;'static str`
  </code></pre>
  
  <p>I've seen <a href="https://stackoverflow.com/q/25383488/155423">How to match a String against string literals in Rust?</a> so I know how to fix it, but I want to know <em>why</em> the comparison works when <code>if</code> but not using <code>match</code>.</p>