Manishearth / humpty_dumpty

Implicit Drop/move protection for Rust (linear types)
12 stars 1 forks source link

Handle return statements #4

Closed Munksgaard closed 9 years ago

Munksgaard commented 9 years ago

The following code should be allowed

#[drop_protect]
struct Foo;

#[allow_drop(Foo)]
fn close(_: Foo) { }

fn bla(x: Foo) {
    if true {
        close(x);
        return;
    }

    close(x);
}

However, this shouldn't

#[drop_protect]
struct Foo;

#[allow_drop(Foo)]
fn close(_: Foo) { }

fn bla(x: Foo) {
    if true {
        return;
    }

    close(x);
}
Munksgaard commented 9 years ago

The handle-return branch is an attempt to fix this.

Munksgaard commented 9 years ago

In fact, we also need to support break and continue. For example, this should work:

fn loop_break() {
    let foo = Foo;

    loop {
        foo.close();
        break;
    }
}

while this shouldn't

fn loop_break() {
    let foo = Foo;

    loop {
        if something {
          foo.close();
        }
        break;
    }
}
Munksgaard commented 9 years ago

Initial support for all this is in the handle-return branch. I probably need to finish the fix-generics branch before merging though.