Skip to content

Update safety requirements of Vec::from_raw_parts? #94950

Closed
@EFanZh

Description

@EFanZh

The “Safety” section of the document of Vec::from_raw_parts says:

  • length needs to be less than or equal to capacity.
  • capacity needs to be the capacity that the pointer was allocated with.

I think the first requirement should also add “The first length elements starting from ptr are initialized”. And the second requirement could be relaxed into “capacity needs to be less than or equal to the capacity that the pointer was allocated with”, this is because Allocator::deallocate does not require specifying exact size that the pointer was allocated with.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-allocatorsArea: Custom and system allocatorsA-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.C-discussionCategory: Discussion or questions that doesn't represent real issues.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.T-opsemRelevant to the opsem team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions