title: Understanding Traits and Object Safety
body: <p>I am struggling with the basics of object safety. If I have this code</p>
  <pre class="lang-rust prettyprint-override"><code>struct S {
      x: i32,
  }
  
  trait Trait: Sized {
      fn f(&amp;self) -&gt; i32
      where
          Self: Sized;
  }
  
  fn object_safety_dynamic(x: Trait) {}
  </code></pre>
  <p>I receive</p>
  <pre class="lang-none prettyprint-override"><code>error[E0038]: the trait `Trait` cannot be made into an object
    --&gt; src/lib.rs:11:29
     |
  5  | trait Trait: Sized {
     |       -----  ----- ...because it requires `Self: Sized`
     |       |
     |       this trait cannot be made into an object...
  ...
  11 | fn object_safety_dynamic(x: Trait) {}
     |                             ^^^^^ the trait `Trait` cannot be made into an object
  </code></pre>
  <p>When I add or remove <code>: Sized</code> as the supertrait or as <code>f</code>'s bound, I receive slightly different error messages.</p>
  <p>Could someone explain:</p>
  <ul>
  <li><p>Why does this particular example not work? The chapter <a href="https://doc.rust-lang.org/1.30.0/book/first-edition/trait-objects.html" rel="nofollow noreferrer">Trait Objects</a> states:</p>
  <blockquote>
  <p>So what makes a method object-safe? Each method must require that <code>Self: Sized</code></p>
  </blockquote>
  <p>Isn't that fulfilled?</p>
  </li>
  <li><p>What is the difference between <code>Trait: Sized</code> and <code>where Self: Sized</code>? (Well, yes, one inherits the trait and the other one is a parameter bound, but from Rust's trait object perspective?</p>
  </li>
  <li><p>What is the <em>preferred</em> change I had to make <code>object_safety_dynamic</code> work?</p>
  </li>
  </ul>
  <p>I am using <code>rustc 1.19.0-nightly (01951a61a 2017-05-20)</code> if it matters.</p>
  <p>Addressing the comment on fixed sizes.</p>
  <pre class="lang-rust prettyprint-override"><code>trait TraitB {
      fn f(&amp;self) -&gt; i32
      where
          Self: Sized;
  
      fn g&lt;T&gt;(&amp;self, t: T) -&gt; i32
      where
          Self: Sized;
  }
  </code></pre>