Skip to content

Tracking Issue for the Freeze trait #121675

Open

Description

@oli-obk

Feature gate: #![feature(freeze)]

This is a tracking issue for the core::marker::Freeze trait

This trait allows generic code to restrict generic parameters to types without interior mutability.

Public API

use std::marker::Freeze;

trait Trait<T: Freeze + 'static> {
    const VALUE: T;
    const VALUE_REF: &'static T = &Self::VALUE;
}

Steps / History

Unresolved Questions

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩

Activity

  1. added
    T-libs-api
    C-tracking-issue
    on Feb 27, 2024
  2. added
    T-lang
    B-experimental
    on Mar 1, 2024
  3. RalfJung commented on May 2, 2024

    @RalfJung
    Member

    @rust-lang/lang -- quick vibe check, do you think this needs an RFC or can it be done with a writeup and FCP in this issue?

  4. nikomatsakis commented on May 8, 2024

    @nikomatsakis
    Contributor
  5. RalfJung commented on May 8, 2024

    @RalfJung
    Member
  6. nikomatsakis commented on May 9, 2024

    @nikomatsakis
    Contributor
  7. RalfJung commented on May 9, 2024

    @RalfJung
    Member

    Okay, thanks.

    So -- if someone wants to help push this towards stabilization, drafting an RFC would be a good next step. :)

  8. p-avital commented on May 10, 2024

    @p-avital

    Here is a stabilization RFC for this feature: rust-lang/rfcs#3633 :)

  9. jdonszelmann commented on Sep 28, 2024

    @jdonszelmann
    Contributor

    I found an interesting case in which I needed Freeze. Currently, the diagnostics for this are very confusing (I might follow with a PR that improves that) but @WaffleLapkin said it might be nice to comment this here.

    not-working example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=9939beef497fc78bf2951342b379cf4b

    fixed using freeze: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1efad00dbd416d99abe2da4c9758e2a1

  10. RalfJung commented on Sep 28, 2024

    @RalfJung
    Member

    Yeah that's basically the same case as @p-avital's

  11. NickGeek commented on Nov 19, 2024

    @NickGeek
  12. NickGeek commented on Nov 19, 2024

    @NickGeek
  13. RalfJung commented on Nov 19, 2024

    @RalfJung
  14. NickGeek commented on Nov 19, 2024

    @NickGeek
  15. added
    F-freeze
    on Dec 2, 2024
  16. moved this from Exploration to Needs champion in Lang team featureson Feb 21, 2025
  17. moved this from Needs champion to Exploration in Lang team featureson Mar 4, 2025
  18. self-assigned this
    on Mar 4, 2025
  19. added
    T-libs
    and removed
    T-libs-api
    on Aug 12, 2026
  20. ElliottjPierce commented on Sep 11, 2026

    @ElliottjPierce
    Contributor

    I ran into this issue today in my work, and since there hasn't been any update on this in a couple years, I'm curious what's blocking stabilizing this. There currently isn't an idiomatic workaround when a Freeze bound is needed, so it would be great to resolve this.

    From what I can tell, the only still unanswered question is naming. Some people argue that something like NoCell is better. Honestly, I think Freeze is as good as it gets. NoCell is self-explanatory, but even that doesn't capture the essence of what the trait is. If anything, it hints at its current implementation. (What if interior mutability is somehow in the future made possible without cells?) Anyone needing Freeze is probably doing something fairly complex and probably isn't afraid to read some friendly documentation. Once you read what it does, Freeze makes perfect sense: If it goes in a static, it's frozen, and you can't tamper with it! The only name I can think that is as clear as Freeze is something like Seal, but that already has another common meaning in Rust.

    There are a handful of related topics tossed around here, but I haven't seen any of them mentioned as blockers. There's the question of allowing Freeze implementations, but I think that's a separate issue.

    There's also discussion of how this should work with certain pointers, especially Unique, and with PhantomData. IMO, these interactions are non-essential to what Freeze does. We could always have a trait in the future, like DeepFreeze or something, that prevents semantic interior mutability in addition to structural interior mutability. That is, PhantomData<UnsafeCell<()>> and Unique<UnsafeCell<()>> would be Freeze but not DeepFreeze. I think it's worth distinguishing between a "it can go in immutable static memory" trait, Freeze, and a "you can't tamper with a value given a readonly reference to it" trait, DeepFreeze or something else we can figure out in the future.

    If there is active work on this, I don't mean to rush anyone. I just couldn't find it and am curious what the next steps are.

  21. RalfJung commented on Sep 11, 2026

    @RalfJung
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

B-experimentalC-tracking-issueF-freezeT-langT-libs

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions