title: Why can a &str not be passed to a function accepting a &dyn Display trait object?
body: <p>I'm reading a Rust book and I am confused by this example:</p>
  
  <pre><code>use std::fmt::Display;
  
  fn main() {
      test("hello");
      test2("hello")
  }
  
  fn test(s: &amp;dyn Display) {
      println!("{}", s);
  }
  
  fn test2(s: &amp;str) {
      println!("{}", s);
  }
  </code></pre>
  
  <p>Passing <code>&amp;'static str</code> as a trait object fails:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0277]: the size for values of type `str` cannot be known at compilation time
   --&gt; src/main.rs:4:10
    |
  4 |     test("hello");
    |          ^^^^^^^ doesn't have a size known at compile-time
    |
    = help: the trait `std::marker::Sized` is not implemented for `str`
    = note: to learn more, visit &lt;https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait&gt;
    = note: required for the cast to the object type `dyn std::fmt::Display`
  </code></pre>
  
  <p>Why does this fail and the second call work?</p>