Manishearth / humpty_dumpty

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

Incorrent handling of breaks inside match statements #23

Closed Munksgaard closed 9 years ago

Munksgaard commented 9 years ago

The following code incorrectly compiles without errors:

#[drop_protect]
struct Foo;

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

fn main() {
    let x = Foo;
    loop {
        match true {
            true => {
                close(x);
                break
            }
            false => {
                let y = Foo;
            }
        }
    }
}
Munksgaard commented 9 years ago

I think the handling of match and if statements could use an overhaul. The current code is very hacky, and I feel like it should be possible to make something more elegant.

Munksgaard commented 9 years ago

The same is true in if statements:

fn test6() {
    let x = Foo;
    loop {
        if true {
            x.close();
            break
        } else {
            let y = Foo;
        }
    }
}

compiles without error