Skip to content

Segfault when matching a copy of a owned box #4541

Closed
@lbonn

Description

@lbonn

I am very new to rust, so please bear with me :).

When trying to do a small routine to parse the arguments of a program, I stumbled on a nice segfault. Here is the prototype of what I tried.

fn parse_args() -> ~str {
    let args = core::os::args();
    let mut n = 0;

    while n < args.len() {
        match copy args[n] {
            ~"-v" => (),
            s => {
                return s;
            }
        }
        n += 1;
    }

    return ~""
}

fn main() {
    io::println(parse_args());
}

This example is meaningless and only illustrates the issue. I managed to write what I wanted in a cleanier style afterwards but I still think it's a bug.

It compiles without a warning but it crashes violently when running it.

Metadata

Metadata

Assignees

Labels

A-codegenArea: Code generationA-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsI-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions