Skip to content

Commit 40aedab

Browse files
committed
Require Pointee::Metadata to be Freeze
So pointee metadata can be used in anonymous statics. This is prerequisite for implementing ThinBox without allocation for ZST. See #123184 (comment)
1 parent 399fa2f commit 40aedab

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

library/core/src/ptr/metadata.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use crate::fmt;
44
use crate::hash::{Hash, Hasher};
5+
use crate::marker::Freeze;
56

67
/// Provides the pointer metadata type of any pointed-to type.
78
///
@@ -57,7 +58,7 @@ pub trait Pointee {
5758
// NOTE: Keep trait bounds in `static_assert_expected_bounds_for_metadata`
5859
// in `library/core/src/ptr/metadata.rs`
5960
// in sync with those here:
60-
type Metadata: Copy + Send + Sync + Ord + Hash + Unpin;
61+
type Metadata: Copy + Send + Sync + Ord + Hash + Unpin + Freeze;
6162
}
6263

6364
/// Pointers to types implementing this trait alias are “thin”.

library/core/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#![feature(duration_constructors)]
3737
#![feature(exact_size_is_empty)]
3838
#![feature(extern_types)]
39+
#![feature(freeze)]
3940
#![feature(flt2dec)]
4041
#![feature(fmt_internals)]
4142
#![feature(float_minimum_maximum)]

library/core/tests/ptr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use core::cell::RefCell;
2+
use core::marker::Freeze;
23
use core::mem::{self, MaybeUninit};
34
use core::num::NonZero;
45
use core::ptr;
@@ -841,7 +842,7 @@ fn ptr_metadata_bounds() {
841842
fn static_assert_expected_bounds_for_metadata<Meta>()
842843
where
843844
// Keep this in sync with the associated type in `library/core/src/ptr/metadata.rs`
844-
Meta: Copy + Send + Sync + Ord + std::hash::Hash + Unpin,
845+
Meta: Copy + Send + Sync + Ord + std::hash::Hash + Unpin + Freeze,
845846
{
846847
}
847848
}

0 commit comments

Comments
 (0)