nikomatsakis / nll-rfc

Non-lexical lifetimes RFC.
48 stars 17 forks source link

[borrowck] discriminant accesses #39

Closed arielb1 closed 7 years ago

arielb1 commented 7 years ago

Enum discriminants can be accessed in today's Rust without doing a read of all the interior of the enum:

fn main() {
    let mut t = Some(0);
    let y = if let Some(ref mut y) = t {
        y
    } else {
        panic!();
    };

    if let Some(_) = t {
        println!("{}", y);
    }
}

I think the smartest way to handle this is to treat discriminants as their own separate field. This might warrant a note in the RFC.

Sorry for being tedious here - I am trying to use the borrowck part of this RFC as a specification to check against while reviewing MIR borrowck.

nikomatsakis commented 7 years ago

This is a very good point. I agree with the idea of them being a kind of field.