Skip to content

Book section 4.8 (Ownership) v1 should be v. #34510

Closed
@jonmarkprice

Description

@jonmarkprice

In section 4.8, "The details" subheading, while explaining ownership with the following code example:

let v = vec![1, 2, 3];

let mut v2 = v;

the book suddenly switches to v1 instead of v after the v2.truncate example.

It would violate Rust’s safety guarantees by introducing a data race if one could access both v and v2 at the same time.

For example if we truncated the vector to just two elements through v2:

v2.truncate(2);

and v1 were still accessible we'd end up with an invalid vector since v1 would not know that the heap data has been truncated.

The book continues to use v1 for the rest of the paragraph. But v1 does not appear in any of the preceding code segments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions