<p dir="auto">We currently only check for object safety when coercing a concrete object to a trait object. We should prevent the programmer writing object types which are not object safe.</p>
<p dir="auto">The following definition compiles fine:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fn two&lt;V&gt;(f: &amp;mut FnMut(V) -&gt; V, v: V) -&gt; V {
    let temp = f(v);
    f(temp)
}"><pre class="notranslate"><code class="notranslate">fn two&lt;V&gt;(f: &amp;mut FnMut(V) -&gt; V, v: V) -&gt; V {
    let temp = f(v);
    f(temp)
}
</code></pre></div>
<p dir="auto">whereas the more direct version does not:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fn two&lt;V&gt;(f: &amp;mut FnMut(V) -&gt; V, v: V) -&gt; V {
    f(f(v))
}"><pre class="notranslate"><code class="notranslate">fn two&lt;V&gt;(f: &amp;mut FnMut(V) -&gt; V, v: V) -&gt; V {
    f(f(v))
}
</code></pre></div>
<p dir="auto">The error we get here is:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="error: cannot borrow `*f` as mutable more than once at a time
         f(f(v))
           ^
note: previous borrow of `*f` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `*f` until the borrow ends
         f(f(v))
         ^
note: previous borrow ends here
         f(f(v))
               ^
error: cannot borrow `*f` as mutable more than once at a time
         f(f(v))
           ^
note: previous borrow of `*f` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `*f` until the borrow ends
         f(f(v))
         ^
note: previous borrow ends here
         f(f(v))
               ^"><pre class="notranslate"><code class="notranslate">error: cannot borrow `*f` as mutable more than once at a time
         f(f(v))
           ^
note: previous borrow of `*f` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `*f` until the borrow ends
         f(f(v))
         ^
note: previous borrow ends here
         f(f(v))
               ^
error: cannot borrow `*f` as mutable more than once at a time
         f(f(v))
           ^
note: previous borrow of `*f` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `*f` until the borrow ends
         f(f(v))
         ^
note: previous borrow ends here
         f(f(v))
               ^
</code></pre></div>
<p dir="auto">(The repetition is in the original.)</p>
<p dir="auto">If I'm reading the notes here correctly, it seems that a call like <code class="notranslate">closure(args...)</code> borrows <code class="notranslate">closure</code> before evaluating <code class="notranslate">args...</code>, so that <code class="notranslate">args...</code> itself is not allowed to refer to <code class="notranslate">closure</code>. Is it really necessary to borrow closure so early? Can't we give the borrow a scope that starts after the arguments have been evaluated?</p>
<p dir="auto">Using: rustc 1.2.0-nightly (<a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/rust-lang/rust/commit/d6c8028ce0eaf18abb67e4e2dafc5aae2e6e91de/hovercard" href="https://github.com/rust-lang/rust/commit/d6c8028ce0eaf18abb67e4e2dafc5aae2e6e91de"><tt>d6c8028</tt></a> 2015-06-09)</p>