Skip to content

SemVer hazards around changes to static items #15126

@obi1kenobi

Description

@obi1kenobi

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:

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 becomes extern, 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-semverArea: semver specifications, version matching, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions