Skip to content

Commit aa38b7f

Browse files
committed
add MaybeUninit to minicore
1 parent ec2d669 commit aa38b7f

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

tests/auxiliary/minicore.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
decl_macro,
2828
f16,
2929
f128,
30+
transparent_unions,
3031
asm_experimental_arch,
3132
unboxed_closures
3233
)]
@@ -127,6 +128,25 @@ pub struct ManuallyDrop<T: PointeeSized> {
127128
}
128129
impl<T: Copy + PointeeSized> Copy for ManuallyDrop<T> {}
129130

131+
#[lang = "maybe_uninit"]
132+
#[repr(transparent)]
133+
pub union MaybeUninit<T> {
134+
uninit: (),
135+
value: ManuallyDrop<T>,
136+
}
137+
138+
impl<T: Copy + PointeeSized> Copy for MaybeUninit<T> {}
139+
140+
impl<T> MaybeUninit<T> {
141+
pub const fn uninit() -> Self {
142+
Self { uninit: () }
143+
}
144+
145+
pub const fn new(value: T) -> Self {
146+
Self { value: ManuallyDrop { value } }
147+
}
148+
}
149+
130150
#[repr(transparent)]
131151
#[rustc_nonnull_optimization_guaranteed]
132152
pub struct NonNull<T: ?Sized> {

0 commit comments

Comments
 (0)