48: move more feature gates behind a Cargo feature r=japaric a=japaric



Co-authored-by: Jorge Aparicio <jorge@japaric.io>
This commit is contained in:
bors[bot] 2018-07-14 00:18:32 +00:00
commit e2fbadfd30
4 changed files with 46 additions and 55 deletions

View File

@ -2,6 +2,19 @@ language: rust
matrix:
include:
- env: TARGET=x86_64-unknown-linux-gnu
rust: beta
if: branch != master
# wait for 1.29-beta
# - env: TARGET=thumbv6m-none-eabi
# rust: beta
# if: branch != master
- env: TARGET=thumbv7m-none-eabi
rust: beta
if: branch != master
- env: TARGET=x86_64-unknown-linux-gnu
rust: nightly

View File

@ -1,22 +1,28 @@
set -euxo pipefail
main() {
cargo check --target $TARGET
cargo check --target $TARGET --no-default-features
if [ $TRAVIS_RUST_VERSION = nightly ]; then
cargo check --target $TARGET
fi
if [ $TARGET = x86_64-unknown-linux-gnu ]; then
cargo test --target $TARGET
cargo test --target $TARGET --no-default-features
cargo test --target $TARGET --release
cargo test --target $TARGET --release --no-default-features
export RUSTFLAGS="-Z sanitizer=thread"
export RUST_TEST_THREADS=1
export TSAN_OPTIONS="suppressions=$(pwd)/blacklist.txt"
if [ $TRAVIS_RUST_VERSION = nightly ]; then
cargo test --target $TARGET
cargo test --target $TARGET --release
cargo test --test tsan --target $TARGET
cargo test --test tsan --target $TARGET --no-default-features
cargo test --test tsan --target $TARGET --release
cargo test --test tsan --target $TARGET --release --no-default-features
export RUSTFLAGS="-Z sanitizer=thread"
export RUST_TEST_THREADS=1
export TSAN_OPTIONS="suppressions=$(pwd)/blacklist.txt"
cargo test --test tsan --target $TARGET
cargo test --test tsan --target $TARGET --no-default-features
cargo test --test tsan --target $TARGET --release
cargo test --test tsan --target $TARGET --release --no-default-features
fi
fi
}

View File

@ -1,51 +1,20 @@
/// Temporary fork of some stuff in `core` that's doesn't have a `const fn` API
pub mod mem {
pub use core::mem::{replace, zeroed};
#[cfg(not(feature = "const-fn"))]
pub use core::mem::uninitialized;
pub use core::mem::{replace, zeroed, ManuallyDrop};
use core::ops::{Deref, DerefMut};
#[allow(unions_with_drop_fields)]
pub union ManuallyDrop<T> {
value: T,
}
impl<T> ManuallyDrop<T> {
#[inline]
const_fn!(
pub const fn new(value: T) -> ManuallyDrop<T> {
ManuallyDrop { value: value }
}
);
}
impl<T> Deref for ManuallyDrop<T> {
type Target = T;
#[inline]
fn deref(&self) -> &Self::Target {
unsafe { &self.value }
#[cfg(feature = "const-fn")]
pub const unsafe fn uninitialized<T>() -> T {
#[allow(unions_with_drop_fields)]
union U<T> {
none: (),
some: T,
}
U { none: () }.some
}
impl<T> DerefMut for ManuallyDrop<T> {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut self.value }
}
}
const_fn!(
pub const unsafe fn uninitialized<T>() -> T {
#[allow(unions_with_drop_fields)]
union U<T> {
none: (),
some: T,
}
U { none: () }.some
}
);
}
#[cfg(feature = "const-fn")] // Remove this if there are more tests
@ -61,14 +30,16 @@ mod test {
static mut I: i32 = unsafe { __core::mem::uninitialized() };
// Initialize before drop
unsafe { core::ptr::write(&mut I as *mut i32, 42) };
unsafe{ assert_eq!(I, 42) };
unsafe { assert_eq!(I, 42) };
}
#[cfg(feature = "const-fn")]
#[test]
fn static_new_manually_drop() {
static mut M: ManuallyDrop<i32> = ManuallyDrop::new(42);
unsafe { assert_eq!(*M, 42); }
unsafe {
assert_eq!(*M, 42);
}
// Drop before deinitialization
unsafe { core::ptr::drop_in_place(&mut M as &mut i32 as *mut i32) };
}

View File

@ -83,8 +83,9 @@
#![deny(missing_docs)]
#![deny(warnings)]
#![cfg_attr(feature = "const-fn", feature(const_fn))]
#![cfg_attr(feature = "const-fn", feature(const_manually_drop_new))]
#![cfg_attr(feature = "const-fn", feature(untagged_unions))]
#![cfg_attr(feature = "smaller-atomics", feature(core_intrinsics))]
#![feature(untagged_unions)]
#![no_std]
extern crate generic_array;