[rust-dev] Confusion about lifetime guide example

Jens Lideström jens at lidestrom.se
Sun Jun 1 13:32:52 PDT 2014

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

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

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

Jens Lideström

More information about the Rust-dev mailing list