<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="trait Foo {}
impl Foo for () {}

#[cfg(not(good))]
fn foo(x: bool) -&gt; Box&lt;Foo+'static&gt; {
    match x {
        true =&gt; box() (),
        false =&gt; box() ()
    }
}
#[cfg(good)]
fn foo(x: bool) -&gt; Box&lt;Foo+'static&gt; {
    match x {
        true =&gt; box() () as Box&lt;Foo&gt;,
        false =&gt; box() () as Box&lt;Foo&gt;
    }
}

fn main() {
    foo(true);
    foo(false);
}"><pre class="notranslate"><span class="pl-k">trait</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>
<span class="pl-k">impl</span> <span class="pl-smi">Foo</span> <span class="pl-k">for</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>

<span class="pl-c1">#<span class="pl-kos">[</span>cfg<span class="pl-kos">(</span>not<span class="pl-kos">(</span>good<span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">]</span></span>
<span class="pl-k">fn</span> <span class="pl-en">foo</span><span class="pl-kos">(</span><span class="pl-s1">x</span><span class="pl-kos">:</span> <span class="pl-smi">bool</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">Box</span><span class="pl-kos">&lt;</span><span class="pl-smi">Foo</span>+<span class="pl-c1">'</span><span class="pl-ent">static</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">match</span> x <span class="pl-kos">{</span>
        <span class="pl-c1">true</span> =&gt; <span class="pl-en">box</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-c1">false</span> =&gt; <span class="pl-en">box</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>
<span class="pl-c1">#<span class="pl-kos">[</span>cfg<span class="pl-kos">(</span>good<span class="pl-kos">)</span><span class="pl-kos">]</span></span>
<span class="pl-k">fn</span> <span class="pl-en">foo</span><span class="pl-kos">(</span><span class="pl-s1">x</span><span class="pl-kos">:</span> <span class="pl-smi">bool</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">Box</span><span class="pl-kos">&lt;</span><span class="pl-smi">Foo</span>+<span class="pl-c1">'</span><span class="pl-ent">static</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">match</span> x <span class="pl-kos">{</span>
        <span class="pl-c1">true</span> =&gt; <span class="pl-en">box</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-k">as</span> <span class="pl-smi">Box</span><span class="pl-kos">&lt;</span><span class="pl-smi">Foo</span><span class="pl-kos">&gt;</span><span class="pl-kos">,</span>
        <span class="pl-c1">false</span> =&gt; <span class="pl-en">box</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-k">as</span> <span class="pl-smi">Box</span><span class="pl-kos">&lt;</span><span class="pl-smi">Foo</span><span class="pl-kos">&gt;</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">foo</span><span class="pl-kos">(</span><span class="pl-c1">true</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-en">foo</span><span class="pl-kos">(</span><span class="pl-c1">false</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Compiling with <code class="notranslate">--cfg good</code> (i.e. explicit casts) runs 100% fine, compiling without it (i.e. implicit coercions) segfaults/crashes. This also runs fine on 0.12 on the playpen, and with <code class="notranslate">if x {</code> instead of <code class="notranslate">match</code> .</p>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/nick29581/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/nick29581">@nick29581</a> (maybe?)</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="trait Thing {
    fn hello(&amp;self) -&gt; uint;
}

struct Thing1 { name: String }
impl Thing for Thing1 {
    fn hello(&amp;self) -&gt; uint { 1 }
}

struct Thing2 { name: String }
impl Thing for Thing2 {
    fn hello(&amp;self) -&gt; uint { 2 }
}

fn main() {
    let t: Box&lt;Thing&gt; = match true {
        true =&gt; box Thing1 { name: &quot;hello&quot;.to_string() },
        _    =&gt; box Thing2 { name: &quot;hello&quot;.to_string() },
    };
    println!(&quot;{}&quot;, t.hello());
}"><pre class="notranslate"><span class="pl-k">trait</span> <span class="pl-smi">Thing</span> <span class="pl-kos">{</span>
    <span class="pl-k">fn</span> <span class="pl-en">hello</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-smi">self</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">uint</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">struct</span> <span class="pl-smi">Thing1</span> <span class="pl-kos">{</span> <span class="pl-c1">name</span><span class="pl-kos">:</span> <span class="pl-smi">String</span> <span class="pl-kos">}</span>
<span class="pl-k">impl</span> <span class="pl-smi">Thing</span> <span class="pl-k">for</span> <span class="pl-smi">Thing1</span> <span class="pl-kos">{</span>
    <span class="pl-k">fn</span> <span class="pl-en">hello</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-smi">self</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">uint</span> <span class="pl-kos">{</span> <span class="pl-c1">1</span> <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-k">struct</span> <span class="pl-smi">Thing2</span> <span class="pl-kos">{</span> <span class="pl-c1">name</span><span class="pl-kos">:</span> <span class="pl-smi">String</span> <span class="pl-kos">}</span>
<span class="pl-k">impl</span> <span class="pl-smi">Thing</span> <span class="pl-k">for</span> <span class="pl-smi">Thing2</span> <span class="pl-kos">{</span>
    <span class="pl-k">fn</span> <span class="pl-en">hello</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-smi">self</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">uint</span> <span class="pl-kos">{</span> <span class="pl-c1">2</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-k">let</span> t<span class="pl-kos">:</span> <span class="pl-smi">Box</span><span class="pl-kos">&lt;</span><span class="pl-smi">Thing</span><span class="pl-kos">&gt;</span> = <span class="pl-k">match</span> <span class="pl-c1">true</span> <span class="pl-kos">{</span>
        <span class="pl-c1">true</span> =&gt; box <span class="pl-smi">Thing1</span> <span class="pl-kos">{</span> <span class="pl-c1">name</span><span class="pl-kos">:</span> <span class="pl-s">"hello"</span><span class="pl-kos">.</span><span class="pl-en">to_string</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">}</span><span class="pl-kos">,</span>
        _    =&gt; box <span class="pl-smi">Thing2</span> <span class="pl-kos">{</span> <span class="pl-c1">name</span><span class="pl-kos">:</span> <span class="pl-s">"hello"</span><span class="pl-kos">.</span><span class="pl-en">to_string</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>
    <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"{}"</span>, t.hello<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>
<p dir="auto">Running this code yields various failures (SIGSEGV, "Illegal instruction: 4"):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ rustc s.rs
# Warnings snipped
$ ./s
Illegal instruction: 4"><pre class="notranslate"><code class="notranslate">$ rustc s.rs
# Warnings snipped
$ ./s
Illegal instruction: 4
</code></pre></div>
<p dir="auto">LLDB has this to say:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="(lldb) bt
* thread #1: tid = 0x821935, 0x0000000100003358 s`Box$LT$Thing$GT$::glue_drop.1635::ha5cee14c6e595b4f + 72, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
  * frame #0: 0x0000000100003358 s`Box$LT$Thing$GT$::glue_drop.1635::ha5cee14c6e595b4f + 72
    frame #1: 0x00000001000011f8 s`main::hb72fec937d964a29Zaa + 680
    frame #2: 0x000000010000f2d9 s`rust_try_inner + 9
    frame #3: 0x000000010000f2c6 s`rust_try + 6
    frame #4: 0x000000010000e1df s`rt::lang_start::h270935babb5b337fRCz + 831
    frame #5: 0x00000001000013bf s`main + 79
    frame #6: 0x00007fff92d9b5c9 libdyld.dylib`start + 1"><pre class="notranslate"><code class="notranslate">(lldb) bt
* thread #1: tid = 0x821935, 0x0000000100003358 s`Box$LT$Thing$GT$::glue_drop.1635::ha5cee14c6e595b4f + 72, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
  * frame #0: 0x0000000100003358 s`Box$LT$Thing$GT$::glue_drop.1635::ha5cee14c6e595b4f + 72
    frame #1: 0x00000001000011f8 s`main::hb72fec937d964a29Zaa + 680
    frame #2: 0x000000010000f2d9 s`rust_try_inner + 9
    frame #3: 0x000000010000f2c6 s`rust_try + 6
    frame #4: 0x000000010000e1df s`rt::lang_start::h270935babb5b337fRCz + 831
    frame #5: 0x00000001000013bf s`main + 79
    frame #6: 0x00007fff92d9b5c9 libdyld.dylib`start + 1
</code></pre></div>
<p dir="auto">and I'm reasonably up-to-date:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ rustc --version=verbose
rustc 0.13.0-dev (1c2df5cc3 2014-12-20 01:12:19 +0000)
binary: rustc
commit-hash: 1c2df5cc3cfc0c9e80adf9fa6504d55056741c5a
commit-date: 2014-12-20 01:12:19 +0000
host: x86_64-apple-darwin
release: 0.13.0-dev"><pre class="notranslate"><code class="notranslate">$ rustc --version=verbose
rustc 0.13.0-dev (1c2df5cc3 2014-12-20 01:12:19 +0000)
binary: rustc
commit-hash: 1c2df5cc3cfc0c9e80adf9fa6504d55056741c5a
commit-date: 2014-12-20 01:12:19 +0000
host: x86_64-apple-darwin
release: 0.13.0-dev
</code></pre></div>