Closed
Description
➜ datastructures.rs git:(master) ✗ RUST_LOG="rustc=1;::rt::backtrace" rustc stack.rs &&./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
The code that caused it is:
trait ImmStack<T> {
fn push(self, item : T) -> Self;
fn pop(self) -> (Option<T>, Option<Self>);
fn new() -> Self;
}
#[deriving(Eq, ToStr)]
enum Chain<T> {
Link(T, ~Chain<T>),
Break
}
//impl<T> ImmStack<T> for Chain<T> {
// fn push(self, item : T) -> Chain<T> {
// Link(item, ~self)
// }
// fn pop(self) -> (Option<T>, Option<Chain<T>>) {
// match self {
// Link(item, ~new_self) => return (Some(item), Some(new_self)),
// Break => return (None, None)
// }
// }
// fn new() -> Chain<T> {
// Break
// }
//}
fn push<'self, T>(stack : &'self mut Chain<T>, item : T) -> &'self mut Chain<T> {
&mut Link(item, ~*stack)
}
fn pop<T>(stack : &mut Chain<T>) -> Option<T> {
match *stack {
Link(item, ~new_stack) => {
stack = &mut new_stack;
return Some(item);
},
Break => return None
}
}
fn new<T>() -> &mut Chain<T> {
&mut Break
}
fn main() {
let mut b : &Chain<int> = ~Break;
push(push(push(b, 1), 2), 3);
println(b.to_str());
}