<p dir="auto">I've got a small Rust program, trying to implement a binary search tree.  With Rust 0.8, the compiler segfaults.  WIth GIT revision <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/rust-lang/rust/commit/8ea2123055dcbc1caa0bb07bc492516027b832b4/hovercard" href="https://github.com/rust-lang/rust/commit/8ea2123055dcbc1caa0bb07bc492516027b832b4"><tt>8ea2123</tt></a>, I get a nicer error-message, THEN a segfault.  Looks like some sort of infinite stack-recursion.</p>
<p dir="auto">I'm including the program.</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="extern mod extra ;
use std::rand;
use std::rand::Rng;
use std::vec ;
use std::str ;
use extra::sort ;

struct bstnode&lt;K, V&gt; {
    k : K,
    v : V,
    l : Option&lt; bstnode&lt;K, V&gt; &gt;,
    r : Option&lt; bstnode&lt;K, V&gt; &gt;
}

impl&lt;K : Clone + Eq + TotalOrd , V : Clone&gt; bstnode&lt;K, V&gt; {
    fn new(k: &amp;K, v: &amp;V) -&gt; bstnode&lt;K,V&gt; {
        bstnode { k: (*k).clone(), v: (*v).clone(), l: None, r: None }
    }
    fn dumbinsert(node: &amp;mut bstnode&lt;K, V&gt;, k : &amp;K, v : &amp;V) {
        if (node.k.cmp(k) == Equal) {
            node.v = v.clone() ;
        }
        else if (k.cmp(&amp;(node.k)) == Less) {
            match node.l {
                None =&gt; { node.l = Some(bstnode::new(k, v)) ; }
                Some(ref mut l) =&gt; bstnode::dumbinsert(l, k, v)
            }
        }
        else {
            match node.r {
                None =&gt; { node.r = Some(bstnode::new(k, v)) ; }
                Some(ref mut r) =&gt; bstnode::dumbinsert(r, k, v)
            }
        }
    }
}

fn main() {
    let k = ~&quot;foo&quot;;
    let v = ~&quot;bar&quot;;
    let mut t = bstnode::new(&amp;k, &amp;v) ;
    let k2 = ~&quot;foo2&quot; ; let v2 = ~&quot;bar2&quot; ;
    bstnode::dumbinsert(&amp;mut t, &amp;k2, &amp;v2) ;
}"><pre class="notranslate"><span class="pl-k">extern</span> <span class="pl-k">mod</span> extra <span class="pl-kos">;</span>
<span class="pl-k">use</span> std<span class="pl-kos">::</span>rand<span class="pl-kos">;</span>
<span class="pl-k">use</span> std<span class="pl-kos">::</span>rand<span class="pl-kos">::</span><span class="pl-v">Rng</span><span class="pl-kos">;</span>
<span class="pl-k">use</span> std<span class="pl-kos">::</span>vec <span class="pl-kos">;</span>
<span class="pl-k">use</span> std<span class="pl-kos">::</span>str <span class="pl-kos">;</span>
<span class="pl-k">use</span> extra<span class="pl-kos">::</span>sort <span class="pl-kos">;</span>

<span class="pl-k">struct</span> <span class="pl-smi">bstnode</span><span class="pl-kos">&lt;</span><span class="pl-smi">K</span><span class="pl-kos">,</span> <span class="pl-smi">V</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-c1">k</span> <span class="pl-kos">:</span> <span class="pl-smi">K</span><span class="pl-kos">,</span>
    <span class="pl-c1">v</span> <span class="pl-kos">:</span> <span class="pl-smi">V</span><span class="pl-kos">,</span>
    <span class="pl-c1">l</span> <span class="pl-kos">:</span> <span class="pl-smi">Option</span><span class="pl-kos">&lt;</span> <span class="pl-smi">bstnode</span><span class="pl-kos">&lt;</span><span class="pl-smi">K</span><span class="pl-kos">,</span> <span class="pl-smi">V</span><span class="pl-kos">&gt;</span> <span class="pl-kos">&gt;</span><span class="pl-kos">,</span>
    <span class="pl-c1">r</span> <span class="pl-kos">:</span> <span class="pl-smi">Option</span><span class="pl-kos">&lt;</span> <span class="pl-smi">bstnode</span><span class="pl-kos">&lt;</span><span class="pl-smi">K</span><span class="pl-kos">,</span> <span class="pl-smi">V</span><span class="pl-kos">&gt;</span> <span class="pl-kos">&gt;</span>
<span class="pl-kos">}</span>

<span class="pl-k">impl</span><span class="pl-kos">&lt;</span><span class="pl-smi">K</span> <span class="pl-kos">:</span> <span class="pl-smi">Clone</span> + <span class="pl-smi">Eq</span> + <span class="pl-smi">TotalOrd</span> <span class="pl-kos">,</span> <span class="pl-smi">V</span> <span class="pl-kos">:</span> <span class="pl-smi">Clone</span><span class="pl-kos">&gt;</span> <span class="pl-smi">bstnode</span><span class="pl-kos">&lt;</span><span class="pl-smi">K</span><span class="pl-kos">,</span> <span class="pl-smi">V</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">fn</span> <span class="pl-en">new</span><span class="pl-kos">(</span><span class="pl-s1">k</span><span class="pl-kos">:</span> <span class="pl-c1">&amp;</span><span class="pl-smi">K</span><span class="pl-kos">,</span> <span class="pl-s1">v</span><span class="pl-kos">:</span> <span class="pl-c1">&amp;</span><span class="pl-smi">V</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">bstnode</span><span class="pl-kos">&lt;</span><span class="pl-smi">K</span><span class="pl-kos">,</span><span class="pl-smi">V</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
        <span class="pl-smi">bstnode</span> <span class="pl-kos">{</span> <span class="pl-c1">k</span><span class="pl-kos">:</span> <span class="pl-kos">(</span><span class="pl-c1">*</span>k<span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">clone</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-c1">v</span><span class="pl-kos">:</span> <span class="pl-kos">(</span><span class="pl-c1">*</span>v<span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">clone</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-c1">l</span><span class="pl-kos">:</span> <span class="pl-v">None</span><span class="pl-kos">,</span> <span class="pl-c1">r</span><span class="pl-kos">:</span> <span class="pl-v">None</span> <span class="pl-kos">}</span>
    <span class="pl-kos">}</span>
    <span class="pl-k">fn</span> <span class="pl-en">dumbinsert</span><span class="pl-kos">(</span><span class="pl-s1">node</span><span class="pl-kos">:</span> <span class="pl-c1">&amp;</span><span class="pl-k">mut</span> <span class="pl-smi">bstnode</span><span class="pl-kos">&lt;</span><span class="pl-smi">K</span><span class="pl-kos">,</span> <span class="pl-smi">V</span><span class="pl-kos">&gt;</span><span class="pl-kos">,</span> <span class="pl-s1">k</span> <span class="pl-kos">:</span> <span class="pl-c1">&amp;</span><span class="pl-smi">K</span><span class="pl-kos">,</span> <span class="pl-s1">v</span> <span class="pl-kos">:</span> <span class="pl-c1">&amp;</span><span class="pl-smi">V</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">if</span> <span class="pl-kos">(</span>node<span class="pl-kos">.</span><span class="pl-c1">k</span><span class="pl-kos">.</span><span class="pl-en">cmp</span><span class="pl-kos">(</span>k<span class="pl-kos">)</span> == <span class="pl-v">Equal</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            node<span class="pl-kos">.</span><span class="pl-c1">v</span> = v<span class="pl-kos">.</span><span class="pl-en">clone</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">else</span> <span class="pl-k">if</span> <span class="pl-kos">(</span>k<span class="pl-kos">.</span><span class="pl-en">cmp</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-kos">(</span>node<span class="pl-kos">.</span><span class="pl-c1">k</span><span class="pl-kos">)</span><span class="pl-kos">)</span> == <span class="pl-v">Less</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
            <span class="pl-k">match</span> node<span class="pl-kos">.</span><span class="pl-c1">l</span> <span class="pl-kos">{</span>
                <span class="pl-v">None</span> =&gt; <span class="pl-kos">{</span> node<span class="pl-kos">.</span><span class="pl-c1">l</span> = <span class="pl-v">Some</span><span class="pl-kos">(</span>bstnode<span class="pl-kos">::</span><span class="pl-en">new</span><span class="pl-kos">(</span>k<span class="pl-kos">,</span> v<span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-kos">;</span> <span class="pl-kos">}</span>
                <span class="pl-v">Some</span><span class="pl-kos">(</span><span class="pl-k">ref</span> <span class="pl-k">mut</span> l<span class="pl-kos">)</span> =&gt; bstnode<span class="pl-kos">::</span><span class="pl-en">dumbinsert</span><span class="pl-kos">(</span>l<span class="pl-kos">,</span> k<span class="pl-kos">,</span> v<span class="pl-kos">)</span>
            <span class="pl-kos">}</span>
        <span class="pl-kos">}</span>
        <span class="pl-k">else</span> <span class="pl-kos">{</span>
            <span class="pl-k">match</span> node<span class="pl-kos">.</span><span class="pl-c1">r</span> <span class="pl-kos">{</span>
                <span class="pl-v">None</span> =&gt; <span class="pl-kos">{</span> node<span class="pl-kos">.</span><span class="pl-c1">r</span> = <span class="pl-v">Some</span><span class="pl-kos">(</span>bstnode<span class="pl-kos">::</span><span class="pl-en">new</span><span class="pl-kos">(</span>k<span class="pl-kos">,</span> v<span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-kos">;</span> <span class="pl-kos">}</span>
                <span class="pl-v">Some</span><span class="pl-kos">(</span><span class="pl-k">ref</span> <span class="pl-k">mut</span> r<span class="pl-kos">)</span> =&gt; bstnode<span class="pl-kos">::</span><span class="pl-en">dumbinsert</span><span class="pl-kos">(</span>r<span class="pl-kos">,</span> k<span class="pl-kos">,</span> v<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">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> k = ~"foo"<span class="pl-kos">;</span>
    <span class="pl-k">let</span> v = ~"bar"<span class="pl-kos">;</span>
    <span class="pl-k">let</span> <span class="pl-k">mut</span> t = bstnode<span class="pl-kos">::</span><span class="pl-en">new</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span>k<span class="pl-kos">,</span> <span class="pl-c1">&amp;</span>v<span class="pl-kos">)</span> <span class="pl-kos">;</span>
    <span class="pl-k">let</span> k2 = ~"foo2" <span class="pl-kos">;</span> <span class="pl-k">let</span> v2 = ~"bar2" <span class="pl-kos">;</span>
    bstnode<span class="pl-kos">::</span><span class="pl-en">dumbinsert</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-k">mut</span> t<span class="pl-kos">,</span> <span class="pl-c1">&amp;</span>k2<span class="pl-kos">,</span> <span class="pl-c1">&amp;</span>v2<span class="pl-kos">)</span> <span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">This is a backtrace from compiletest built with -g</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#11 0x00007ffff7aee3ff in context::call_shim_on_c_stack (this=0x43d700, args=0x445e80, fn_ptr=0x7ffff7af2f48) at
 ../src/rt/arch/x86_64/context.h:58
#12 0x00007ffff7af4066 in call_upcall_on_c_stack (args=0x445e80, fn_ptr=0x7ffff7af2f48) at ../src/rt/rust_upcall
.cpp:37
#13 0x00007ffff7af3144 in upcall_shared_malloc (nbytes=52, td=0x0) at ../src/rt/rust_upcall.cpp:200
#14 0x000000000042be44 in glue_take::S::_7fffa7de31d4d8d4 ()
#15 0x000000000042ebf6 in _ZN9glue_take32R_5B_compile_lib_path_3D_Srun_lib_path17_78527795f021202cE ()
#16 0x0000000000426d8e in run_tests::_37dd24d3b9435856 ()
#17 0x000000000042fe28 in __morestack ()
#18 0x000000000041c0d0 in main::_c5e23313747479c7 ()
#19 0x000000000041c162 in _rust_main ()
#20 0x00007ffff7aec619 in task_start_wrapper (a=0x44272c) at ../src/rt/rust_task.cpp:282
#21 0x0000000000000000 in ?? ()"><pre class="notranslate"><code class="notranslate">#11 0x00007ffff7aee3ff in context::call_shim_on_c_stack (this=0x43d700, args=0x445e80, fn_ptr=0x7ffff7af2f48) at
 ../src/rt/arch/x86_64/context.h:58
#12 0x00007ffff7af4066 in call_upcall_on_c_stack (args=0x445e80, fn_ptr=0x7ffff7af2f48) at ../src/rt/rust_upcall
.cpp:37
#13 0x00007ffff7af3144 in upcall_shared_malloc (nbytes=52, td=0x0) at ../src/rt/rust_upcall.cpp:200
#14 0x000000000042be44 in glue_take::S::_7fffa7de31d4d8d4 ()
#15 0x000000000042ebf6 in _ZN9glue_take32R_5B_compile_lib_path_3D_Srun_lib_path17_78527795f021202cE ()
#16 0x0000000000426d8e in run_tests::_37dd24d3b9435856 ()
#17 0x000000000042fe28 in __morestack ()
#18 0x000000000041c0d0 in main::_c5e23313747479c7 ()
#19 0x000000000041c162 in _rust_main ()
#20 0x00007ffff7aec619 in task_start_wrapper (a=0x44272c) at ../src/rt/rust_task.cpp:282
#21 0x0000000000000000 in ?? ()
</code></pre></div>
<p dir="auto">gdb doesn't understand one of the names.</p>