Closed RalfJung closed 1 month ago
I have a few ideas about how to write it, for varying levels of rigor. I think that in terms of lifetime extension, const-promotion occurs for both static
and const
items, correct? I'd expect that the const-promotion rule would apply there as well.
Const promotion and lifetime extension are largely orthogonal mechanisms. I was talking about lifetime extension above. Promotion does not apply in that example as Vec
has a destructor.
Ok, then I'd probably say
All bytes within a const-promoted expression, or a lifetime-extended expression in the initializer of a
static
orconst
item are immutable. All bytes owned (directly) by an immutable binding or immutablestatic
are immutable, except bytes within an [core::cell::UnsafeCell
].
Yeah, that sounds good.
Currently, we define "immutable bytes" as
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
Secondly, for
static
, the actual rule is that for bytes inside lifetime-extended values, they are all immutable.UnsafeCell
makes no difference.