Skip to content

Commit e2fbadf

Browse files
bors[bot]japaric
andcommitted
Merge #48
48: move more feature gates behind a Cargo feature r=japaric a=japaric Co-authored-by: Jorge Aparicio <[email protected]>
2 parents 930b496 + baacdf7 commit e2fbadf

File tree

4 files changed

+45
-54
lines changed

4 files changed

+45
-54
lines changed

.travis.yml

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ language: rust
22

33
matrix:
44
include:
5+
- env: TARGET=x86_64-unknown-linux-gnu
6+
rust: beta
7+
if: branch != master
8+
9+
# wait for 1.29-beta
10+
# - env: TARGET=thumbv6m-none-eabi
11+
# rust: beta
12+
# if: branch != master
13+
14+
- env: TARGET=thumbv7m-none-eabi
15+
rust: beta
16+
if: branch != master
17+
518
- env: TARGET=x86_64-unknown-linux-gnu
619
rust: nightly
720

ci/script.sh

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
set -euxo pipefail
22

33
main() {
4-
cargo check --target $TARGET
4+
cargo check --target $TARGET --no-default-features
5+
if [ $TRAVIS_RUST_VERSION = nightly ]; then
6+
cargo check --target $TARGET
7+
fi
58

69
if [ $TARGET = x86_64-unknown-linux-gnu ]; then
7-
cargo test --target $TARGET
810
cargo test --target $TARGET --no-default-features
9-
cargo test --target $TARGET --release
1011
cargo test --target $TARGET --release --no-default-features
1112

12-
export RUSTFLAGS="-Z sanitizer=thread"
13-
export RUST_TEST_THREADS=1
14-
export TSAN_OPTIONS="suppressions=$(pwd)/blacklist.txt"
13+
if [ $TRAVIS_RUST_VERSION = nightly ]; then
14+
cargo test --target $TARGET
15+
cargo test --target $TARGET --release
16+
17+
export RUSTFLAGS="-Z sanitizer=thread"
18+
export RUST_TEST_THREADS=1
19+
export TSAN_OPTIONS="suppressions=$(pwd)/blacklist.txt"
1520

16-
cargo test --test tsan --target $TARGET
17-
cargo test --test tsan --target $TARGET --no-default-features
18-
cargo test --test tsan --target $TARGET --release
19-
cargo test --test tsan --target $TARGET --release --no-default-features
21+
cargo test --test tsan --target $TARGET
22+
cargo test --test tsan --target $TARGET --no-default-features
23+
cargo test --test tsan --target $TARGET --release
24+
cargo test --test tsan --target $TARGET --release --no-default-features
25+
fi
2026
fi
2127
}
2228

src/__core.rs

+14-43
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

+2-1
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)