Hi all!

Could someone help me with a question about the [References and lifetime
guide](http://doc.rust-lang.org/guide-lifetimes.html#borrowing-and-enums) (for
0.11.0) which I can't figure out.

In the *Lifetimes* section there is this example:

    fn example3() -> int {
        struct House { owner: Box<Person> }
        struct Person { age: int }

        let mut house = box House {
            owner: box Person {age: 30}
        };

        let owner_age = &house.owner.age;
        house = box House {owner: box Person {age: 40}}; // Error
        house.owner = box Person {age: 50}; // Error
        *owner_age
    }

Referring to this example the following section, *Borrowing and enums*,
says: "The previous example showed that the type system forbids any
borrowing of owned boxes found in aliasable, mutable memory."

But to me it seems that this example shows that borrowing and thus
aliasing is allowed, but prevents modification of the owning reference.
(Or conversely, that borrowing is not allowed is the owning reference is
modified.)

Is the quoted text from the guide incorrect? Or am I confused about the
meaning of the quote or the example?

BR,
Jens Lideström


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

Reply via email to