Skip to content

spec: clarify whether the spec guarantees that slicing an array reuses that array in the slice #31689

@theckman

Description

@theckman

While trying to explain a behavior of slicing an array, and the associated resulting capacity, we realized the spec wasn't immediately clear as to whether slicing an array reuses that array. Making it hard to know if it's part of the spec, or an implementation defined detail.

While reading this section, I understood it to say that this array would be used in the slice but not everyone interpreted it that way:

A slice, once initialized, is always associated with an underlying array that holds its elements. A slice therefore shares storage with its array and with other slices of the same array; by contrast, distinct arrays always represent distinct storage.

Would you be able to clarify if the spec guarantees this behavior, or if it's implementation-specific? If the former, would it make sense to add an explicit note to the spec to clear up any confusion? If it's not guaranteed, is it worth calling that out as being implementation specific?

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions