title: Error when a trait is used as a type but not when used as a bound in a where clause
body: <p>It seems that the Rust compiler has different behaviour on <code>where</code> clauses.</p>
  <pre><code>mod sub {
      use std::mem;
  
      static mut FF : *const Foo = &amp;NopFoo;
  
      pub trait Foo: Send + Sync {
          fn foo(&amp;self);
      }
  
      pub struct NopFoo;
  
      impl Foo for NopFoo {
          fn foo(&amp;self) { println!(&quot;Nop&quot;); }
      }
  
      pub struct HelloFoo {
          pub num: i64,
      }
  
      impl Foo for HelloFoo {
          fn foo(&amp;self) { println!(&quot;Hello, {}&quot;, self.num ); }
      }
  
      pub fn set_ff&lt;M&gt;(make_foo: M) -&gt; bool
          where M: FnOnce() -&gt; Box&lt;Foo&gt; // &lt;== Here
      {
          unsafe {
              FF = mem::transmute(make_foo());
          }
          false
      }
  
      pub fn get_ff() -&gt; Option&lt;&amp;'static Foo&gt; {
          Some(unsafe { &amp;*FF })
      }
  }
  
  fn main() {
      sub::get_ff().unwrap().foo();
  
      let f = sub::HelloFoo{num: 42};
      sub::set_ff(|| Box::new(f));
  
      sub::get_ff().unwrap().foo();
  }
  </code></pre>
  <p>(<a href="https://play.rust-lang.org/?gist=0ad2281fb636d62a50441203681c63d0&amp;version=nightly&amp;backtrace=1" rel="nofollow noreferrer">Playground</a>)</p>
  <p>With a <code>where</code> clause it works fine, prints:</p>
  <pre class="lang-none prettyprint-override"><code>Nop
  Hello, 42
  </code></pre>
  <hr />
  <p>If I remove the <code>where</code> clause from <code>sub::set_ff()</code> the Rust compiler reports errors <code>E0277</code> and <code>E0308</code>:</p>
  <pre><code>mod sub {
      use std::mem;
  
      static mut FF : *const Foo = &amp;NopFoo;
  
      pub trait Foo: Send + Sync {
          fn foo(&amp;self);
      }
  
      pub struct NopFoo;
  
      impl Foo for NopFoo {
          fn foo(&amp;self) { println!(&quot;Nop&quot;); }
      }
  
      pub struct HelloFoo {
          pub num: i64,
      }
  
      impl Foo for HelloFoo {
          fn foo(&amp;self) { println!(&quot;Hello, {}&quot;, self.num ); }
      }
  
      pub fn set_ff(make_foo: Box&lt;Foo&gt;) -&gt; bool  // &lt;== Here
      {
          unsafe {
              FF = mem::transmute(make_foo());
          }
          false
      }
  
      pub fn get_ff() -&gt; Option&lt;&amp;'static Foo&gt; {
          Some(unsafe { &amp;*FF })
      }
  }
  
  fn main() {
      sub::get_ff().unwrap().foo();
  
      let f = sub::HelloFoo{num: 42};
      sub::set_ff(|| Box::new(f));
  
      sub::get_ff().unwrap().foo();
  }
  </code></pre>
  <p>(<a href="https://play.rust-lang.org/?gist=8c94e5103a222e845cda2e5de23630de&amp;version=nightly&amp;backtrace=1" rel="nofollow noreferrer">Playground</a>)</p>
  <p>I thought it should work fine, but the compiler reports an error instead:</p>
  <pre class="lang-none prettyprint-override"><code>error: the trait bound `std::ops::FnOnce() -&gt; Box&lt;sub::Foo + 'static&gt; + 'static: std::marker::Sized` is not satisfied [--explain E0277]
    --&gt; &lt;anon&gt;:24:19
  24 |&gt;     pub fn set_ff(make_foo: FnOnce() -&gt; Box&lt;Foo&gt;) -&gt; bool
     |&gt;                   ^^^^^^^^
  note: `std::ops::FnOnce() -&gt; Box&lt;sub::Foo + 'static&gt; + 'static` does not have a constant size known at compile-time
  note: all local variables must have a statically known size
  
  error: mismatched types [--explain E0308]
    --&gt; &lt;anon&gt;:41:17
  41 |&gt;     sub::set_ff(|| Box::new(f));
     |&gt;                 ^^^^^^^^^^^^^^ expected trait std::ops::FnOnce, found closure
  note: expected type `std::ops::FnOnce() -&gt; Box&lt;sub::Foo + 'static&gt; + 'static`
  note:    found type `[closure@&lt;anon&gt;:41:17: 41:31 f:_]`
  </code></pre>
  <p>Why does the Rust complier require <code>'static</code> and <code>Sized</code> in the second one and why does the first one work?</p>
  <p>My OS and Rust versions:</p>
  <pre class="lang-none prettyprint-override"><code>➜  ~ uname -a
  Linux laptop 4.2.0-35-generic #40~14.04.1-Ubuntu SMP Fri Mar 18 16:37:35 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
  ➜  ~ rustc --version
  rustc 1.10.0-nightly (9c6904ca1 2016-05-18)
  </code></pre>