<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>
<p dir="auto">Spawned off of <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="52544157" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/20055" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/20055/hovercard" href="https://github.com/rust-lang/rust/issues/20055">#20055</a> (and PR <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="55647725" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/21692" data-hovercard-type="pull_request" data-hovercard-url="/rust-lang/rust/pull/21692/hovercard" href="https://github.com/rust-lang/rust/pull/21692">#21692</a> )</p>
<p dir="auto">I thought I fixed this and wrote a test for it in PR <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="55647725" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/21692" data-hovercard-type="pull_request" data-hovercard-url="/rust-lang/rust/pull/21692/hovercard" href="https://github.com/rust-lang/rust/pull/21692">#21692</a>, but I was wrong -- the test for <code class="notranslate">Box&lt;Trait&gt;</code> was erroneous/incomplete at best.</p>
<p dir="auto">Test case:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="trait Boo { }

impl Boo for [i8; 1] { }
impl Boo for [i8; 2] { }
impl Boo for [i8; 3] { }
impl Boo for [i8; 4] { }

pub fn foo(box_1: fn () -&gt; Box&lt;[i8; 1]&gt;,
           box_2: fn () -&gt; Box&lt;[i8; 2]&gt;,
           box_3: fn () -&gt; Box&lt;[i8; 3]&gt;,
           box_4: fn () -&gt; Box&lt;[i8; 4]&gt;,
            ) {
    let _b: Box&lt;Boo&gt; = match 3 {
        1 =&gt; box_1(),
        2 =&gt; box_2(),
        3 =&gt; box_3(),
        _ =&gt; box_4(),
    };
}

pub fn main() {
    fn box_1() -&gt; Box&lt;[i8; 1]&gt; { Box::new( [1i8; 1] ) }
    fn box_2() -&gt; Box&lt;[i8; 2]&gt; { Box::new( [1i8; 2] ) }
    fn box_3() -&gt; Box&lt;[i8; 3]&gt; { Box::new( [1i8; 3] ) }
    fn box_4() -&gt; Box&lt;[i8; 4]&gt; { Box::new( [1i8; 4] ) }

    println!(&quot;Hello World 1&quot;);
    foo(box_1, box_2, box_3, box_4);
    println!(&quot;Hello World 2&quot;);

}"><pre class="notranslate"><span class="pl-k">trait</span> <span class="pl-smi">Boo</span> <span class="pl-kos">{</span> <span class="pl-kos">}</span>

<span class="pl-k">impl</span> <span class="pl-smi">Boo</span> <span class="pl-k">for</span> <span class="pl-kos">[</span><span class="pl-smi">i8</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-kos">}</span>
<span class="pl-k">impl</span> <span class="pl-smi">Boo</span> <span class="pl-k">for</span> <span class="pl-kos">[</span><span class="pl-smi">i8</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-kos">}</span>
<span class="pl-k">impl</span> <span class="pl-smi">Boo</span> <span class="pl-k">for</span> <span class="pl-kos">[</span><span class="pl-smi">i8</span><span class="pl-kos">;</span> <span class="pl-c1">3</span><span class="pl-kos">]</span> <span class="pl-kos">{</span> <span class="pl-kos">}</span>
<span class="pl-k">impl</span> <span class="pl-smi">Boo</span> <span class="pl-k">for</span> <span class="pl-kos">[</span><span class="pl-smi">i8</span><span class="pl-kos">;</span> <span class="pl-c1">4</span><span class="pl-kos">]</span> <span class="pl-kos">{</span> <span class="pl-kos">}</span>

<span class="pl-k">pub</span> <span class="pl-k">fn</span> <span class="pl-en">foo</span><span class="pl-kos">(</span><span class="pl-s1">box_1</span><span class="pl-kos">:</span> <span class="pl-k">fn</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">Box</span><span class="pl-kos">&lt;</span><span class="pl-kos">[</span><span class="pl-smi">i8</span><span class="pl-kos">;</span> <span class="pl-c1">1</span><span class="pl-kos">]</span><span class="pl-kos">&gt;</span><span class="pl-kos">,</span>
           <span class="pl-s1">box_2</span><span class="pl-kos">:</span> <span class="pl-k">fn</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">Box</span><span class="pl-kos">&lt;</span><span class="pl-kos">[</span><span class="pl-smi">i8</span><span class="pl-kos">;</span> <span class="pl-c1">2</span><span class="pl-kos">]</span><span class="pl-kos">&gt;</span><span class="pl-kos">,</span>
           <span class="pl-s1">box_3</span><span class="pl-kos">:</span> <span class="pl-k">fn</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">Box</span><span class="pl-kos">&lt;</span><span class="pl-kos">[</span><span class="pl-smi">i8</span><span class="pl-kos">;</span> <span class="pl-c1">3</span><span class="pl-kos">]</span><span class="pl-kos">&gt;</span><span class="pl-kos">,</span>
           <span class="pl-s1">box_4</span><span class="pl-kos">:</span> <span class="pl-k">fn</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">Box</span><span class="pl-kos">&lt;</span><span class="pl-kos">[</span><span class="pl-smi">i8</span><span class="pl-kos">;</span> <span class="pl-c1">4</span><span class="pl-kos">]</span><span class="pl-kos">&gt;</span><span class="pl-kos">,</span>
            <span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">let</span> _b<span class="pl-kos">:</span> <span class="pl-smi">Box</span><span class="pl-kos">&lt;</span><span class="pl-smi">Boo</span><span class="pl-kos">&gt;</span> = <span class="pl-k">match</span> <span class="pl-c1">3</span> <span class="pl-kos">{</span>
        <span class="pl-c1">1</span> =&gt; <span class="pl-en">box_1</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
        <span class="pl-c1">2</span> =&gt; <span class="pl-en">box_2</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
        <span class="pl-c1">3</span> =&gt; <span class="pl-en">box_3</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
        _ =&gt; <span class="pl-en">box_4</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-k">pub</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">fn</span> <span class="pl-en">box_1</span><span class="pl-kos">(</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">Box</span><span class="pl-kos">&lt;</span><span class="pl-kos">[</span><span class="pl-smi">i8</span><span class="pl-kos">;</span> <span class="pl-c1">1</span><span class="pl-kos">]</span><span class="pl-kos">&gt;</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><span class="pl-c1">1i8</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-kos">}</span>
    <span class="pl-k">fn</span> <span class="pl-en">box_2</span><span class="pl-kos">(</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">Box</span><span class="pl-kos">&lt;</span><span class="pl-kos">[</span><span class="pl-smi">i8</span><span class="pl-kos">;</span> <span class="pl-c1">2</span><span class="pl-kos">]</span><span class="pl-kos">&gt;</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><span class="pl-c1">1i8</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-kos">}</span>
    <span class="pl-k">fn</span> <span class="pl-en">box_3</span><span class="pl-kos">(</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">Box</span><span class="pl-kos">&lt;</span><span class="pl-kos">[</span><span class="pl-smi">i8</span><span class="pl-kos">;</span> <span class="pl-c1">3</span><span class="pl-kos">]</span><span class="pl-kos">&gt;</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><span class="pl-c1">1i8</span><span class="pl-kos">;</span> <span class="pl-c1">3</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">box_4</span><span class="pl-kos">(</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">Box</span><span class="pl-kos">&lt;</span><span class="pl-kos">[</span><span class="pl-smi">i8</span><span class="pl-kos">;</span> <span class="pl-c1">4</span><span class="pl-kos">]</span><span class="pl-kos">&gt;</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><span class="pl-c1">1i8</span><span class="pl-kos">;</span> <span class="pl-c1">4</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">"Hello World 1"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-en">foo</span><span class="pl-kos">(</span>box_1<span class="pl-kos">,</span> box_2<span class="pl-kos">,</span> box_3<span class="pl-kos">,</span> box_4<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">"Hello World 2"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-kos">}</span></pre></div>
<p dir="auto">In the playpen, this currently prints:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Hello World 1
playpen: application terminated abnormally with signal 4 (Illegal instruction)"><pre class="notranslate"><code class="notranslate">Hello World 1
playpen: application terminated abnormally with signal 4 (Illegal instruction)
</code></pre></div>