<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="➜  datastructures.rs git:(master) ✗ RUST_LOG=&quot;rustc=1;::rt::backtrace&quot; rustc stack.rs &amp;&amp;./stack
rust: task failed at 'assertion failed: rp.is_none()', /private/tmp/rust-5o4g/rust-0.7/src/librustc/middle/typeck/collect.rs:1040
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=1,::rt::backtrace to get further details and report the results to github.com/mozilla/rust/issues
rust: task failed at 'explicit failure', /private/tmp/rust-5o4g/rust-0.7/src/librustc/rustc.rs:354
rust: domain main @0x7f9afc008410 root task failed"><pre class="notranslate"><code class="notranslate">➜  datastructures.rs git:(master) ✗ RUST_LOG="rustc=1;::rt::backtrace" rustc stack.rs &amp;&amp;./stack
rust: task failed at 'assertion failed: rp.is_none()', /private/tmp/rust-5o4g/rust-0.7/src/librustc/middle/typeck/collect.rs:1040
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=1,::rt::backtrace to get further details and report the results to github.com/mozilla/rust/issues
rust: task failed at 'explicit failure', /private/tmp/rust-5o4g/rust-0.7/src/librustc/rustc.rs:354
rust: domain main @0x7f9afc008410 root task failed
</code></pre></div>
<p dir="auto">The code that caused it is:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="trait ImmStack&lt;T&gt; {
    fn push(self, item : T) -&gt; Self;
    fn pop(self) -&gt; (Option&lt;T&gt;, Option&lt;Self&gt;);
    fn new() -&gt; Self;
}

#[deriving(Eq, ToStr)]
enum Chain&lt;T&gt; {
    Link(T, ~Chain&lt;T&gt;),
    Break
}

//impl&lt;T&gt; ImmStack&lt;T&gt; for Chain&lt;T&gt; {
//    fn push(self, item : T) -&gt; Chain&lt;T&gt; {
//        Link(item, ~self)
//    }
//    fn pop(self) -&gt; (Option&lt;T&gt;, Option&lt;Chain&lt;T&gt;&gt;) {
//        match self {
//            Link(item, ~new_self) =&gt; return (Some(item), Some(new_self)),
//            Break =&gt; return (None, None)
//        }
//    }
//    fn new() -&gt; Chain&lt;T&gt; {
//        Break
//    }
//}

fn push&lt;'self, T&gt;(stack : &amp;'self mut Chain&lt;T&gt;, item : T) -&gt; &amp;'self mut Chain&lt;T&gt; {
    &amp;mut Link(item, ~*stack)
}

fn pop&lt;T&gt;(stack : &amp;mut Chain&lt;T&gt;) -&gt; Option&lt;T&gt; {
    match *stack {
        Link(item, ~new_stack) =&gt; {
            stack = &amp;mut new_stack;
            return Some(item);
        },
        Break =&gt; return None
    }
}

fn new&lt;T&gt;() -&gt; &amp;mut Chain&lt;T&gt; {
    &amp;mut Break
}

fn main() {
    let mut b : &amp;Chain&lt;int&gt; = ~Break;
    push(push(push(b, 1), 2), 3);
    println(b.to_str());
}"><pre class="notranslate"><span class="pl-k">trait</span> <span class="pl-smi">ImmStack</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">fn</span> <span class="pl-en">push</span><span class="pl-kos">(</span><span class="pl-smi">self</span><span class="pl-kos">,</span> <span class="pl-s1">item</span> <span class="pl-kos">:</span> <span class="pl-smi">T</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">Self</span><span class="pl-kos">;</span>
    <span class="pl-k">fn</span> <span class="pl-en">pop</span><span class="pl-kos">(</span><span class="pl-smi">self</span><span class="pl-kos">)</span> -&gt; <span class="pl-kos">(</span><span class="pl-smi">Option</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span><span class="pl-kos">,</span> <span class="pl-smi">Option</span><span class="pl-kos">&lt;</span><span class="pl-smi">Self</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">new</span><span class="pl-kos">(</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">Self</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-c1">#<span class="pl-kos">[</span>deriving<span class="pl-kos">(</span><span class="pl-v">Eq</span>, <span class="pl-v">ToStr</span><span class="pl-kos">)</span><span class="pl-kos">]</span></span>
<span class="pl-k">enum</span> <span class="pl-smi">Chain</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-v">Link</span><span class="pl-kos">(</span><span class="pl-smi">T</span><span class="pl-kos">,</span> ~<span class="pl-smi">Chain</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
    <span class="pl-v">Break</span>
<span class="pl-kos">}</span>

<span class="pl-c">//impl&lt;T&gt; ImmStack&lt;T&gt; for Chain&lt;T&gt; {</span>
<span class="pl-c">//    fn push(self, item : T) -&gt; Chain&lt;T&gt; {</span>
<span class="pl-c">//        Link(item, ~self)</span>
<span class="pl-c">//    }</span>
<span class="pl-c">//    fn pop(self) -&gt; (Option&lt;T&gt;, Option&lt;Chain&lt;T&gt;&gt;) {</span>
<span class="pl-c">//        match self {</span>
<span class="pl-c">//            Link(item, ~new_self) =&gt; return (Some(item), Some(new_self)),</span>
<span class="pl-c">//            Break =&gt; return (None, None)</span>
<span class="pl-c">//        }</span>
<span class="pl-c">//    }</span>
<span class="pl-c">//    fn new() -&gt; Chain&lt;T&gt; {</span>
<span class="pl-c">//        Break</span>
<span class="pl-c">//    }</span>
<span class="pl-c">//}</span>

<span class="pl-k">fn</span> <span class="pl-en">push</span><span class="pl-kos">&lt;</span><span class="pl-c1">'</span><span class="pl-ent">self</span><span class="pl-kos">,</span> <span class="pl-smi">T</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span><span class="pl-s1">stack</span> <span class="pl-kos">:</span> <span class="pl-c1">&amp;</span><span class="pl-c1">'</span><span class="pl-ent">self</span> <span class="pl-k">mut</span> <span class="pl-smi">Chain</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span><span class="pl-kos">,</span> <span class="pl-s1">item</span> <span class="pl-kos">:</span> <span class="pl-smi">T</span><span class="pl-kos">)</span> -&gt; <span class="pl-c1">&amp;</span><span class="pl-c1">'</span><span class="pl-ent">self</span> <span class="pl-k">mut</span> <span class="pl-smi">Chain</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-c1">&amp;</span><span class="pl-k">mut</span> <span class="pl-v">Link</span><span class="pl-kos">(</span>item<span class="pl-kos">,</span> ~<span class="pl-c1">*</span>stack<span class="pl-kos">)</span>
<span class="pl-kos">}</span>

<span class="pl-k">fn</span> <span class="pl-en">pop</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span><span class="pl-s1">stack</span> <span class="pl-kos">:</span> <span class="pl-c1">&amp;</span><span class="pl-k">mut</span> <span class="pl-smi">Chain</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">Option</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">match</span> <span class="pl-c1">*</span>stack <span class="pl-kos">{</span>
        <span class="pl-v">Link</span><span class="pl-kos">(</span>item<span class="pl-kos">,</span> ~new_stack<span class="pl-kos">)</span> =&gt; <span class="pl-kos">{</span>
            stack = <span class="pl-c1">&amp;</span><span class="pl-k">mut</span> new_stack<span class="pl-kos">;</span>
            <span class="pl-k">return</span> <span class="pl-v">Some</span><span class="pl-kos">(</span>item<span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span><span class="pl-kos">,</span>
        <span class="pl-v">Break</span> =&gt; <span class="pl-k">return</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">new</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span><span class="pl-kos">)</span> -&gt; <span class="pl-c1">&amp;</span><span class="pl-k">mut</span> <span class="pl-smi">Chain</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-c1">&amp;</span><span class="pl-k">mut</span> <span class="pl-v">Break</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> <span class="pl-k">mut</span> b <span class="pl-kos">:</span> <span class="pl-c1">&amp;</span><span class="pl-smi">Chain</span><span class="pl-kos">&lt;</span><span class="pl-smi">int</span><span class="pl-kos">&gt;</span> = ~<span class="pl-v">Break</span><span class="pl-kos">;</span>
    <span class="pl-en">push</span><span class="pl-kos">(</span><span class="pl-en">push</span><span class="pl-kos">(</span><span class="pl-en">push</span><span class="pl-kos">(</span>b<span class="pl-kos">,</span> <span class="pl-c1">1</span><span class="pl-kos">)</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-c1">3</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-en">println</span><span class="pl-kos">(</span>b<span class="pl-kos">.</span><span class="pl-en">to_str</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></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ RUST_LOG=rustc=1,::rt::backtrace rustc link_header.rs
rust: task failed at 'assertion failed: rp.is_none()', /Users/shout/Projects/rust/src/librustc/middle/typeck/collect.rs:1044
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=1,::rt::backtrace to get further details and report the results to github.com/mozilla/rust/issues
rust: task failed at 'explicit failure', /Users/shout/Projects/rust/src/librustc/rustc.rs:358
rust: domain main @0x7f86ba819810 root task failed"><pre class="notranslate"><code class="notranslate">$ RUST_LOG=rustc=1,::rt::backtrace rustc link_header.rs
rust: task failed at 'assertion failed: rp.is_none()', /Users/shout/Projects/rust/src/librustc/middle/typeck/collect.rs:1044
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=1,::rt::backtrace to get further details and report the results to github.com/mozilla/rust/issues
rust: task failed at 'explicit failure', /Users/shout/Projects/rust/src/librustc/rustc.rs:358
rust: domain main @0x7f86ba819810 root task failed
</code></pre></div>
<p dir="auto">Complete contents of <code class="notranslate">link_header.rs</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#[ crate_type = &quot;lib&quot; ];

// Given a Link header, parse out the next url
// &lt;https://api.github.com/repositories?since=364&gt;; rel=&quot;next&quot;, &lt;https://api.github.com/repositories{?since}&gt;; rel=&quot;first&quot;
fn parse(header: ~str) -&gt; &amp;'self str {
    match header.find('&lt;') {
        Some(start) =&gt; {
            match header.find('&gt;') {
                Some(end) =&gt; {
                    return header.slice(start + 1, end);
                },
                _ =&gt; { fail!(&quot;Missing &gt;&quot;) }
            }
        },
        _ =&gt; {fail!(&quot;Missing &lt;&quot;) }
    }
}"><pre class="notranslate"><code class="notranslate">#[ crate_type = "lib" ];

// Given a Link header, parse out the next url
// &lt;https://api.github.com/repositories?since=364&gt;; rel="next", &lt;https://api.github.com/repositories{?since}&gt;; rel="first"
fn parse(header: ~str) -&gt; &amp;'self str {
    match header.find('&lt;') {
        Some(start) =&gt; {
            match header.find('&gt;') {
                Some(end) =&gt; {
                    return header.slice(start + 1, end);
                },
                _ =&gt; { fail!("Missing &gt;") }
            }
        },
        _ =&gt; {fail!("Missing &lt;") }
    }
}
</code></pre></div>