Skip to content

Commit e890370

Browse files
committed
add MaybeUninit to minicore
1 parent 9725c4b commit e890370

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/auxiliary/minicore.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
decl_macro,
2727
f16,
2828
f128,
29+
transparent_unions,
2930
asm_experimental_arch,
3031
unboxed_closures
3132
)]
@@ -119,6 +120,25 @@ pub struct ManuallyDrop<T: PointeeSized> {
119120
}
120121
impl<T: Copy + PointeeSized> Copy for ManuallyDrop<T> {}
121122

123+
#[lang = "maybe_uninit"]
124+
#[repr(transparent)]
125+
pub union MaybeUninit<T> {
126+
uninit: (),
127+
value: ManuallyDrop<T>,
128+
}
129+
130+
impl<T: Copy + PointeeSized> Copy for MaybeUninit<T> {}
131+
132+
impl<T> MaybeUninit<T> {
133+
pub const fn uninit() -> Self {
134+
Self { uninit: () }
135+
}
136+
137+
pub const fn new(value: T) -> Self {
138+
Self { value: ManuallyDrop { value } }
139+
}
140+
}
141+
122142
#[lang = "unsafe_cell"]
123143
#[repr(transparent)]
124144
pub struct UnsafeCell<T: PointeeSized> {

0 commit comments

Comments
 (0)