Skip to content

Clarify "immutable bytes" definition #1616

Closed
@RalfJung

Description

@RalfJung

Currently, we define "immutable bytes" as

All bytes inside a const item or within an implicitly const-promoted expression are immutable. The bytes owned by an immutable binding or immutable static are immutable, unless those bytes are part of an UnsafeCell.

However, there are some issue with this. First of all, a const item can only be used as a value, not as a place, so it doesn't really "contain" bytes that could be (im)mutable -- except if it is subject to lifetime extension, as in

const C: &Vec<i32> = &Vec::new();

Secondly, for static, the actual rule is that for bytes inside lifetime-extended values, they are all immutable. UnsafeCell makes no difference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions