Repository navigation
Open
Labels
B-experimentalBlocker: In-tree experiment; RFC pending, not yet approved or unneeded (requires FCP to stabilize).C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-freeze`#![feature(freeze)]`T-langRelevant to the language teamT-libsRelevant to the library team, which will review and decide on the PR/issue.
Description
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
- Implementation: Expose the Freeze trait again (unstably) and forbid implementing it manually #121840
- Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- naming the trait differently (see #121501 (comment))
Footnotes
Reacted by Juniper Tyree, Lily, terrarier2111, Stepan Koltsov, zachs18, Alyssa Haroldsen, Timothy Harding, Mincong Lu, musjj, Gabriel Bjørnager Jensen and 2 more
Reacted by Juniper Tyree and musjj
Reacted by Juniper Tyree and musjj
Reacted by Juniper Tyree, Alyssa Haroldsen, Gabriel Bjørnager Jensen, Timothy Harding, musjj and nthorat230-lab
Reacted by Juniper Tyree, Jiening Yu, Alyssa Haroldsen, Mincong Lu and musjj
Reacted by Juniper Tyree, orzogc, Alyssa Haroldsen, José Luis Cruz, Mincong Lu and musjj
Metadata
Metadata
Assignees
Labels
B-experimentalBlocker: In-tree experiment; RFC pending, not yet approved or unneeded (requires FCP to stabilize).C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-freeze`#![feature(freeze)]`T-langRelevant to the language teamT-libsRelevant to the library team, which will review and decide on the PR/issue.
Type
Projects
- StatusShow more project fieldsExploration
Activity
RalfJung commentedon May 2, 2024
@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?
nikomatsakis commentedon May 8, 2024
RalfJung commentedon May 8, 2024
nikomatsakis commentedon May 9, 2024
RalfJung commentedon May 9, 2024
Okay, thanks.
So -- if someone wants to help push this towards stabilization, drafting an RFC would be a good next step. :)
p-avital commentedon May 10, 2024
Here is a stabilization RFC for this feature: rust-lang/rfcs#3633 :)
jdonszelmann commentedon Sep 28, 2024
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
RalfJung commentedon Sep 28, 2024
Yeah that's basically the same case as @p-avital's
NickGeek commentedon Nov 19, 2024
NickGeek commentedon Nov 19, 2024
RalfJung commentedon Nov 19, 2024
NickGeek commentedon Nov 19, 2024
`declare_interior_mutable_const`, `borrow_interior_mutable_const`: re…
fix(error): the door AsMut's removal closed was the ordinary one, not…
ElliottjPierce commentedon Sep 11, 2026
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
Freezebound 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
NoCellis better. Honestly, I thinkFreezeis as good as it gets.NoCellis 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 needingFreezeis probably doing something fairly complex and probably isn't afraid to read some friendly documentation. Once you read what it does,Freezemakes 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 asFreezeis something likeSeal, 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
Freezeimplementations, but I think that's a separate issue.There's also discussion of how this should work with certain pointers, especially
Unique, and withPhantomData. IMO, these interactions are non-essential to whatFreezedoes. We could always have a trait in the future, likeDeepFreezeor something, that prevents semantic interior mutability in addition to structural interior mutability. That is,PhantomData<UnsafeCell<()>>andUnique<UnsafeCell<()>>would beFreezebut notDeepFreeze. 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,DeepFreezeor 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.
RalfJung commentedon Sep 11, 2026
There has been some recent discussion at https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/Reviving.20the.20Freeze.20RFC.20.283633.29/with/615146836