<p dir="auto">It doesn't appear to be possible to return a FnBox which accepts references:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#![feature(fnbox)]

use std::boxed::FnBox;

type Callback = Box&lt;FnBox(&amp;mut usize, &amp;usize)&gt;;

fn get_cb() -&gt; Callback {
    Box::new(|a, b| {})
}

fn main() { }"><pre class="notranslate"><span class="pl-c1">#!<span class="pl-kos">[</span>feature<span class="pl-kos">(</span>fnbox<span class="pl-kos">)</span><span class="pl-kos">]</span></span>

<span class="pl-k">use</span> std<span class="pl-kos">::</span>boxed<span class="pl-kos">::</span><span class="pl-v">FnBox</span><span class="pl-kos">;</span>

<span class="pl-k">type</span> <span class="pl-smi">Callback</span> = <span class="pl-smi">Box</span><span class="pl-kos">&lt;</span><span class="pl-smi">FnBox</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-k">mut</span> <span class="pl-smi">usize</span><span class="pl-kos">,</span> <span class="pl-c1">&amp;</span><span class="pl-smi">usize</span><span class="pl-kos">)</span><span class="pl-kos">&gt;</span><span class="pl-kos">;</span>

<span class="pl-k">fn</span> <span class="pl-en">get_cb</span><span class="pl-kos">(</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">Callback</span> <span class="pl-kos">{</span>
    <span class="pl-smi">Box</span><span class="pl-kos">::</span><span class="pl-en">new</span><span class="pl-kos">(</span>|a<span class="pl-kos">,</span> b| <span class="pl-kos">{</span><span class="pl-kos">}</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span>

<span class="pl-k">fn</span> <span class="pl-en">main</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-kos">}</span></pre></div>
<p dir="auto">produces the following error on <code class="notranslate">rustc 1.4.0-nightly (cd138dc44 2015-09-02)</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;anon&gt;:8:5: 10:7 error: type mismatch resolving `for&lt;'r, 'r&gt; &lt;[closure@&lt;anon&gt;:8:14: 10:6] as alloc::boxed::FnBox&lt;(&amp;'r mut usize, &amp;'r usize)&gt;&gt;::Output == ()`:
 expected bound lifetime parameter ,
    found concrete lifetime [E0271]
&lt;anon&gt;: 8     Box::new(|a, b| {
&lt;anon&gt;: 9         
&lt;anon&gt;:10     })
&lt;anon&gt;:8:5: 10:7 help: see the detailed explanation for E0271
&lt;anon&gt;:8:5: 10:7 note: required for the cast to the object type `for&lt;'r, 'r&gt; alloc::boxed::FnBox&lt;(&amp;'r mut usize, &amp;'r usize), Output=()&gt; + 'static`
&lt;anon&gt;: 8     Box::new(|a, b| {
&lt;anon&gt;: 9         
&lt;anon&gt;:10     })
&lt;anon&gt;:8:5: 10:7 error: type mismatch: the type `[closure@&lt;anon&gt;:8:14: 10:6]` implements the trait `core::ops::FnOnce&lt;(_, _)&gt;`, but the trait `for&lt;'r, 'r&gt; core::ops::FnOnce&lt;(&amp;'r mut usize, &amp;'r usize)&gt;` is required (expected concrete lifetime, found bound lifetime parameter ) [E0281]
&lt;anon&gt;: 8     Box::new(|a, b| {
&lt;anon&gt;: 9         
&lt;anon&gt;:10     })
&lt;anon&gt;:8:5: 10:7 help: see the detailed explanation for E0281
&lt;anon&gt;:8:5: 10:7 note: required for the cast to the object type `for&lt;'r, 'r&gt; alloc::boxed::FnBox&lt;(&amp;'r mut usize, &amp;'r usize), Output=()&gt; + 'static`
&lt;anon&gt;: 8     Box::new(|a, b| {
&lt;anon&gt;: 9         
&lt;anon&gt;:10     })
error: aborting due to 2 previous errors"><pre class="notranslate"><code class="notranslate">&lt;anon&gt;:8:5: 10:7 error: type mismatch resolving `for&lt;'r, 'r&gt; &lt;[closure@&lt;anon&gt;:8:14: 10:6] as alloc::boxed::FnBox&lt;(&amp;'r mut usize, &amp;'r usize)&gt;&gt;::Output == ()`:
 expected bound lifetime parameter ,
    found concrete lifetime [E0271]
&lt;anon&gt;: 8     Box::new(|a, b| {
&lt;anon&gt;: 9         
&lt;anon&gt;:10     })
&lt;anon&gt;:8:5: 10:7 help: see the detailed explanation for E0271
&lt;anon&gt;:8:5: 10:7 note: required for the cast to the object type `for&lt;'r, 'r&gt; alloc::boxed::FnBox&lt;(&amp;'r mut usize, &amp;'r usize), Output=()&gt; + 'static`
&lt;anon&gt;: 8     Box::new(|a, b| {
&lt;anon&gt;: 9         
&lt;anon&gt;:10     })
&lt;anon&gt;:8:5: 10:7 error: type mismatch: the type `[closure@&lt;anon&gt;:8:14: 10:6]` implements the trait `core::ops::FnOnce&lt;(_, _)&gt;`, but the trait `for&lt;'r, 'r&gt; core::ops::FnOnce&lt;(&amp;'r mut usize, &amp;'r usize)&gt;` is required (expected concrete lifetime, found bound lifetime parameter ) [E0281]
&lt;anon&gt;: 8     Box::new(|a, b| {
&lt;anon&gt;: 9         
&lt;anon&gt;:10     })
&lt;anon&gt;:8:5: 10:7 help: see the detailed explanation for E0281
&lt;anon&gt;:8:5: 10:7 note: required for the cast to the object type `for&lt;'r, 'r&gt; alloc::boxed::FnBox&lt;(&amp;'r mut usize, &amp;'r usize), Output=()&gt; + 'static`
&lt;anon&gt;: 8     Box::new(|a, b| {
&lt;anon&gt;: 9         
&lt;anon&gt;:10     })
error: aborting due to 2 previous errors
</code></pre></div>
<p dir="auto"><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="78461986" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/25647" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/25647/hovercard" href="https://github.com/rust-lang/rust/issues/25647">#25647</a> is a similar bug when <em>calling</em> FnBox.</p>
<p dir="auto">In the code below, type inference works in the first line of <code class="notranslate">main()</code>, but fails in the second one. Note also that the "kind" of the closure has to be given with explicit syntax when inside <code class="notranslate">Box::new()</code>.</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="fn do_async&lt;F&gt;(_cb: Box&lt;F&gt;) where F: FnOnce(&amp;i32) {
}

fn do_async_unboxed&lt;F&gt;(cb: F) where F: FnOnce(&amp;i32) {
    do_async(Box::new(cb))
}

fn main() {
    do_async_unboxed(|x| { println!(&quot;{}&quot;, *x); });
    do_async(Box::new(|: x| { println!(&quot;{}&quot;, *x); }));
}"><pre class="notranslate"><span class="pl-k">fn</span> <span class="pl-en">do_async</span><span class="pl-kos">&lt;</span><span class="pl-smi">F</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span><span class="pl-s1">_cb</span><span class="pl-kos">:</span> <span class="pl-smi">Box</span><span class="pl-kos">&lt;</span><span class="pl-smi">F</span><span class="pl-kos">&gt;</span><span class="pl-kos">)</span> <span class="pl-k">where</span> <span class="pl-smi">F</span><span class="pl-kos">:</span> <span class="pl-smi">FnOnce</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-smi">i32</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
<span class="pl-kos">}</span>

<span class="pl-k">fn</span> <span class="pl-en">do_async_unboxed</span><span class="pl-kos">&lt;</span><span class="pl-smi">F</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span><span class="pl-s1">cb</span><span class="pl-kos">:</span> <span class="pl-smi">F</span><span class="pl-kos">)</span> <span class="pl-k">where</span> <span class="pl-smi">F</span><span class="pl-kos">:</span> <span class="pl-smi">FnOnce</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-smi">i32</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-en">do_async</span><span class="pl-kos">(</span><span class="pl-smi">Box</span><span class="pl-kos">::</span><span class="pl-en">new</span><span class="pl-kos">(</span>cb<span class="pl-kos">)</span><span class="pl-kos">)</span>
<span class="pl-kos">}</span>

<span class="pl-k">fn</span> <span class="pl-en">main</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-en">do_async_unboxed</span><span class="pl-kos">(</span>|x| <span class="pl-kos">{</span> <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"{}"</span>, *x<span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-en">do_async</span><span class="pl-kos">(</span><span class="pl-smi">Box</span><span class="pl-kos">::</span><span class="pl-en">new</span><span class="pl-kos">(</span>|<span class="pl-kos">:</span> x| <span class="pl-kos">{</span> <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"{}"</span>, *x<span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>