On 2/8/12 12:05 AM, Marijn Haverbeke wrote:
Help me understand -- does this mean 'let x = {a: 10}; x = {a: 20};'
would be illegal (assigning to non-assignable type)?

Yes. What would be legal would be:

    let x = @{a: 10};
    x = @{a: 20};

or something similar. But `x = {a: 20}` effectively overwrites x.a, which was declared as immutable.

Also, you only mention pattern matching, but function calls also
create references to the arguments. Would it be forbidden to do
f(foo.x) where x is a mutable field?

No, it is legal to do `f(foo.x)` but, depending on the type of `foo.x`, `f()` might be restricted in what it can do with the reference. For example:

    fn f(&x: {a: int}) {
        x = {a: 20}; // illegal, x is not an assignable type
    }

As far as I can see, there isn't much point to have mutable slots (e.g., by-mut-ref, vectors, @, fields, local variables) of non-assignable type, so perhaps that should simply be illegal. In which case, the declaration of `f()` above would not be illegal, you would have to use an immutable reference `&&` because `{a: int}` is not an assignable type. This would probably be my preference.


Niko
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to