-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
The following SemVer hazards around changes to static
items are not yet documented in the SemVer reference page.
Changing whether a static
is mutable or immutable
This change is breaking in both directions:
static mut
requires anunsafe
block to use, even for reads: https://doc.rust-lang.org/reference/items/static-items.html#r-items.static.mut.safety- non-
mut
static items cannot be mutated
Internal mutability, and possible extern
mutation
Moved from rust-lang/reference#1724 (comment)
As of Rust 1.83, some static
values can be assigned to const
items, with the limitation that the const
may not contain anything mutable: https://doc.rust-lang.org/beta/reference/items/constant-items.html#r-items.const.final-value-immutable
There are two possible breaking changes here:
- a
pub static
newly becomes internally-mutable - a
pub static
becomesextern
, in which case the compiler will conservatively assume it may be mutable
To demonstrate a breaking change via these hazards, consider an assignment of the static
to a const
akin to:
pub const WITNESS: i64 = THE_STATIC;
This will only work so long as the static
is non-extern
, not mut
, and not internally-mutable. The mut
hazard is described above already, and doesn't require a const
to demonstrate.