Skip to content

rvalues don't live long enough when using "ref" #3217

Description

@bblum

This code does a use-after-free:

fn main() {
    let msg;
    match some(~"Hello") {
        some(ref m) => {
            msg = m;
        },  
        none => { fail }
    }   
    io::println(*msg);
}

Should it not compile? Or should liveness/borrowck ensure that the string live as long as the escaped reference?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsI-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