<p dir="auto">See <a href="http://is.gd/0FO78Z" rel="nofollow">http://is.gd/0FO78Z</a></p>
<p dir="auto">Code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="pub type TypeWithLifetime&lt;'a&gt; = Box&lt;Fn() -&gt; () + 'a&gt;;

static static_closure : TypeWithLifetime&lt;'static&gt; = Box::new(|| {
    panic!()
});

fn main() {}"><pre class="notranslate"><code class="notranslate">pub type TypeWithLifetime&lt;'a&gt; = Box&lt;Fn() -&gt; () + 'a&gt;;

static static_closure : TypeWithLifetime&lt;'static&gt; = Box::new(|| {
    panic!()
});

fn main() {}
</code></pre></div>
<p dir="auto">Error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="6:3 error: function calls in statics are limited to struct and enum constructors [E0015]
&lt;anon&gt;:4 static static_closure : TypeWithLifetime&lt;'static&gt; = Box::new(|| {
&lt;anon&gt;:5     panic!()
&lt;anon&gt;:6 });
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace"><pre class="notranslate"><code class="notranslate">6:3 error: function calls in statics are limited to struct and enum constructors [E0015]
&lt;anon&gt;:4 static static_closure : TypeWithLifetime&lt;'static&gt; = Box::new(|| {
&lt;anon&gt;:5     panic!()
&lt;anon&gt;:6 });
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
</code></pre></div>
<p dir="auto">Our <code class="notranslate">sort_by</code> method takes a closure to do the comparison. This closure can fail arbitrarily, and the sort routine is implemented unsafely. These two things usually mean that failure will leave the world in an inconsistent state.</p>
<p dir="auto">Add a test that fails in the middle of sorting some heap objects and make sure it doesn't crash or leak.</p>
<p dir="auto">Here's the questionable line: <a href="https://github.com/mozilla/rust/blob/master/src/libstd/slice.rs#L539">https://github.com/mozilla/rust/blob/master/src/libstd/slice.rs#L539</a></p>