任务'rustc'溢出了它的堆栈

时间:2014-10-08 21:24:03

标签: stack-overflow rust

无法编译的聊天服务器:

use std::io::{TcpListener, TcpStream};
use std::io::{Acceptor, Listener};

enum StreamOrSlice {
     Strm(TcpStream),
     Slc(uint, [u8, ..1024])
}

fn main() {
    let listener = TcpListener::bind("127.0.0.1", 5555);

    // bind the listener to the specified address
    let mut acceptor = listener.listen();

    let (tx, rx) = channel();

    spawn(proc() {
        let mut streams: Vec<TcpStream> = Vec::new();
        loop {
            let rxd: StreamOrSlice = rx.recv();
            match rxd {
                Strm(stream) => {
                    streams.push(stream);
                }
                Slc(len, buf) => {
                    for stream in streams.iter_mut() {
                        let _ = stream.write(buf.slice(0, len));
                    }
                }
            }
        }
    });

    // accept connections and process them, spawning a new tasks for each one
    for stream in acceptor.incoming() {
        match stream {
            Err(e) => { /* connection failed */ }
            Ok(mut stream) => {
                // connection succeeded
                tx.send(Strm(stream.clone()));
                let tx2 = tx.clone();
                spawn(proc() {
                    let mut buf: [u8, ..1024] = [0, ..1024];
                    loop {
                        let len = stream.read(buf);
                        tx2.send(Slc(len.unwrap(), buf));
                    }
                })
            }
        }
    }
}

错误是:

   Compiling chat v0.1.0 (file:///home/chris/rust/chat)
task 'rustc' has overflowed its stack
Could not compile `chat`.

这可以在代码中修复,还是编译器错误?

注意:@Levans感谢您今晚的帮助。

1 个答案:

答案 0 :(得分:3)

编译器崩溃了。你甚至没有编写自己的宏。这是100%的编译器错误。报告。