<p dir="auto">This code:</p>
<pre class="notranslate">enum Command {
    Create{qname:~str},
    Help,
    Unknown,
}

fn main() {
    let val = Unknown;

    match val{
        Create{qname: qname} =&gt; {
            print(fmt!("Create %?", qname));
        }
        Help =&gt; {
            print(~"Help");
        }
        _ =&gt; {
            print(~"Other");
        }
    }
}
</pre>
<p dir="auto">Gives segmentation fault in runtime.</p>
<p dir="auto">Running this <code class="notranslate">test.rs</code> causes a segfault on Ubuntu 12.10 (compiled with incoming <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/rust-lang/rust/commit/bda4dd3c911ba54e342de2ff1b59e371442e58dd/hovercard" href="https://github.com/rust-lang/rust/commit/bda4dd3c911ba54e342de2ff1b59e371442e58dd"><tt>bda4dd3</tt></a>):</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="enum Foo {
    Bar,
    Baz {a: uint}
}

impl Foo {
    fn equals(&amp;self, other: &amp;Foo) -&gt; bool {
        match *self {
            Bar =&gt; match *other { Bar =&gt; true, _ =&gt; false },
            Baz {a: ref sa} =&gt; match *other {
                Baz {a: ref oa} =&gt; sa == oa,
                _ =&gt; false
            }
        }
    }
}

pub fn main() {
    let x = Baz {a: 4};
    let y = Bar;
    x.equals(&amp;y);
}"><pre class="notranslate"><span class="pl-k">enum</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
    <span class="pl-v">Bar</span><span class="pl-kos">,</span>
    <span class="pl-v">Baz</span> <span class="pl-kos">{</span><span class="pl-c1">a</span><span class="pl-kos">:</span> <span class="pl-smi">uint</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-kos">{</span>
    <span class="pl-k">fn</span> <span class="pl-en">equals</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-smi">self</span><span class="pl-kos">,</span> <span class="pl-s1">other</span><span class="pl-kos">:</span> <span class="pl-c1">&amp;</span><span class="pl-smi">Foo</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">bool</span> <span class="pl-kos">{</span>
        <span class="pl-k">match</span> <span class="pl-c1">*</span><span class="pl-smi">self</span> <span class="pl-kos">{</span>
            <span class="pl-v">Bar</span> =&gt; <span class="pl-k">match</span> <span class="pl-c1">*</span>other <span class="pl-kos">{</span> <span class="pl-v">Bar</span> =&gt; <span class="pl-c1">true</span><span class="pl-kos">,</span> _ =&gt; <span class="pl-c1">false</span> <span class="pl-kos">}</span><span class="pl-kos">,</span>
            <span class="pl-smi">Baz</span> <span class="pl-kos">{</span><span class="pl-c1">a</span><span class="pl-kos">:</span> <span class="pl-k">ref</span> sa<span class="pl-kos">}</span> =&gt; <span class="pl-k">match</span> <span class="pl-c1">*</span>other <span class="pl-kos">{</span>
                <span class="pl-smi">Baz</span> <span class="pl-kos">{</span><span class="pl-c1">a</span><span class="pl-kos">:</span> <span class="pl-k">ref</span> oa<span class="pl-kos">}</span> =&gt; sa == oa<span class="pl-kos">,</span>
                _ =&gt; <span class="pl-c1">false</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">let</span> x = <span class="pl-smi">Baz</span> <span class="pl-kos">{</span><span class="pl-c1">a</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-k">let</span> y = <span class="pl-v">Bar</span><span class="pl-kos">;</span>
    x<span class="pl-kos">.</span><span class="pl-en">equals</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span>y<span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Valgrind says this about it:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="==16637== Thread 2:
==16637== Use of uninitialised value of size 8
==16637==    at 0x400AE8: uint::__extensions__::meth_2509::eq::_693b4a7b2ad824e5::_00 (test.rs:1)
==16637==    by 0x400A9D: ptr::__extensions__::eq_2502::_37b8589111841e1::_00 (test.rs:1)
==16637==    by 0x400A3B: __extensions__::meth_2459::equals::_e3a12daf95a36916::_00 (test.rs:11)
==16637==    by 0x400B68: main::_6706ae2286769fe::_00 (test.rs:21)
==16637==    by 0x400B9D: _rust_main (test.rs:12)
==16637==    by 0x535E4C3: task_start_wrapper(spawn_args*) (rust_task.cpp:162)
==16637== 
==16637== Invalid read of size 8
==16637==    at 0x400AE8: uint::__extensions__::meth_2509::eq::_693b4a7b2ad824e5::_00 (test.rs:1)
==16637==    by 0x400A9D: ptr::__extensions__::eq_2502::_37b8589111841e1::_00 (test.rs:1)
==16637==    by 0x400A3B: __extensions__::meth_2459::equals::_e3a12daf95a36916::_00 (test.rs:11)
==16637==    by 0x400B68: main::_6706ae2286769fe::_00 (test.rs:21)
==16637==    by 0x400B9D: _rust_main (test.rs:12)
==16637==    by 0x535E4C3: task_start_wrapper(spawn_args*) (rust_task.cpp:162)
==16637==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==16637== 
==16637== 
==16637== Process terminating with default action of signal 11 (SIGSEGV)
==16637==  Access not within mapped region at address 0x0
==16637==    at 0x400AE8: uint::__extensions__::meth_2509::eq::_693b4a7b2ad824e5::_00 (test.rs:1)
==16637==    by 0x400A9D: ptr::__extensions__::eq_2502::_37b8589111841e1::_00 (test.rs:1)
==16637==    by 0x400A3B: __extensions__::meth_2459::equals::_e3a12daf95a36916::_00 (test.rs:11)
==16637==    by 0x400B68: main::_6706ae2286769fe::_00 (test.rs:21)
==16637==    by 0x400B9D: _rust_main (test.rs:12)
==16637==    by 0x535E4C3: task_start_wrapper(spawn_args*) (rust_task.cpp:162)"><pre class="notranslate"><code class="notranslate">==16637== Thread 2:
==16637== Use of uninitialised value of size 8
==16637==    at 0x400AE8: uint::__extensions__::meth_2509::eq::_693b4a7b2ad824e5::_00 (test.rs:1)
==16637==    by 0x400A9D: ptr::__extensions__::eq_2502::_37b8589111841e1::_00 (test.rs:1)
==16637==    by 0x400A3B: __extensions__::meth_2459::equals::_e3a12daf95a36916::_00 (test.rs:11)
==16637==    by 0x400B68: main::_6706ae2286769fe::_00 (test.rs:21)
==16637==    by 0x400B9D: _rust_main (test.rs:12)
==16637==    by 0x535E4C3: task_start_wrapper(spawn_args*) (rust_task.cpp:162)
==16637== 
==16637== Invalid read of size 8
==16637==    at 0x400AE8: uint::__extensions__::meth_2509::eq::_693b4a7b2ad824e5::_00 (test.rs:1)
==16637==    by 0x400A9D: ptr::__extensions__::eq_2502::_37b8589111841e1::_00 (test.rs:1)
==16637==    by 0x400A3B: __extensions__::meth_2459::equals::_e3a12daf95a36916::_00 (test.rs:11)
==16637==    by 0x400B68: main::_6706ae2286769fe::_00 (test.rs:21)
==16637==    by 0x400B9D: _rust_main (test.rs:12)
==16637==    by 0x535E4C3: task_start_wrapper(spawn_args*) (rust_task.cpp:162)
==16637==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==16637== 
==16637== 
==16637== Process terminating with default action of signal 11 (SIGSEGV)
==16637==  Access not within mapped region at address 0x0
==16637==    at 0x400AE8: uint::__extensions__::meth_2509::eq::_693b4a7b2ad824e5::_00 (test.rs:1)
==16637==    by 0x400A9D: ptr::__extensions__::eq_2502::_37b8589111841e1::_00 (test.rs:1)
==16637==    by 0x400A3B: __extensions__::meth_2459::equals::_e3a12daf95a36916::_00 (test.rs:11)
==16637==    by 0x400B68: main::_6706ae2286769fe::_00 (test.rs:21)
==16637==    by 0x400B9D: _rust_main (test.rs:12)
==16637==    by 0x535E4C3: task_start_wrapper(spawn_args*) (rust_task.cpp:162)
</code></pre></div>
<p dir="auto">Note that the following variants of the last line of <code class="notranslate">main</code> do <em>not</em> cause a segfault:</p>
<ul dir="auto">
<li><code class="notranslate">x.equals(&amp;x);</code></li>
<li><code class="notranslate">y.equals(&amp;y);</code></li>
<li><code class="notranslate">y.equals(&amp;x);</code></li>
</ul>