Skip to content

Commit 63ae080

Browse files
committed
move more feature gates behind a Cargo feature
1 parent 930b496 commit 63ae080

File tree

2 files changed

+16
-44
lines changed

2 files changed

+16
-44
lines changed

src/__core.rs

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,20 @@
11
/// Temporary fork of some stuff in `core` that's doesn't have a `const fn` API
22
33
pub mod mem {
4-
pub use core::mem::{replace, zeroed};
4+
#[cfg(not(feature = "const-fn"))]
5+
pub use core::mem::uninitialized;
6+
pub use core::mem::{replace, zeroed, ManuallyDrop};
57

6-
use core::ops::{Deref, DerefMut};
7-
8-
#[allow(unions_with_drop_fields)]
9-
pub union ManuallyDrop<T> {
10-
value: T,
11-
}
12-
13-
impl<T> ManuallyDrop<T> {
14-
#[inline]
15-
const_fn!(
16-
pub const fn new(value: T) -> ManuallyDrop<T> {
17-
ManuallyDrop { value: value }
18-
}
19-
);
20-
}
21-
22-
impl<T> Deref for ManuallyDrop<T> {
23-
type Target = T;
24-
25-
#[inline]
26-
fn deref(&self) -> &Self::Target {
27-
unsafe { &self.value }
8+
#[cfg(feature = "const-fn")]
9+
pub const unsafe fn uninitialized<T>() -> T {
10+
#[allow(unions_with_drop_fields)]
11+
union U<T> {
12+
none: (),
13+
some: T,
2814
}
29-
}
3015

31-
impl<T> DerefMut for ManuallyDrop<T> {
32-
#[inline]
33-
fn deref_mut(&mut self) -> &mut Self::Target {
34-
unsafe { &mut self.value }
35-
}
16+
U { none: () }.some
3617
}
37-
38-
const_fn!(
39-
pub const unsafe fn uninitialized<T>() -> T {
40-
#[allow(unions_with_drop_fields)]
41-
union U<T> {
42-
none: (),
43-
some: T,
44-
}
45-
46-
U { none: () }.some
47-
}
48-
);
4918
}
5019

5120
#[cfg(feature = "const-fn")] // Remove this if there are more tests
@@ -61,14 +30,16 @@ mod test {
6130
static mut I: i32 = unsafe { __core::mem::uninitialized() };
6231
// Initialize before drop
6332
unsafe { core::ptr::write(&mut I as *mut i32, 42) };
64-
unsafe{ assert_eq!(I, 42) };
33+
unsafe { assert_eq!(I, 42) };
6534
}
6635

6736
#[cfg(feature = "const-fn")]
6837
#[test]
6938
fn static_new_manually_drop() {
7039
static mut M: ManuallyDrop<i32> = ManuallyDrop::new(42);
71-
unsafe { assert_eq!(*M, 42); }
40+
unsafe {
41+
assert_eq!(*M, 42);
42+
}
7243
// Drop before deinitialization
7344
unsafe { core::ptr::drop_in_place(&mut M as &mut i32 as *mut i32) };
7445
}

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@
8383
#![deny(missing_docs)]
8484
#![deny(warnings)]
8585
#![cfg_attr(feature = "const-fn", feature(const_fn))]
86+
#![cfg_attr(feature = "const-fn", feature(const_manually_drop_new))]
87+
#![cfg_attr(feature = "const-fn", feature(untagged_unions))]
8688
#![cfg_attr(feature = "smaller-atomics", feature(core_intrinsics))]
87-
#![feature(untagged_unions)]
8889
#![no_std]
8990

9091
extern crate generic_array;

0 commit comments

Comments
 (0)