From 8350ac6afb2d678b74581000a6aafe1994b72231 Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Wed, 16 Jan 2019 17:26:30 -0800 Subject: Update nitrokey crate to 0.3.3 This change updates the nitrokey crate to version 0.3.3. Along with that change we update rand to 0.6.4 because rand 0.6.1 does not yet contain a publicly accessible rand_os. Note that we no longer require all crates in rand's workspace, but only rand_os and rand_core, which is a significant reduction in the number of lines of code compiled. Import subrepo nitrokey/:nitrokey at 7cf747d56ddc0b7eeedc3caf36dcc909907a171c Import subrepo rand/:rand at 4336232dda03323634b10ec72ddf27914aebc3a2 --- rand/src/distributions/uniform.rs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'rand/src/distributions/uniform.rs') diff --git a/rand/src/distributions/uniform.rs b/rand/src/distributions/uniform.rs index 5fb89e3..ceed77d 100644 --- a/rand/src/distributions/uniform.rs +++ b/rand/src/distributions/uniform.rs @@ -111,7 +111,7 @@ #[cfg(feature = "std")] use std::time::Duration; -#[cfg(all(not(feature = "std"), rust_1_25))] +#[cfg(all(not(feature = "std"), rustc_1_25))] use core::time::Duration; use Rng; @@ -277,7 +277,7 @@ impl From<::core::ops::Range> for Uniform { } } -#[cfg(rust_1_27)] +#[cfg(rustc_1_27)] impl From<::core::ops::RangeInclusive> for Uniform { fn from(r: ::core::ops::RangeInclusive) -> Uniform { Uniform::new_inclusive(r.start(), r.end()) @@ -452,8 +452,9 @@ macro_rules! uniform_int_impl { let ints_to_reject = (unsigned_max - range + 1) % range; unsigned_max - ints_to_reject } else { - // conservative but fast approximation - range << range.leading_zeros() + // conservative but fast approximation. `- 1` is necessary to allow the + // same comparison without bias. + (range << range.leading_zeros()).wrapping_sub(1) }; loop { @@ -472,7 +473,7 @@ uniform_int_impl! { i8, i8, u8, i32, u32 } uniform_int_impl! { i16, i16, u16, i32, u32 } uniform_int_impl! { i32, i32, u32, i32, u32 } uniform_int_impl! { i64, i64, u64, i64, u64 } -#[cfg(rust_1_26)] +#[cfg(all(rustc_1_26, not(target_os = "emscripten")))] uniform_int_impl! { i128, i128, u128, u128, u128 } uniform_int_impl! { isize, isize, usize, isize, usize } uniform_int_impl! { u8, i8, u8, i32, u32 } @@ -480,7 +481,7 @@ uniform_int_impl! { u16, i16, u16, i32, u32 } uniform_int_impl! { u32, i32, u32, i32, u32 } uniform_int_impl! { u64, i64, u64, i64, u64 } uniform_int_impl! { usize, isize, usize, isize, usize } -#[cfg(rust_1_26)] +#[cfg(all(rustc_1_26, not(target_os = "emscripten")))] uniform_int_impl! { u128, u128, u128, i128, u128 } #[cfg(all(feature = "simd_support", feature = "nightly"))] @@ -835,14 +836,14 @@ uniform_float_impl! { f64x8, u64x8, f64, u64, 64 - 52 } /// /// [`UniformSampler`]: trait.UniformSampler.html /// [`Uniform`]: struct.Uniform.html -#[cfg(any(feature = "std", rust_1_25))] +#[cfg(any(feature = "std", rustc_1_25))] #[derive(Clone, Copy, Debug)] pub struct UniformDuration { mode: UniformDurationMode, offset: u32, } -#[cfg(any(feature = "std", rust_1_25))] +#[cfg(any(feature = "std", rustc_1_25))] #[derive(Debug, Copy, Clone)] enum UniformDurationMode { Small { @@ -859,12 +860,12 @@ enum UniformDurationMode { } } -#[cfg(any(feature = "std", rust_1_25))] +#[cfg(any(feature = "std", rustc_1_25))] impl SampleUniform for Duration { type Sampler = UniformDuration; } -#[cfg(any(feature = "std", rust_1_25))] +#[cfg(any(feature = "std", rustc_1_25))] impl UniformSampler for UniformDuration { type X = Duration; @@ -989,7 +990,7 @@ mod tests { fn test_integers() { use core::{i8, i16, i32, i64, isize}; use core::{u8, u16, u32, u64, usize}; - #[cfg(rust_1_26)] + #[cfg(all(rustc_1_26, not(target_os = "emscripten")))] use core::{i128, u128}; let mut rng = ::test::rng(251); @@ -1053,7 +1054,7 @@ mod tests { } t!(i8, i16, i32, i64, isize, u8, u16, u32, u64, usize); - #[cfg(rust_1_26)] + #[cfg(all(rustc_1_26, not(target_os = "emscripten")))] t!(i128, u128); #[cfg(all(feature = "simd_support", feature = "nightly"))] @@ -1208,11 +1209,11 @@ mod tests { #[test] - #[cfg(any(feature = "std", rust_1_25))] + #[cfg(any(feature = "std", rustc_1_25))] fn test_durations() { #[cfg(feature = "std")] use std::time::Duration; - #[cfg(all(not(feature = "std"), rust_1_25))] + #[cfg(all(not(feature = "std"), rustc_1_25))] use core::time::Duration; let mut rng = ::test::rng(253); @@ -1283,7 +1284,7 @@ mod tests { assert_eq!(r.inner.scale, 5.0); } - #[cfg(rust_1_27)] + #[cfg(rustc_1_27)] #[test] fn test_uniform_from_std_range_inclusive() { let r = Uniform::from(2u32..=6); -- cgit v1.2.1