简体   繁体   中英

Task 'rustc' has overflowed its stack

Chat server which fails to compile:

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));
                    }
                })
            }
        }
    }
}

The error is:

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

Is this fixable in code, or is it a compiler bug?

Note: @Levans thanks for your help this evening.

The compiler has crashed. You are not even writing your own macros. This is 100% a compiler bug. Report it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM