Skip to content

move_val_init causes wierd breakage #3917

Closed
@brson

Description

@brson

From Blub:

fn main() {
    // this line causes the madness
    let mut _done: ~[bool] = vec::from_fn(4, |_x| { false });

    let input = io::stdin();
    let line = read_line(input);

    io::println(fmt!("got %?", line));
}

fn read_line(input: @io::Reader) -> ~str {
    let mut bytes = ~[];
    loop {
        let ch = input.read_byte();
        if ch == -1 || ch == 10 { break; }
        bytes.push(ch as u8);
    }
    str::from_bytes(bytes)
}
This is obviously wrong:

wry:tmp/ $ rustc order.rs && echo aaa | ./order
got ~"\x01\x01\x01"

It gets fixed when I move the read_line() function *above* main.
(same thing happens with input.read_line() from io::ReaderUtil btw)

removing the vec::from_fn() line fixes it too...

Also, changing the type of vec _done from ~[bool] to ~[anything else] makes it go away.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generation

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions