title: Returning a future-generating closure from a function
body: <p>When checking the following code:</p>
  <pre class="lang-rs prettyprint-override"><code>pub fn producer&lt;F&gt;() -&gt; impl Fn() -&gt; F
  where
      F: std::future::Future&lt;Output = ()&gt;,
  {
      || async move {
          println!(&quot;Hello, World!&quot;);
      }
  }
  </code></pre>
  <p>I get following compiler error:</p>
  <pre><code>error[E0308]: mismatched types
    --&gt; src/lib.rs:5:8
     |
  1  |   pub fn producer&lt;F&gt;() -&gt; impl Fn() -&gt; F
     |                   - this type parameter
  ...
  5  |       || async move {
     |  ________^
  6  | |         println!(&quot;Hello, World!&quot;);
  7  | |     }
     | |_____^ expected type parameter `F`, found opaque type
     | 
    ::: /Users/tf/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/mod.rs:61:43
     |
  61 |   pub const fn from_generator&lt;T&gt;(gen: T) -&gt; impl Future&lt;Output = T::Return&gt;
     |                                             ------------------------------- the found opaque type
     |
     = note: expected type parameter `F`
                   found opaque type `impl Future`
     = help: type parameters must be constrained to match other types
     = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
  
  For more information about this error, try `rustc --explain E0308`.
  </code></pre>
  <p>However, the future should eventually resolve to unit. I have seen multiple error messages, basically all related to type mismatches, while I am suspecting something a like a missing <code>Sized</code> marker. But then again boxing the closure didn't help either.</p>
  <p>The usual questions:</p>
  <ol>
  <li>What keeps the compiler from accepting my closure as the proper type?</li>
  <li>How can I fix it?</li>
  </ol>