Skip to content

Commit 33c34ea

Browse files
authored
Rollup merge of rust-lang#121840 - oli-obk:freeze, r=dtolnay
Expose the Freeze trait again (unstably) and forbid implementing it manually non-emoji version of rust-lang#121501 cc rust-lang#60715 This trait is useful for generic constants (associated consts of generic traits). See the test (`tests/ui/associated-consts/freeze.rs`) added in this PR for a usage example. The builtin `Freeze` trait is the only way to do it, users cannot work around this issue. It's also a useful trait for building some very specific abstrations, as shown by the usage by the `zerocopy` crate: google/zerocopy#941 cc ```@RalfJung``` T-lang signed off on reexposing this unstably: rust-lang#121501 (comment)
2 parents aa10551 + 2f57d3e commit 33c34ea

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@
204204
// tidy-alphabetical-start
205205
#![cfg_attr(bootstrap, feature(diagnostic_namespace))]
206206
#![cfg_attr(bootstrap, feature(platform_intrinsics))]
207+
#![cfg_attr(not(bootstrap), feature(freeze_impls))]
207208
#![feature(abi_unadjusted)]
208209
#![feature(adt_const_params)]
209210
#![feature(allow_internal_unsafe)]

core/src/marker.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,15 +810,21 @@ pub trait DiscriminantKind {
810810
type Discriminant: Clone + Copy + Debug + Eq + PartialEq + Hash + Send + Sync + Unpin;
811811
}
812812

813-
/// Compiler-internal trait used to determine whether a type contains
813+
/// Used to determine whether a type contains
814814
/// any `UnsafeCell` internally, but not through an indirection.
815815
/// This affects, for example, whether a `static` of that type is
816816
/// placed in read-only static memory or writable static memory.
817+
/// This can be used to declare that a constant with a generic type
818+
/// will not contain interior mutability, and subsequently allow
819+
/// placing the constant behind references.
817820
#[lang = "freeze"]
818-
pub(crate) unsafe auto trait Freeze {}
821+
#[unstable(feature = "freeze", issue = "121675")]
822+
pub unsafe auto trait Freeze {}
819823

824+
#[unstable(feature = "freeze", issue = "121675")]
820825
impl<T: ?Sized> !Freeze for UnsafeCell<T> {}
821826
marker_impls! {
827+
#[unstable(feature = "freeze", issue = "121675")]
822828
unsafe Freeze for
823829
{T: ?Sized} PhantomData<T>,
824830
{T: ?Sized} *const T,

0 commit comments

Comments
 (0)