From 76fdbb42c5f0f842abe032a4ae0aa201c5935455 Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Wed, 6 Feb 2019 01:31:50 -0800 Subject: [PATCH] Simplify #![cfg()] and #![cfg_attr()] --- src/lib.rs | 15 ++------------- src/rand.rs | 19 +++++++++---------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 62e956bba3..2c9a6b1fb7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -59,19 +59,8 @@ unused_results, warnings )] -#![cfg_attr( - any( - target_os = "redox", - all( - not(test), - not(feature = "use_heap"), - unix, - not(any(target_os = "macos", target_os = "ios")), - any(not(target_os = "linux"), feature = "dev_urandom_fallback") - ) - ), - no_std -)] +// std is only used in tests or when gated with #[cfg(use_heap)] +#![cfg_attr(not(any(test, feature = "use_heap")), no_std)] #![cfg_attr(feature = "internal_benches", allow(unstable_features))] #![cfg_attr(feature = "internal_benches", feature(test))] diff --git a/src/rand.rs b/src/rand.rs index b6fb6bc4ca..eed90a384d 100644 --- a/src/rand.rs +++ b/src/rand.rs @@ -100,14 +100,14 @@ impl sealed::Sealed for SystemRandom {} target_os = "macos", target_os = "ios", target_os = "fuchsia", - windows + target_os = "windows" )) ))] use self::urandom::fill as fill_impl; #[cfg(any( all(target_os = "linux", not(feature = "dev_urandom_fallback")), - windows + target_os = "windows", ))] use self::sysrand::fill as fill_impl; @@ -158,7 +158,7 @@ mod sysrand_chunk { } } -#[cfg(windows)] +#[cfg(target_os = "windows")] mod sysrand_chunk { use crate::{error, polyfill}; use core; @@ -183,7 +183,7 @@ mod sysrand_chunk { } } -#[cfg(any(target_os = "linux", windows))] +#[cfg(any(target_os = "linux", target_os = "windows"))] mod sysrand { use super::sysrand_chunk::chunk; use crate::error; @@ -198,13 +198,13 @@ mod sysrand { } } -// Keep the `cfg` conditions in sync with the conditions in lib.rs. #[cfg(all( feature = "use_heap", - any(target_os = "redox", unix), - not(any(target_os = "macos", target_os = "ios")), not(all(target_os = "linux", not(feature = "dev_urandom_fallback"))), - not(any(target_os = "fuchsia")), + not(target_os = "macos"), + not(target_os = "ios"), + not(target_os = "fuchsia"), + not(target_os = "windows"), ))] mod urandom { use crate::error; @@ -215,7 +215,7 @@ mod urandom { #[cfg(target_os = "redox")] static RANDOM_PATH: &str = "rand:"; - #[cfg(unix)] + #[cfg(not(target_os = "redox"))] static RANDOM_PATH: &str = "/dev/urandom"; lazy_static! { @@ -233,7 +233,6 @@ mod urandom { } } -// Keep the `cfg` conditions in sync with the conditions in lib.rs. #[cfg(all(target_os = "linux", feature = "dev_urandom_fallback"))] mod sysrand_or_urandom { use crate::error;