SemVer hazards around changes to static
items
#15126
Labels
A-semver
Area: semver specifications, version matching, etc.
static
items
#15126
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 immutableThis 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.safetymut
static items cannot be mutatedInternal mutability, and possible
extern
mutationMoved from rust-lang/reference#1724 (comment)
As of Rust 1.83, some
static
values can be assigned toconst
items, with the limitation that theconst
may not contain anything mutable: https://doc.rust-lang.org/beta/reference/items/constant-items.html#r-items.const.final-value-immutableThere are two possible breaking changes here:
pub static
newly becomes internally-mutablepub static
becomesextern
, in which case the compiler will conservatively assume it may be mutableTo demonstrate a breaking change via these hazards, consider an assignment of the
static
to aconst
akin to:This will only work so long as the
static
is non-extern
, notmut
, and not internally-mutable. Themut
hazard is described above already, and doesn't require aconst
to demonstrate.The text was updated successfully, but these errors were encountered: