diff --git a/Cargo.toml b/Cargo.toml index 46d9d966e95..c20fb995495 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,9 +12,9 @@ Random number generators and other randomness functionality. """ keywords = ["random", "rng"] categories = ["algorithms", "no-std"] -build = "build.rs" exclude = ["/utils/*", "/.travis.yml", "/appveyor.yml", ".gitignore"] autobenches = true +edition = "2018" [badges] travis-ci = { repository = "rust-random/rand" } @@ -86,8 +86,5 @@ rand_xoshiro = { path = "rand_xoshiro", version = "0.3" } rand_isaac = { path = "rand_isaac", version = "0.2" } rand_xorshift = { path = "rand_xorshift", version = "0.2" } -[build-dependencies] -autocfg = "0.1" - [package.metadata.docs.rs] all-features = true diff --git a/benches/generators.rs b/benches/generators.rs index 0e83401a2df..b9038816733 100644 --- a/benches/generators.rs +++ b/benches/generators.rs @@ -10,13 +10,6 @@ #![allow(non_snake_case)] extern crate test; -extern crate rand; -extern crate rand_isaac; -extern crate rand_chacha; -extern crate rand_hc; -extern crate rand_pcg; -extern crate rand_xorshift; -extern crate rand_xoshiro; const RAND_BENCH_N: u64 = 1000; const BYTES_LEN: usize = 1024; diff --git a/benches/misc.rs b/benches/misc.rs index 99e43b9bf99..40986863482 100644 --- a/benches/misc.rs +++ b/benches/misc.rs @@ -9,8 +9,6 @@ #![feature(test)] extern crate test; -extern crate rand; -extern crate rand_pcg; const RAND_BENCH_N: u64 = 1000; @@ -25,7 +23,7 @@ fn misc_gen_bool_const(b: &mut Bencher) { let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap(); b.iter(|| { let mut accum = true; - for _ in 0..::RAND_BENCH_N { + for _ in 0..crate::RAND_BENCH_N { accum ^= rng.gen_bool(0.18); } accum @@ -38,7 +36,7 @@ fn misc_gen_bool_var(b: &mut Bencher) { b.iter(|| { let mut accum = true; let mut p = 0.18; - for _ in 0..::RAND_BENCH_N { + for _ in 0..crate::RAND_BENCH_N { accum ^= rng.gen_bool(p); p += 0.0001; } @@ -51,7 +49,7 @@ fn misc_gen_ratio_const(b: &mut Bencher) { let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap(); b.iter(|| { let mut accum = true; - for _ in 0..::RAND_BENCH_N { + for _ in 0..crate::RAND_BENCH_N { accum ^= rng.gen_ratio(2, 3); } accum @@ -63,7 +61,7 @@ fn misc_gen_ratio_var(b: &mut Bencher) { let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap(); b.iter(|| { let mut accum = true; - for i in 2..(::RAND_BENCH_N as u32 + 2) { + for i in 2..(crate::RAND_BENCH_N as u32 + 2) { accum ^= rng.gen_ratio(i, i + 1); } accum @@ -76,7 +74,7 @@ fn misc_bernoulli_const(b: &mut Bencher) { b.iter(|| { let d = rand::distributions::Bernoulli::new(0.18).unwrap(); let mut accum = true; - for _ in 0..::RAND_BENCH_N { + for _ in 0..crate::RAND_BENCH_N { accum ^= rng.sample(d); } accum @@ -89,7 +87,7 @@ fn misc_bernoulli_var(b: &mut Bencher) { b.iter(|| { let mut accum = true; let mut p = 0.18; - for _ in 0..::RAND_BENCH_N { + for _ in 0..crate::RAND_BENCH_N { let d = Bernoulli::new(p).unwrap(); accum ^= rng.sample(d); p += 0.0001; diff --git a/benches/seq.rs b/benches/seq.rs index e426ffbb4c2..4c671b8aad8 100644 --- a/benches/seq.rs +++ b/benches/seq.rs @@ -10,8 +10,6 @@ #![allow(non_snake_case)] extern crate test; -extern crate rand; -extern crate rand_pcg; use test::Bencher; @@ -49,7 +47,7 @@ fn seq_slice_choose_1_of_1000(b: &mut Bencher) { } s }); - b.bytes = size_of::() as u64 * ::RAND_BENCH_N; + b.bytes = size_of::() as u64 * crate::RAND_BENCH_N; } macro_rules! seq_slice_choose_multiple { @@ -91,7 +89,7 @@ fn seq_iter_choose_from_1000(b: &mut Bencher) { } s }); - b.bytes = size_of::() as u64 * ::RAND_BENCH_N; + b.bytes = size_of::() as u64 * crate::RAND_BENCH_N; } #[derive(Clone)] diff --git a/build.rs b/build.rs deleted file mode 100644 index c5085c98041..00000000000 --- a/build.rs +++ /dev/null @@ -1,11 +0,0 @@ -extern crate autocfg; - -fn main() { - println!("cargo:rerun-if-changed=build.rs"); - - let ac = autocfg::new(); - ac.emit_rustc_version(1, 25); - ac.emit_rustc_version(1, 26); - ac.emit_rustc_version(1, 27); - ac.emit_rustc_version(1, 28); -} diff --git a/examples/monte-carlo.rs b/examples/monte-carlo.rs index b79c6a5afa0..39c779f40cd 100644 --- a/examples/monte-carlo.rs +++ b/examples/monte-carlo.rs @@ -26,9 +26,6 @@ #![cfg(feature = "std")] - -extern crate rand; - use rand::distributions::{Distribution, Uniform}; fn main() { diff --git a/examples/monty-hall.rs b/examples/monty-hall.rs index 643fbb5116e..9fe58394aef 100644 --- a/examples/monty-hall.rs +++ b/examples/monty-hall.rs @@ -28,9 +28,6 @@ #![cfg(feature = "std")] - -extern crate rand; - use rand::distributions::{Distribution, Uniform}; use rand::Rng; diff --git a/rand_chacha/Cargo.toml b/rand_chacha/Cargo.toml index 84acf5a580c..90163a7c93f 100644 --- a/rand_chacha/Cargo.toml +++ b/rand_chacha/Cargo.toml @@ -12,7 +12,7 @@ ChaCha random number generator """ keywords = ["random", "rng", "chacha"] categories = ["algorithms", "no-std"] -build = "build.rs" +edition = "2018" [badges] travis-ci = { repository = "rust-random/rand" } @@ -22,9 +22,6 @@ appveyor = { repository = "rust-random/rand" } rand_core = { path = "../rand_core", version = "0.5" } c2-chacha = { version = "0.2.2", default-features = false } -[build-dependencies] -autocfg = "0.1" - [features] default = ["std", "simd"] std = ["c2-chacha/std"] diff --git a/rand_chacha/build.rs b/rand_chacha/build.rs deleted file mode 100644 index 06e12a47b6e..00000000000 --- a/rand_chacha/build.rs +++ /dev/null @@ -1,7 +0,0 @@ -extern crate autocfg; - -fn main() { - println!("cargo:rerun-if-changed=build.rs"); - let ac = autocfg::new(); - ac.emit_rustc_version(1, 26); -} diff --git a/rand_chacha/src/lib.rs b/rand_chacha/src/lib.rs index ff915b5787a..e374bddf321 100644 --- a/rand_chacha/src/lib.rs +++ b/rand_chacha/src/lib.rs @@ -18,12 +18,11 @@ #![cfg_attr(not(feature = "std"), no_std)] -extern crate c2_chacha; -pub extern crate rand_core; +pub use rand_core; mod chacha; -pub use chacha::{ChaCha12Core, ChaCha12Rng, ChaCha20Core, ChaCha20Rng, ChaCha8Core, ChaCha8Rng}; +pub use crate::chacha::{ChaCha12Core, ChaCha12Rng, ChaCha20Core, ChaCha20Rng, ChaCha8Core, ChaCha8Rng}; /// ChaCha with 20 rounds pub type ChaChaRng = ChaCha20Rng; diff --git a/rand_core/Cargo.toml b/rand_core/Cargo.toml index dbbc5c5be6c..0830fcdc6d4 100644 --- a/rand_core/Cargo.toml +++ b/rand_core/Cargo.toml @@ -12,6 +12,7 @@ Core random number generator traits and tools for implementation. """ keywords = ["random", "rng"] categories = ["algorithms", "no-std"] +edition = "2018" [badges] travis-ci = { repository = "rust-random/rand" } @@ -20,9 +21,8 @@ appveyor = { repository = "rust-random/rand" } [features] std = ["alloc", "getrandom", "getrandom/std"] # use std library; should be default but for above bug alloc = [] # enables Vec and Box support without std -serde1 = ["serde", "serde_derive"] # enables serde for BlockRng wrapper +serde1 = ["serde"] # enables serde for BlockRng wrapper [dependencies] -serde = { version = "1", optional = true } -serde_derive = { version = "^1.0.38", optional = true } +serde = { version = "1", features = ["derive"], optional = true } getrandom = { version = "0.1", optional = true } diff --git a/rand_core/src/block.rs b/rand_core/src/block.rs index e4f07e74bc7..7d222784337 100644 --- a/rand_core/src/block.rs +++ b/rand_core/src/block.rs @@ -52,8 +52,9 @@ use core::convert::AsRef; use core::{fmt, ptr}; -use {RngCore, CryptoRng, SeedableRng, Error}; -use impls::{fill_via_u32_chunks, fill_via_u64_chunks}; +#[cfg(feature="serde1")] use serde::{Serialize, Deserialize}; +use crate::{RngCore, CryptoRng, SeedableRng, Error}; +use crate::impls::{fill_via_u32_chunks, fill_via_u64_chunks}; /// A trait for RNGs which do not generate random numbers individually, but in /// blocks (typically `[u32; N]`). This technique is commonly used by diff --git a/rand_core/src/impls.rs b/rand_core/src/impls.rs index 57bdd070d08..4978ae42d2a 100644 --- a/rand_core/src/impls.rs +++ b/rand_core/src/impls.rs @@ -22,7 +22,7 @@ use core::ptr::copy_nonoverlapping; use core::slice; use core::cmp::min; use core::mem::size_of; -use RngCore; +use crate::RngCore; /// Implement `next_u64` via `next_u32`, little-endian order. diff --git a/rand_core/src/lib.rs b/rand_core/src/lib.rs index 7472a666038..e210b5eca37 100644 --- a/rand_core/src/lib.rs +++ b/rand_core/src/lib.rs @@ -38,16 +38,12 @@ #![cfg_attr(not(feature="std"), no_std)] #![cfg_attr(all(feature="alloc", not(feature="std")), feature(alloc))] -#[cfg(feature="std")] extern crate core; -#[cfg(all(feature = "alloc", not(feature="std")))] extern crate alloc; -#[cfg(feature="serde1")] extern crate serde; -#[cfg(feature="serde1")] #[macro_use] extern crate serde_derive; - use core::default::Default; use core::convert::AsMut; use core::ptr::copy_nonoverlapping; +#[cfg(all(feature="alloc", not(feature="std")))] extern crate alloc; #[cfg(all(feature="alloc", not(feature="std")))] use alloc::boxed::Box; pub use error::Error; @@ -435,7 +431,7 @@ impl RngCore for Box { } #[cfg(feature="std")] -impl std::io::Read for RngCore { +impl std::io::Read for dyn RngCore { fn read(&mut self, buf: &mut [u8]) -> Result { self.try_fill_bytes(buf)?; Ok(buf.len()) diff --git a/rand_distr/benches/distributions.rs b/rand_distr/benches/distributions.rs index 893ac4706f0..63bde367060 100644 --- a/rand_distr/benches/distributions.rs +++ b/rand_distr/benches/distributions.rs @@ -8,8 +8,6 @@ #![feature(test)] -extern crate test; - const RAND_BENCH_N: u64 = 1000; use std::mem::size_of; diff --git a/rand_jitter/Cargo.toml b/rand_jitter/Cargo.toml index 64cc523fa87..7380f702ebb 100644 --- a/rand_jitter/Cargo.toml +++ b/rand_jitter/Cargo.toml @@ -8,6 +8,7 @@ repository = "https://github.com/rust-random/rand" documentation = "https://docs.rs/rand_jitter" description = "Random number generator based on timing jitter" keywords = ["random", "rng", "os"] +edition = "2018" [badges] travis-ci = { repository = "rust-random/rand" } diff --git a/rand_jitter/benches/mod.rs b/rand_jitter/benches/mod.rs index 23b34472bdc..bf7c8a27465 100644 --- a/rand_jitter/benches/mod.rs +++ b/rand_jitter/benches/mod.rs @@ -1,6 +1,5 @@ #![feature(test)] -extern crate test; -extern crate rand_jitter; +#![cfg(std)] use test::Bencher; use rand_jitter::rand_core::RngCore; diff --git a/rand_jitter/src/dummy_log.rs b/rand_jitter/src/dummy_log.rs deleted file mode 100644 index ccfe4baeff2..00000000000 --- a/rand_jitter/src/dummy_log.rs +++ /dev/null @@ -1,10 +0,0 @@ -#[allow(unused)] -macro_rules! trace { ($($x:tt)*) => () } -#[allow(unused)] -macro_rules! debug { ($($x:tt)*) => () } -#[allow(unused)] -macro_rules! info { ($($x:tt)*) => () } -#[allow(unused)] -macro_rules! warn { ($($x:tt)*) => () } -#[allow(unused)] -macro_rules! error { ($($x:tt)*) => () } diff --git a/rand_jitter/src/lib.rs b/rand_jitter/src/lib.rs index 450f5810754..49c53e6fbfd 100644 --- a/rand_jitter/src/lib.rs +++ b/rand_jitter/src/lib.rs @@ -54,15 +54,10 @@ // compiler not optimize out code which does influence timing jitter, but is // technically dead code. #![no_std] -pub extern crate rand_core; #[cfg(feature = "std")] extern crate std; -#[cfg(feature = "log")] -#[macro_use] extern crate log; -#[cfg(any(target_os = "macos", target_os = "ios"))] -extern crate libc; -#[cfg(target_os = "windows")] -extern crate winapi; + +pub use rand_core; // Coming from https://crates.io/crates/doc-comment #[cfg(test)] @@ -76,21 +71,47 @@ macro_rules! doc_comment { #[cfg(test)] doc_comment!(include_str!("../README.md")); -#[cfg(not(feature = "log"))] -#[macro_use] mod dummy_log; +#[allow(unused)] +macro_rules! trace { ($($x:tt)*) => ( + #[cfg(feature = "log")] { + log::trace!($($x)*) + } +) } +#[allow(unused)] +macro_rules! debug { ($($x:tt)*) => ( + #[cfg(feature = "log")] { + log::debug!($($x)*) + } +) } +#[allow(unused)] +macro_rules! info { ($($x:tt)*) => ( + #[cfg(feature = "log")] { + log::info!($($x)*) + } +) } +#[allow(unused)] +macro_rules! warn { ($($x:tt)*) => ( + #[cfg(feature = "log")] { + log::warn!($($x)*) + } +) } +#[allow(unused)] +macro_rules! error { ($($x:tt)*) => ( + #[cfg(feature = "log")] { + log::error!($($x)*) + } +) } + #[cfg(feature = "std")] mod platform; mod error; use rand_core::{RngCore, Error, impls}; -pub use error::TimerError; +pub use crate::error::TimerError; use core::{fmt, mem, ptr}; #[cfg(feature = "std")] use std::sync::atomic::{AtomicUsize, Ordering}; -#[cfg(feature = "std")] -#[allow(deprecated)] // Required for compatibility with Rust < 1.24. -use std::sync::atomic::ATOMIC_USIZE_INIT; const MEMORY_BLOCKS: usize = 64; const MEMORY_BLOCKSIZE: usize = 32; @@ -185,8 +206,7 @@ impl Clone for JitterRng { // Initialise to zero; must be positive #[cfg(all(feature = "std", not(target_arch = "wasm32")))] -#[allow(deprecated)] -static JITTER_ROUNDS: AtomicUsize = ATOMIC_USIZE_INIT; +static JITTER_ROUNDS: AtomicUsize = AtomicUsize::new(0); impl JitterRng { /// Create a new `JitterRng`. Makes use of `std::time` for a timer, or a diff --git a/rand_jitter/tests/mod.rs b/rand_jitter/tests/mod.rs index 6820c2080a5..961dc27d31b 100644 --- a/rand_jitter/tests/mod.rs +++ b/rand_jitter/tests/mod.rs @@ -1,6 +1,3 @@ -extern crate rand_jitter; -extern crate rand_core; - use rand_jitter::JitterRng; #[cfg(feature = "std")] use rand_core::RngCore; diff --git a/rand_pcg/Cargo.toml b/rand_pcg/Cargo.toml index e77c2c6730b..bfe2a1537c8 100644 --- a/rand_pcg/Cargo.toml +++ b/rand_pcg/Cargo.toml @@ -30,6 +30,3 @@ serde = { version = "1", features = ["derive"], optional = true } # deps yet, see: https://github.com/rust-lang/cargo/issues/1596 # We require at least 1.1.2 for i128 auto-detection bincode = { version = "1.1.2" } - -[build-dependencies] -autocfg = "0.1" diff --git a/rand_xoshiro/src/xoroshiro128plus.rs b/rand_xoshiro/src/xoroshiro128plus.rs index 243b427062d..a7b4ebc1267 100644 --- a/rand_xoshiro/src/xoroshiro128plus.rs +++ b/rand_xoshiro/src/xoroshiro128plus.rs @@ -36,8 +36,6 @@ impl Xoroshiro128Plus { /// parallel computations. /// /// ``` - /// # extern crate rand_xoshiro; - /// # fn main() { /// use rand_xoshiro::rand_core::SeedableRng; /// use rand_xoshiro::Xoroshiro128Plus; /// @@ -46,7 +44,6 @@ impl Xoroshiro128Plus { /// rng2.jump(); /// let mut rng3 = rng2.clone(); /// rng3.jump(); - /// # } /// ``` pub fn jump(&mut self) { impl_jump!(u64, self, [0xdf900294d8f554a5, 0x170865df4b3201fc]); diff --git a/rand_xoshiro/src/xoroshiro128starstar.rs b/rand_xoshiro/src/xoroshiro128starstar.rs index 32f13c8cb13..21823f50d8b 100644 --- a/rand_xoshiro/src/xoroshiro128starstar.rs +++ b/rand_xoshiro/src/xoroshiro128starstar.rs @@ -35,8 +35,6 @@ impl Xoroshiro128StarStar { /// parallel computations. /// /// ``` - /// # extern crate rand_xoshiro; - /// # fn main() { /// use rand_xoshiro::rand_core::SeedableRng; /// use rand_xoshiro::Xoroshiro128StarStar; /// @@ -45,7 +43,6 @@ impl Xoroshiro128StarStar { /// rng2.jump(); /// let mut rng3 = rng2.clone(); /// rng3.jump(); - /// # } /// ``` pub fn jump(&mut self) { impl_jump!(u64, self, [0xdf900294d8f554a5, 0x170865df4b3201fc]); diff --git a/rand_xoshiro/src/xoshiro128plus.rs b/rand_xoshiro/src/xoshiro128plus.rs index 9bcdaf32e5e..7cbd61249fb 100644 --- a/rand_xoshiro/src/xoshiro128plus.rs +++ b/rand_xoshiro/src/xoshiro128plus.rs @@ -33,8 +33,6 @@ impl Xoshiro128Plus { /// parallel computations. /// /// ``` - /// # extern crate rand_xoshiro; - /// # fn main() { /// use rand_xoshiro::rand_core::SeedableRng; /// use rand_xoshiro::Xoroshiro128StarStar; /// @@ -43,7 +41,6 @@ impl Xoshiro128Plus { /// rng2.jump(); /// let mut rng3 = rng2.clone(); /// rng3.jump(); - /// # } /// ``` pub fn jump(&mut self) { impl_jump!(u32, self, [0x8764000b, 0xf542d2d3, 0x6fa035c3, 0x77f2db5b]); diff --git a/rand_xoshiro/src/xoshiro128starstar.rs b/rand_xoshiro/src/xoshiro128starstar.rs index aa1c4bfa733..7af1e50ff0f 100644 --- a/rand_xoshiro/src/xoshiro128starstar.rs +++ b/rand_xoshiro/src/xoshiro128starstar.rs @@ -32,8 +32,6 @@ impl Xoshiro128StarStar { /// parallel computations. /// /// ``` - /// # extern crate rand_xoshiro; - /// # fn main() { /// use rand_xoshiro::rand_core::SeedableRng; /// use rand_xoshiro::Xoroshiro128StarStar; /// @@ -42,7 +40,6 @@ impl Xoshiro128StarStar { /// rng2.jump(); /// let mut rng3 = rng2.clone(); /// rng3.jump(); - /// # } /// ``` pub fn jump(&mut self) { impl_jump!(u32, self, [0x8764000b, 0xf542d2d3, 0x6fa035c3, 0x77f2db5b]); diff --git a/rand_xoshiro/src/xoshiro256plus.rs b/rand_xoshiro/src/xoshiro256plus.rs index 0821abc1067..396f5880e02 100644 --- a/rand_xoshiro/src/xoshiro256plus.rs +++ b/rand_xoshiro/src/xoshiro256plus.rs @@ -33,8 +33,6 @@ impl Xoshiro256Plus { /// parallel computations. /// /// ``` - /// # extern crate rand_xoshiro; - /// # fn main() { /// use rand_xoshiro::rand_core::SeedableRng; /// use rand_xoshiro::Xoshiro256Plus; /// @@ -43,7 +41,6 @@ impl Xoshiro256Plus { /// rng2.jump(); /// let mut rng3 = rng2.clone(); /// rng3.jump(); - /// # } /// ``` pub fn jump(&mut self) { impl_jump!(u64, self, [ diff --git a/rand_xoshiro/src/xoshiro256starstar.rs b/rand_xoshiro/src/xoshiro256starstar.rs index 2c9aacc079e..2cc2029141f 100644 --- a/rand_xoshiro/src/xoshiro256starstar.rs +++ b/rand_xoshiro/src/xoshiro256starstar.rs @@ -32,8 +32,6 @@ impl Xoshiro256StarStar { /// parallel computations. /// /// ``` - /// # extern crate rand_xoshiro; - /// # fn main() { /// use rand_xoshiro::rand_core::SeedableRng; /// use rand_xoshiro::Xoshiro256StarStar; /// @@ -42,7 +40,6 @@ impl Xoshiro256StarStar { /// rng2.jump(); /// let mut rng3 = rng2.clone(); /// rng3.jump(); - /// # } /// ``` pub fn jump(&mut self) { impl_jump!(u64, self, [ diff --git a/rand_xoshiro/src/xoshiro512plus.rs b/rand_xoshiro/src/xoshiro512plus.rs index 68ac385f49f..4b589f26898 100644 --- a/rand_xoshiro/src/xoshiro512plus.rs +++ b/rand_xoshiro/src/xoshiro512plus.rs @@ -35,8 +35,6 @@ impl Xoshiro512Plus { /// parallel computations. /// /// ``` - /// # extern crate rand_xoshiro; - /// # fn main() { /// use rand_xoshiro::rand_core::SeedableRng; /// use rand_xoshiro::Xoshiro512Plus; /// @@ -45,7 +43,6 @@ impl Xoshiro512Plus { /// rng2.jump(); /// let mut rng3 = rng2.clone(); /// rng3.jump(); - /// # } /// ``` pub fn jump(&mut self) { impl_jump!(u64, self, [ diff --git a/rand_xoshiro/src/xoshiro512starstar.rs b/rand_xoshiro/src/xoshiro512starstar.rs index 92fc5feccc6..2db9ac1fa2c 100644 --- a/rand_xoshiro/src/xoshiro512starstar.rs +++ b/rand_xoshiro/src/xoshiro512starstar.rs @@ -34,8 +34,6 @@ impl Xoshiro512StarStar { /// parallel computations. /// /// ``` - /// # extern crate rand_xoshiro; - /// # fn main() { /// use rand_xoshiro::rand_core::SeedableRng; /// use rand_xoshiro::Xoshiro512StarStar; /// @@ -44,7 +42,6 @@ impl Xoshiro512StarStar { /// rng2.jump(); /// let mut rng3 = rng2.clone(); /// rng3.jump(); - /// # } /// ``` pub fn jump(&mut self) { impl_jump!(u64, self, [ diff --git a/rand_xoshiro/tests/serde.rs b/rand_xoshiro/tests/serde.rs index 3dcca79c27b..ee23a1db447 100644 --- a/rand_xoshiro/tests/serde.rs +++ b/rand_xoshiro/tests/serde.rs @@ -1,9 +1,5 @@ #![cfg(feature="serde1")] -extern crate rand_xoshiro; -extern crate rand_core; -#[cfg(all(feature="serde1", test))] extern crate bincode; - use rand_core::{RngCore, SeedableRng}; use rand_xoshiro::{SplitMix64, Xoroshiro64StarStar, Xoroshiro64Star, Xoroshiro128Plus, Xoroshiro128StarStar, Xoshiro128StarStar, Xoshiro128Plus, diff --git a/rustfmt.toml b/rustfmt.toml index 4fe708f4c55..6b2aba35178 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -18,9 +18,7 @@ where_single_line = true # struct_field_align_threshold = 20 # Compatibility: -use_try_shorthand = true # stable since Rustc 1.13.0 -use_field_init_shorthand = true # stable since Rustc 1.17.0 -edition = "2015" # we require compatibility back to 1.22.0 +edition = "2018" # we require compatibility back to 1.32.0 # Misc: blank_lines_upper_bound = 2 diff --git a/src/distributions/bernoulli.rs b/src/distributions/bernoulli.rs index d0ef6b80073..f7bdae46947 100644 --- a/src/distributions/bernoulli.rs +++ b/src/distributions/bernoulli.rs @@ -8,8 +8,8 @@ //! The Bernoulli distribution. -use Rng; -use distributions::Distribution; +use crate::Rng; +use crate::distributions::Distribution; /// The Bernoulli distribution. /// @@ -119,13 +119,13 @@ impl Distribution for Bernoulli { #[cfg(test)] mod test { - use Rng; - use distributions::Distribution; + use crate::Rng; + use crate::distributions::Distribution; use super::Bernoulli; #[test] fn test_trivial() { - let mut r = ::test::rng(1); + let mut r = crate::test::rng(1); let always_false = Bernoulli::new(0.0).unwrap(); let always_true = Bernoulli::new(1.0).unwrap(); for _ in 0..5 { @@ -148,7 +148,7 @@ mod test { let mut sum1: u32 = 0; let mut sum2: u32 = 0; - let mut rng = ::test::rng(2); + let mut rng = crate::test::rng(2); for _ in 0..N { if d1.sample(&mut rng) { sum1 += 1; diff --git a/src/distributions/binomial.rs b/src/distributions/binomial.rs index 434b9d6425b..977e3ce026b 100644 --- a/src/distributions/binomial.rs +++ b/src/distributions/binomial.rs @@ -10,8 +10,8 @@ //! The binomial distribution. #![allow(deprecated)] -use Rng; -use distributions::{Distribution, Uniform}; +use crate::Rng; +use crate::distributions::{Distribution, Uniform}; /// The binomial distribution `Binomial(n, p)`. /// @@ -262,8 +262,8 @@ impl Distribution for Binomial { #[cfg(test)] mod test { - use Rng; - use distributions::Distribution; + use crate::Rng; + use crate::distributions::Distribution; use super::Binomial; fn test_binomial_mean_and_variance(n: u64, p: f64, rng: &mut R) { @@ -289,7 +289,7 @@ mod test { #[test] #[cfg(not(miri))] // Miri is too slow fn test_binomial() { - let mut rng = ::test::rng(351); + let mut rng = crate::test::rng(351); test_binomial_mean_and_variance(150, 0.1, &mut rng); test_binomial_mean_and_variance(70, 0.6, &mut rng); test_binomial_mean_and_variance(40, 0.5, &mut rng); @@ -299,7 +299,7 @@ mod test { #[test] fn test_binomial_end_points() { - let mut rng = ::test::rng(352); + let mut rng = crate::test::rng(352); assert_eq!(rng.sample(Binomial::new(20, 0.0)), 0); assert_eq!(rng.sample(Binomial::new(20, 1.0)), 20); } diff --git a/src/distributions/cauchy.rs b/src/distributions/cauchy.rs index 3ec9fee9651..61ea95dd02c 100644 --- a/src/distributions/cauchy.rs +++ b/src/distributions/cauchy.rs @@ -10,8 +10,8 @@ //! The Cauchy distribution. #![allow(deprecated)] -use Rng; -use distributions::Distribution; +use crate::Rng; +use crate::distributions::Distribution; use std::f64::consts::PI; /// The Cauchy distribution `Cauchy(median, scale)`. @@ -53,7 +53,7 @@ impl Distribution for Cauchy { #[cfg(test)] mod test { - use distributions::Distribution; + use crate::distributions::Distribution; use super::Cauchy; fn median(mut numbers: &mut [f64]) -> f64 { diff --git a/src/distributions/dirichlet.rs b/src/distributions/dirichlet.rs index 21269b686b0..e9352446128 100644 --- a/src/distributions/dirichlet.rs +++ b/src/distributions/dirichlet.rs @@ -10,9 +10,9 @@ //! The dirichlet distribution. #![allow(deprecated)] -use Rng; -use distributions::Distribution; -use distributions::gamma::Gamma; +use crate::Rng; +use crate::distributions::Distribution; +use crate::distributions::gamma::Gamma; /// The dirichelet distribution `Dirichlet(alpha)`. /// @@ -81,12 +81,12 @@ impl Distribution> for Dirichlet { #[cfg(test)] mod test { use super::Dirichlet; - use distributions::Distribution; + use crate::distributions::Distribution; #[test] fn test_dirichlet() { let d = Dirichlet::new(vec![1.0, 2.0, 3.0]); - let mut rng = ::test::rng(221); + let mut rng = crate::test::rng(221); let samples = d.sample(&mut rng); let _: Vec = samples .into_iter() @@ -102,7 +102,7 @@ mod test { let alpha = 0.5f64; let size = 2; let d = Dirichlet::new_with_param(alpha, size); - let mut rng = ::test::rng(221); + let mut rng = crate::test::rng(221); let samples = d.sample(&mut rng); let _: Vec = samples .into_iter() diff --git a/src/distributions/exponential.rs b/src/distributions/exponential.rs index 1637a1c4773..3859af65569 100644 --- a/src/distributions/exponential.rs +++ b/src/distributions/exponential.rs @@ -10,9 +10,9 @@ //! The exponential distribution. #![allow(deprecated)] -use {Rng}; -use distributions::{ziggurat_tables, Distribution}; -use distributions::utils::ziggurat; +use crate::{Rng}; +use crate::distributions::{ziggurat_tables, Distribution}; +use crate::distributions::utils::ziggurat; /// Samples floating-point numbers according to the exponential distribution, /// with rate parameter `λ = 1`. This is equivalent to `Exp::new(1.0)` or @@ -84,13 +84,13 @@ impl Distribution for Exp { #[cfg(test)] mod test { - use distributions::Distribution; + use crate::distributions::Distribution; use super::Exp; #[test] fn test_exp() { let exp = Exp::new(10.0); - let mut rng = ::test::rng(221); + let mut rng = crate::test::rng(221); for _ in 0..1000 { assert!(exp.sample(&mut rng) >= 0.0); } diff --git a/src/distributions/float.rs b/src/distributions/float.rs index fd40fed93ca..ca1e79d341d 100644 --- a/src/distributions/float.rs +++ b/src/distributions/float.rs @@ -9,9 +9,9 @@ //! Basic floating-point number distributions use core::mem; -use Rng; -use distributions::{Distribution, Standard}; -use distributions::utils::FloatSIMDUtils; +use crate::Rng; +use crate::distributions::{Distribution, Standard}; +use crate::distributions::utils::FloatSIMDUtils; #[cfg(feature="simd_support")] use packed_simd::*; @@ -170,9 +170,9 @@ float_impls! { f64x8, u64x8, f64, u64, 52, 1023 } #[cfg(test)] mod tests { - use Rng; - use distributions::{Open01, OpenClosed01}; - use rngs::mock::StepRng; + use crate::Rng; + use crate::distributions::{Open01, OpenClosed01}; + use crate::rngs::mock::StepRng; #[cfg(feature="simd_support")] use packed_simd::*; diff --git a/src/distributions/gamma.rs b/src/distributions/gamma.rs index 90f07cedfae..b5a97f52fad 100644 --- a/src/distributions/gamma.rs +++ b/src/distributions/gamma.rs @@ -13,9 +13,9 @@ use self::GammaRepr::*; use self::ChiSquaredRepr::*; -use Rng; -use distributions::normal::StandardNormal; -use distributions::{Distribution, Exp, Open01}; +use crate::Rng; +use crate::distributions::normal::StandardNormal; +use crate::distributions::{Distribution, Exp, Open01}; /// The Gamma distribution `Gamma(shape, scale)` distribution. /// @@ -301,7 +301,7 @@ impl Distribution for Beta { #[cfg(test)] mod test { - use distributions::Distribution; + use crate::distributions::Distribution; use super::{Beta, ChiSquared, StudentT, FisherF}; const N: u32 = 100; @@ -309,7 +309,7 @@ mod test { #[test] fn test_chi_squared_one() { let chi = ChiSquared::new(1.0); - let mut rng = ::test::rng(201); + let mut rng = crate::test::rng(201); for _ in 0..N { chi.sample(&mut rng); } @@ -317,7 +317,7 @@ mod test { #[test] fn test_chi_squared_small() { let chi = ChiSquared::new(0.5); - let mut rng = ::test::rng(202); + let mut rng = crate::test::rng(202); for _ in 0..N { chi.sample(&mut rng); } @@ -325,7 +325,7 @@ mod test { #[test] fn test_chi_squared_large() { let chi = ChiSquared::new(30.0); - let mut rng = ::test::rng(203); + let mut rng = crate::test::rng(203); for _ in 0..N { chi.sample(&mut rng); } @@ -339,7 +339,7 @@ mod test { #[test] fn test_f() { let f = FisherF::new(2.0, 32.0); - let mut rng = ::test::rng(204); + let mut rng = crate::test::rng(204); for _ in 0..N { f.sample(&mut rng); } @@ -348,7 +348,7 @@ mod test { #[test] fn test_t() { let t = StudentT::new(11.0); - let mut rng = ::test::rng(205); + let mut rng = crate::test::rng(205); for _ in 0..N { t.sample(&mut rng); } @@ -357,7 +357,7 @@ mod test { #[test] fn test_beta() { let beta = Beta::new(1.0, 2.0); - let mut rng = ::test::rng(201); + let mut rng = crate::test::rng(201); for _ in 0..N { beta.sample(&mut rng); } diff --git a/src/distributions/integer.rs b/src/distributions/integer.rs index 7316d30a86f..31eb237e9f8 100644 --- a/src/distributions/integer.rs +++ b/src/distributions/integer.rs @@ -8,9 +8,8 @@ //! The implementations of the `Standard` distribution for integer types. -use {Rng}; -use distributions::{Distribution, Standard}; -#[cfg(rustc_1_28)] +use crate::{Rng}; +use crate::distributions::{Distribution, Standard}; use core::num::{NonZeroU8, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroUsize}; #[cfg(not(target_os = "emscripten"))] use core::num::NonZeroU128; #[cfg(feature="simd_support")] @@ -48,7 +47,7 @@ impl Distribution for Standard { } } -#[cfg(all(rustc_1_26, not(target_os = "emscripten")))] +#[cfg(not(target_os = "emscripten"))] impl Distribution for Standard { #[inline] fn sample(&self, rng: &mut R) -> u128 { @@ -88,7 +87,7 @@ impl_int_from_uint! { i8, u8 } impl_int_from_uint! { i16, u16 } impl_int_from_uint! { i32, u32 } impl_int_from_uint! { i64, u64 } -#[cfg(all(rustc_1_26, not(target_os = "emscripten")))] impl_int_from_uint! { i128, u128 } +#[cfg(not(target_os = "emscripten"))] impl_int_from_uint! { i128, u128 } impl_int_from_uint! { isize, usize } macro_rules! impl_nzint { @@ -105,12 +104,12 @@ macro_rules! impl_nzint { } } -#[cfg(rustc_1_28)] impl_nzint!(NonZeroU8, NonZeroU8::new); -#[cfg(rustc_1_28)] impl_nzint!(NonZeroU16, NonZeroU16::new); -#[cfg(rustc_1_28)] impl_nzint!(NonZeroU32, NonZeroU32::new); -#[cfg(rustc_1_28)] impl_nzint!(NonZeroU64, NonZeroU64::new); -#[cfg(all(rustc_1_28, not(target_os = "emscripten")))] impl_nzint!(NonZeroU128, NonZeroU128::new); -#[cfg(rustc_1_28)] impl_nzint!(NonZeroUsize, NonZeroUsize::new); +impl_nzint!(NonZeroU8, NonZeroU8::new); +impl_nzint!(NonZeroU16, NonZeroU16::new); +impl_nzint!(NonZeroU32, NonZeroU32::new); +impl_nzint!(NonZeroU64, NonZeroU64::new); +#[cfg(not(target_os = "emscripten"))] impl_nzint!(NonZeroU128, NonZeroU128::new); +impl_nzint!(NonZeroUsize, NonZeroUsize::new); #[cfg(feature="simd_support")] macro_rules! simd_impl { @@ -159,19 +158,19 @@ simd_impl!((__m64, u8x8), (__m128i, u8x16), (__m256i, u8x32),); #[cfg(test)] mod tests { - use Rng; - use distributions::{Standard}; + use crate::Rng; + use crate::distributions::{Standard}; #[test] fn test_integers() { - let mut rng = ::test::rng(806); + let mut rng = crate::test::rng(806); rng.sample::(Standard); rng.sample::(Standard); rng.sample::(Standard); rng.sample::(Standard); rng.sample::(Standard); - #[cfg(all(rustc_1_26, not(target_os = "emscripten")))] + #[cfg(not(target_os = "emscripten"))] rng.sample::(Standard); rng.sample::(Standard); @@ -179,7 +178,7 @@ mod tests { rng.sample::(Standard); rng.sample::(Standard); rng.sample::(Standard); - #[cfg(all(rustc_1_26, not(target_os = "emscripten")))] + #[cfg(not(target_os = "emscripten"))] rng.sample::(Standard); } } diff --git a/src/distributions/mod.rs b/src/distributions/mod.rs index b2fd884d3bd..693e0f97fe6 100644 --- a/src/distributions/mod.rs +++ b/src/distributions/mod.rs @@ -101,9 +101,8 @@ //! [`rand_distr`]: https://crates.io/crates/rand_distr //! [`statrs`]: https://crates.io/crates/statrs -#[cfg(any(rustc_1_26, features="nightly"))] use core::iter; -use Rng; +use crate::Rng; pub use self::other::Alphanumeric; #[doc(inline)] pub use self::uniform::Uniform; @@ -259,7 +258,6 @@ impl Iterator for DistIter } } -#[cfg(rustc_1_26)] impl iter::FusedIterator for DistIter where D: Distribution, R: Rng {} @@ -351,13 +349,13 @@ pub struct Standard; #[cfg(all(test, feature = "std"))] mod tests { - use ::Rng; + use crate::Rng; use super::{Distribution, Uniform}; #[test] fn test_distributions_iter() { - use distributions::Open01; - let mut rng = ::test::rng(210); + use crate::distributions::Open01; + let mut rng = crate::test::rng(210); let distr = Open01; let results: Vec = distr.sample_iter(&mut rng).take(100).collect(); println!("{:?}", results); @@ -372,7 +370,7 @@ mod tests { .take(10) } - let mut rng = ::test::rng(211); + let mut rng = crate::test::rng(211); let mut count = 0; for val in ten_dice_rolls_other_than_five(&mut rng) { assert!(val >= 1 && val <= 6 && val != 5); diff --git a/src/distributions/normal.rs b/src/distributions/normal.rs index 06fda5cf9c7..7808bafee83 100644 --- a/src/distributions/normal.rs +++ b/src/distributions/normal.rs @@ -10,9 +10,9 @@ //! The normal and derived distributions. #![allow(deprecated)] -use Rng; -use distributions::{ziggurat_tables, Distribution, Open01}; -use distributions::utils::ziggurat; +use crate::Rng; +use crate::distributions::{ziggurat_tables, Distribution, Open01}; +use crate::distributions::utils::ziggurat; /// Samples floating-point numbers according to the normal distribution /// `N(0, 1)` (a.k.a. a standard normal, or Gaussian). This is equivalent to @@ -136,13 +136,13 @@ impl Distribution for LogNormal { #[cfg(test)] mod tests { - use distributions::Distribution; + use crate::distributions::Distribution; use super::{Normal, LogNormal}; #[test] fn test_normal() { let norm = Normal::new(10.0, 10.0); - let mut rng = ::test::rng(210); + let mut rng = crate::test::rng(210); for _ in 0..1000 { norm.sample(&mut rng); } @@ -157,7 +157,7 @@ mod tests { #[test] fn test_log_normal() { let lnorm = LogNormal::new(10.0, 10.0); - let mut rng = ::test::rng(211); + let mut rng = crate::test::rng(211); for _ in 0..1000 { lnorm.sample(&mut rng); } diff --git a/src/distributions/other.rs b/src/distributions/other.rs index 84068a1c36d..a3af1dc8415 100644 --- a/src/distributions/other.rs +++ b/src/distributions/other.rs @@ -11,8 +11,8 @@ use core::char; use core::num::Wrapping; -use {Rng}; -use distributions::{Distribution, Standard, Uniform}; +use crate::{Rng}; +use crate::distributions::{Distribution, Standard, Uniform}; // ----- Sampling distributions ----- @@ -176,13 +176,13 @@ impl Distribution> for Standard where Standard: Distribution { #[cfg(test)] mod tests { - use {Rng, RngCore, Standard}; - use distributions::Alphanumeric; + use crate::{Rng, RngCore, Standard}; + use crate::distributions::Alphanumeric; #[cfg(all(not(feature="std"), feature="alloc"))] use alloc::string::String; #[test] fn test_misc() { - let rng: &mut dyn RngCore = &mut ::test::rng(820); + let rng: &mut dyn RngCore = &mut crate::test::rng(820); rng.sample::(Standard); rng.sample::(Standard); @@ -192,7 +192,7 @@ mod tests { #[test] fn test_chars() { use core::iter; - let mut rng = ::test::rng(805); + let mut rng = crate::test::rng(805); // Test by generating a relatively large number of chars, so we also // take the rejection sampling path. @@ -203,7 +203,7 @@ mod tests { #[test] fn test_alphanumeric() { - let mut rng = ::test::rng(806); + let mut rng = crate::test::rng(806); // Test by generating a relatively large number of chars, so we also // take the rejection sampling path. diff --git a/src/distributions/pareto.rs b/src/distributions/pareto.rs index ae7968cbbb8..edc91223295 100644 --- a/src/distributions/pareto.rs +++ b/src/distributions/pareto.rs @@ -9,8 +9,8 @@ //! The Pareto distribution. #![allow(deprecated)] -use Rng; -use distributions::{Distribution, OpenClosed01}; +use crate::Rng; +use crate::distributions::{Distribution, OpenClosed01}; /// Samples floating-point numbers according to the Pareto distribution #[deprecated(since="0.7.0", note="moved to rand_distr crate")] @@ -44,7 +44,7 @@ impl Distribution for Pareto { #[cfg(test)] mod tests { - use distributions::Distribution; + use crate::distributions::Distribution; use super::Pareto; #[test] @@ -58,7 +58,7 @@ mod tests { let scale = 1.0; let shape = 2.0; let d = Pareto::new(scale, shape); - let mut rng = ::test::rng(1); + let mut rng = crate::test::rng(1); for _ in 0..1000 { let r = d.sample(&mut rng); assert!(r >= scale); diff --git a/src/distributions/poisson.rs b/src/distributions/poisson.rs index 22b7e76baa8..9fd6e999ecc 100644 --- a/src/distributions/poisson.rs +++ b/src/distributions/poisson.rs @@ -10,9 +10,9 @@ //! The Poisson distribution. #![allow(deprecated)] -use Rng; -use distributions::{Distribution, Cauchy}; -use distributions::utils::log_gamma; +use crate::Rng; +use crate::distributions::{Distribution, Cauchy}; +use crate::distributions::utils::log_gamma; /// The Poisson distribution `Poisson(lambda)`. /// @@ -105,14 +105,14 @@ impl Distribution for Poisson { #[cfg(test)] mod test { - use distributions::Distribution; + use crate::distributions::Distribution; use super::Poisson; #[test] #[cfg(not(miri))] // Miri is too slow fn test_poisson_10() { let poisson = Poisson::new(10.0); - let mut rng = ::test::rng(123); + let mut rng = crate::test::rng(123); let mut sum = 0; for _ in 0..1000 { sum += poisson.sample(&mut rng); @@ -127,7 +127,7 @@ mod test { fn test_poisson_15() { // Take the 'high expected values' path let poisson = Poisson::new(15.0); - let mut rng = ::test::rng(123); + let mut rng = crate::test::rng(123); let mut sum = 0; for _ in 0..1000 { sum += poisson.sample(&mut rng); diff --git a/src/distributions/triangular.rs b/src/distributions/triangular.rs index 0f02055053d..3e8f8b03eff 100644 --- a/src/distributions/triangular.rs +++ b/src/distributions/triangular.rs @@ -9,8 +9,8 @@ //! The triangular distribution. #![allow(deprecated)] -use Rng; -use distributions::{Distribution, Standard}; +use crate::Rng; +use crate::distributions::{Distribution, Standard}; /// The triangular distribution. #[deprecated(since="0.7.0", note="moved to rand_distr crate")] @@ -54,7 +54,7 @@ impl Distribution for Triangular { #[cfg(test)] mod test { - use distributions::Distribution; + use crate::distributions::Distribution; use super::Triangular; #[test] @@ -71,7 +71,7 @@ mod test { #[test] fn test_sample() { let norm = Triangular::new(0., 1., 0.5); - let mut rng = ::test::rng(1); + let mut rng = crate::test::rng(1); for _ in 0..1000 { norm.sample(&mut rng); } diff --git a/src/distributions/uniform.rs b/src/distributions/uniform.rs index c1a1b2594e0..f07fba95374 100644 --- a/src/distributions/uniform.rs +++ b/src/distributions/uniform.rs @@ -109,17 +109,17 @@ #[cfg(feature = "std")] use std::time::Duration; -#[cfg(all(not(feature = "std"), rustc_1_25))] +#[cfg(not(feature = "std"))] use core::time::Duration; -use Rng; -use distributions::Distribution; -use distributions::float::IntoFloat; -use distributions::utils::{WideningMultiply, FloatSIMDUtils, FloatAsSIMD, BoolAsSIMD}; +use crate::Rng; +use crate::distributions::Distribution; +use crate::distributions::float::IntoFloat; +use crate::distributions::utils::{WideningMultiply, FloatSIMDUtils, FloatAsSIMD, BoolAsSIMD}; #[cfg(not(feature = "std"))] #[allow(unused_imports)] // rustc doesn't detect that this is actually used -use distributions::utils::Float; +use crate::distributions::utils::Float; #[cfg(feature="simd_support")] @@ -267,7 +267,6 @@ impl From<::core::ops::Range> for Uniform { } } -#[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()) @@ -453,7 +452,7 @@ uniform_int_impl! { i8, u8, u32 } uniform_int_impl! { i16, u16, u32 } uniform_int_impl! { i32, u32, u32 } uniform_int_impl! { i64, u64, u64 } -#[cfg(all(rustc_1_26, not(target_os = "emscripten")))] +#[cfg(not(target_os = "emscripten"))] uniform_int_impl! { i128, u128, u128 } uniform_int_impl! { isize, usize, usize } uniform_int_impl! { u8, u8, u32 } @@ -461,7 +460,7 @@ uniform_int_impl! { u16, u16, u32 } uniform_int_impl! { u32, u32, u32 } uniform_int_impl! { u64, u64, u64 } uniform_int_impl! { usize, usize, usize } -#[cfg(all(rustc_1_26, not(target_os = "emscripten")))] +#[cfg(not(target_os = "emscripten"))] uniform_int_impl! { u128, u128, u128 } #[cfg(all(feature = "simd_support", feature = "nightly"))] @@ -811,14 +810,12 @@ uniform_float_impl! { f64x8, u64x8, f64, u64, 64 - 52 } /// /// Unless you are implementing [`UniformSampler`] for your own types, this type /// should not be used directly, use [`Uniform`] instead. -#[cfg(any(feature = "std", rustc_1_25))] #[derive(Clone, Copy, Debug)] pub struct UniformDuration { mode: UniformDurationMode, offset: u32, } -#[cfg(any(feature = "std", rustc_1_25))] #[derive(Debug, Copy, Clone)] enum UniformDurationMode { Small { @@ -835,12 +832,10 @@ enum UniformDurationMode { } } -#[cfg(any(feature = "std", rustc_1_25))] impl SampleUniform for Duration { type Sampler = UniformDuration; } -#[cfg(any(feature = "std", rustc_1_25))] impl UniformSampler for UniformDuration { type X = Duration; @@ -934,10 +929,10 @@ impl UniformSampler for UniformDuration { #[cfg(test)] mod tests { - use Rng; - use rngs::mock::StepRng; - use distributions::uniform::Uniform; - use distributions::utils::FloatAsSIMD; + use crate::Rng; + use crate::rngs::mock::StepRng; + use crate::distributions::uniform::Uniform; + use crate::distributions::utils::FloatAsSIMD; #[cfg(feature="simd_support")] use packed_simd::*; #[should_panic] @@ -948,7 +943,7 @@ mod tests { #[test] fn test_uniform_good_limits_equal_int() { - let mut rng = ::test::rng(804); + let mut rng = crate::test::rng(804); let dist = Uniform::new_inclusive(10, 10); for _ in 0..20 { assert_eq!(rng.sample(dist), 10); @@ -966,10 +961,10 @@ mod tests { fn test_integers() { use core::{i8, i16, i32, i64, isize}; use core::{u8, u16, u32, u64, usize}; - #[cfg(all(rustc_1_26, not(target_os = "emscripten")))] + #[cfg(not(target_os = "emscripten"))] use core::{i128, u128}; - let mut rng = ::test::rng(251); + let mut rng = crate::test::rng(251); macro_rules! t { ($ty:ident, $v:expr, $le:expr, $lt:expr) => {{ for &(low, high) in $v.iter() { @@ -1030,7 +1025,7 @@ mod tests { } t!(i8, i16, i32, i64, isize, u8, u16, u32, u64, usize); - #[cfg(all(rustc_1_26, not(target_os = "emscripten")))] + #[cfg(not(target_os = "emscripten"))] t!(i128, u128); #[cfg(all(feature = "simd_support", feature = "nightly"))] @@ -1049,7 +1044,7 @@ mod tests { #[test] #[cfg(not(miri))] // Miri is too slow fn test_floats() { - let mut rng = ::test::rng(252); + let mut rng = crate::test::rng(252); let mut zero_rng = StepRng::new(0, 0); let mut max_rng = StepRng::new(0xffff_ffff_ffff_ffff, 0); macro_rules! t { @@ -1137,7 +1132,7 @@ mod tests { use std::panic::catch_unwind; use super::SampleUniform; fn range(low: T, high: T) { - let mut rng = ::test::rng(253); + let mut rng = crate::test::rng(253); rng.gen_range(low, high); } @@ -1187,15 +1182,14 @@ mod tests { #[test] - #[cfg(any(feature = "std", rustc_1_25))] #[cfg(not(miri))] // Miri is too slow fn test_durations() { #[cfg(feature = "std")] use std::time::Duration; - #[cfg(all(not(feature = "std"), rustc_1_25))] + #[cfg(not(feature = "std"))] use core::time::Duration; - let mut rng = ::test::rng(253); + let mut rng = crate::test::rng(253); let v = &[(Duration::new(10, 50000), Duration::new(100, 1234)), (Duration::new(0, 100), Duration::new(1, 50)), @@ -1211,7 +1205,7 @@ mod tests { #[test] fn test_custom_uniform() { - use distributions::uniform::{UniformSampler, UniformFloat, SampleUniform, SampleBorrow}; + use crate::distributions::uniform::{UniformSampler, UniformFloat, SampleUniform, SampleBorrow}; #[derive(Clone, Copy, PartialEq, PartialOrd)] struct MyF32 { x: f32, @@ -1246,7 +1240,7 @@ mod tests { let (low, high) = (MyF32{ x: 17.0f32 }, MyF32{ x: 22.0f32 }); let uniform = Uniform::new(low, high); - let mut rng = ::test::rng(804); + let mut rng = crate::test::rng(804); for _ in 0..100 { let x: MyF32 = rng.sample(uniform); assert!(low <= x && x < high); @@ -1263,7 +1257,6 @@ mod tests { assert_eq!(r.inner.scale, 5.0); } - #[cfg(rustc_1_27)] #[test] fn test_uniform_from_std_range_inclusive() { let r = Uniform::from(2u32..=6); diff --git a/src/distributions/unit_circle.rs b/src/distributions/unit_circle.rs index ddd3caf71df..1f3cb77a207 100644 --- a/src/distributions/unit_circle.rs +++ b/src/distributions/unit_circle.rs @@ -8,8 +8,8 @@ #![allow(deprecated)] -use Rng; -use distributions::{Distribution, Uniform}; +use crate::Rng; +use crate::distributions::{Distribution, Uniform}; /// Samples uniformly from the edge of the unit circle in two dimensions. /// @@ -53,7 +53,7 @@ impl Distribution<[f64; 2]> for UnitCircle { #[cfg(test)] mod tests { - use distributions::Distribution; + use crate::distributions::Distribution; use super::UnitCircle; /// Assert that two numbers are almost equal to each other. @@ -74,7 +74,7 @@ mod tests { #[test] fn norm() { - let mut rng = ::test::rng(1); + let mut rng = crate::test::rng(1); let dist = UnitCircle::new(); for _ in 0..1000 { let x = dist.sample(&mut rng); diff --git a/src/distributions/unit_sphere.rs b/src/distributions/unit_sphere.rs index 3cd94d6dbcc..2a224cbe5ec 100644 --- a/src/distributions/unit_sphere.rs +++ b/src/distributions/unit_sphere.rs @@ -8,8 +8,8 @@ #![allow(deprecated)] -use Rng; -use distributions::{Distribution, Uniform}; +use crate::Rng; +use crate::distributions::{Distribution, Uniform}; /// Samples uniformly from the surface of the unit sphere in three dimensions. /// @@ -48,7 +48,7 @@ impl Distribution<[f64; 3]> for UnitSphereSurface { #[cfg(test)] mod tests { - use distributions::Distribution; + use crate::distributions::Distribution; use super::UnitSphereSurface; /// Assert that two numbers are almost equal to each other. @@ -69,7 +69,7 @@ mod tests { #[test] fn norm() { - let mut rng = ::test::rng(1); + let mut rng = crate::test::rng(1); let dist = UnitSphereSurface::new(); for _ in 0..1000 { let x = dist.sample(&mut rng); diff --git a/src/distributions/utils.rs b/src/distributions/utils.rs index 980c75ecb27..fb482a86cae 100644 --- a/src/distributions/utils.rs +++ b/src/distributions/utils.rs @@ -11,9 +11,9 @@ #[cfg(feature="simd_support")] use packed_simd::*; #[cfg(feature="std")] -use distributions::ziggurat_tables; +use crate::distributions::ziggurat_tables; #[cfg(feature="std")] -use Rng; +use crate::Rng; pub trait WideningMultiply { @@ -61,7 +61,7 @@ macro_rules! wmul_impl { wmul_impl! { u8, u16, 8 } wmul_impl! { u16, u32, 16 } wmul_impl! { u32, u64, 32 } -#[cfg(all(rustc_1_26, not(target_os = "emscripten")))] +#[cfg(not(target_os = "emscripten"))] wmul_impl! { u64, u128, 64 } // This code is a translation of the __mulddi3 function in LLVM's @@ -125,9 +125,9 @@ macro_rules! wmul_impl_large { )+ }; } -#[cfg(not(all(rustc_1_26, not(target_os = "emscripten"))))] +#[cfg(target_os = "emscripten")] wmul_impl_large! { u64, 32 } -#[cfg(all(rustc_1_26, not(target_os = "emscripten")))] +#[cfg(not(target_os = "emscripten"))] wmul_impl_large! { u128, 64 } macro_rules! wmul_impl_usize { @@ -465,7 +465,7 @@ pub fn ziggurat( mut pdf: P, mut zero_case: Z) -> f64 where P: FnMut(f64) -> f64, Z: FnMut(&mut R, f64) -> f64 { - use distributions::float::IntoFloat; + use crate::distributions::float::IntoFloat; loop { // As an optimisation we re-implement the conversion to a f64. // From the remaining 12 most significant bits we use 8 to construct `i`. diff --git a/src/distributions/weibull.rs b/src/distributions/weibull.rs index ee4e8b2fe67..483714f9bf5 100644 --- a/src/distributions/weibull.rs +++ b/src/distributions/weibull.rs @@ -9,8 +9,8 @@ //! The Weibull distribution. #![allow(deprecated)] -use Rng; -use distributions::{Distribution, OpenClosed01}; +use crate::Rng; +use crate::distributions::{Distribution, OpenClosed01}; /// Samples floating-point numbers according to the Weibull distribution #[deprecated(since="0.7.0", note="moved to rand_distr crate")] @@ -41,7 +41,7 @@ impl Distribution for Weibull { #[cfg(test)] mod tests { - use distributions::Distribution; + use crate::distributions::Distribution; use super::Weibull; #[test] @@ -55,7 +55,7 @@ mod tests { let scale = 1.0; let shape = 2.0; let d = Weibull::new(scale, shape); - let mut rng = ::test::rng(1); + let mut rng = crate::test::rng(1); for _ in 0..1000 { let r = d.sample(&mut rng); assert!(r >= 0.); diff --git a/src/distributions/weighted/alias_method.rs b/src/distributions/weighted/alias_method.rs index 2e58d84ceca..bdd4ba0f3c9 100644 --- a/src/distributions/weighted/alias_method.rs +++ b/src/distributions/weighted/alias_method.rs @@ -3,14 +3,16 @@ use super::WeightedError; #[cfg(not(feature = "std"))] -use alloc::vec::Vec; +use crate::alloc::vec::Vec; +#[cfg(not(feature = "std"))] +use crate::alloc::vec; use core::fmt; use core::iter::Sum; use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; -use distributions::uniform::SampleUniform; -use distributions::Distribution; -use distributions::Uniform; -use Rng; +use crate::distributions::uniform::SampleUniform; +use crate::distributions::Distribution; +use crate::distributions::Uniform; +use crate::Rng; /// A distribution using weighted sampling to pick a discretely selected item. /// @@ -349,14 +351,14 @@ macro_rules! impl_weight_for_int { impl_weight_for_float!(f64); impl_weight_for_float!(f32); impl_weight_for_int!(usize); -#[cfg(all(rustc_1_26, not(target_os = "emscripten")))] +#[cfg(not(target_os = "emscripten"))] impl_weight_for_int!(u128); impl_weight_for_int!(u64); impl_weight_for_int!(u32); impl_weight_for_int!(u16); impl_weight_for_int!(u8); impl_weight_for_int!(isize); -#[cfg(all(rustc_1_26, not(target_os = "emscripten")))] +#[cfg(not(target_os = "emscripten"))] impl_weight_for_int!(i128); impl_weight_for_int!(i64); impl_weight_for_int!(i32); @@ -395,7 +397,7 @@ mod test { ); } - #[cfg(all(rustc_1_26, not(target_os = "emscripten")))] + #[cfg(not(target_os = "emscripten"))] #[test] #[cfg(not(miri))] // Miri is too slow fn test_weighted_index_u128() { @@ -448,11 +450,11 @@ mod test { const NUM_WEIGHTS: u32 = 10; const ZERO_WEIGHT_INDEX: u32 = 3; const NUM_SAMPLES: u32 = 15000; - let mut rng = ::test::rng(0x9c9fa0b0580a7031); + let mut rng = crate::test::rng(0x9c9fa0b0580a7031); let weights = { let mut weights = Vec::with_capacity(NUM_WEIGHTS as usize); - let random_weight_distribution = ::distributions::Uniform::new_inclusive( + let random_weight_distribution = crate::distributions::Uniform::new_inclusive( W::ZERO, W::MAX / W::try_from_u32_lossy(NUM_WEIGHTS).unwrap(), ); diff --git a/src/distributions/weighted/mod.rs b/src/distributions/weighted/mod.rs index 660f177f616..de2711b1527 100644 --- a/src/distributions/weighted/mod.rs +++ b/src/distributions/weighted/mod.rs @@ -11,14 +11,14 @@ pub mod alias_method; -use Rng; -use distributions::Distribution; -use distributions::uniform::{UniformSampler, SampleUniform, SampleBorrow}; -use ::core::cmp::PartialOrd; +use crate::Rng; +use crate::distributions::Distribution; +use crate::distributions::uniform::{UniformSampler, SampleUniform, SampleBorrow}; +use core::cmp::PartialOrd; use core::fmt; // Note that this whole module is only imported if feature="alloc" is enabled. -#[cfg(not(feature="std"))] use alloc::vec::Vec; +#[cfg(not(feature="std"))] use crate::alloc::vec::Vec; /// A distribution using weighted sampling to pick a discretely selected /// item. @@ -142,7 +142,7 @@ mod test { #[test] #[cfg(not(miri))] // Miri is too slow fn test_weightedindex() { - let mut r = ::test::rng(700); + let mut r = crate::test::rng(700); const N_REPS: u32 = 5000; let weights = [1u32, 2, 3, 0, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7]; let total_weight = weights.iter().sum::() as f32; diff --git a/src/lib.rs b/src/lib.rs index be384751b30..31f0169e1ae 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,37 +53,48 @@ #![cfg_attr(all(feature="alloc", not(feature="std")), feature(alloc))] #![cfg_attr(all(feature="simd_support", feature="nightly"), feature(stdsimd))] -#[cfg(feature = "std")] extern crate core; -#[cfg(all(feature = "alloc", not(feature="std")))] #[macro_use] extern crate alloc; - -#[cfg(feature="simd_support")] extern crate packed_simd; +#[cfg(all(feature="alloc", not(feature="std")))] +extern crate alloc; #[cfg(feature = "getrandom")] -extern crate getrandom_package as getrandom; - -extern crate rand_core; -#[cfg(not(target_os = "emscripten"))] extern crate rand_chacha; -#[cfg(target_os = "emscripten")] extern crate rand_hc; -#[cfg(feature="small_rng")] extern crate rand_pcg; +use getrandom_package as getrandom; -#[cfg(feature = "log")] #[macro_use] extern crate log; #[allow(unused)] -#[cfg(not(feature = "log"))] macro_rules! trace { ($($x:tt)*) => () } +macro_rules! trace { ($($x:tt)*) => ( + #[cfg(feature = "log")] { + log::trace!($($x)*) + } +) } #[allow(unused)] -#[cfg(not(feature = "log"))] macro_rules! debug { ($($x:tt)*) => () } +macro_rules! debug { ($($x:tt)*) => ( + #[cfg(feature = "log")] { + log::debug!($($x)*) + } +) } #[allow(unused)] -#[cfg(not(feature = "log"))] macro_rules! info { ($($x:tt)*) => () } +macro_rules! info { ($($x:tt)*) => ( + #[cfg(feature = "log")] { + log::info!($($x)*) + } +) } #[allow(unused)] -#[cfg(not(feature = "log"))] macro_rules! warn { ($($x:tt)*) => () } +macro_rules! warn { ($($x:tt)*) => ( + #[cfg(feature = "log")] { + log::warn!($($x)*) + } +) } #[allow(unused)] -#[cfg(not(feature = "log"))] macro_rules! error { ($($x:tt)*) => () } - +macro_rules! error { ($($x:tt)*) => ( + #[cfg(feature = "log")] { + log::error!($($x)*) + } +) } // Re-exports from rand_core pub use rand_core::{RngCore, CryptoRng, SeedableRng, Error}; // Public exports -#[cfg(feature="std")] pub use rngs::thread::thread_rng; +#[cfg(feature="std")] pub use crate::rngs::thread::thread_rng; // Public modules pub mod distributions; @@ -94,8 +105,8 @@ pub mod seq; use core::{mem, slice}; use core::num::Wrapping; -use distributions::{Distribution, Standard}; -use distributions::uniform::{SampleUniform, UniformSampler, SampleBorrow}; +use crate::distributions::{Distribution, Standard}; +use crate::distributions::uniform::{SampleUniform, UniformSampler, SampleBorrow}; /// An automatically-implemented extension trait on [`RngCore`] providing high-level /// generic methods for sampling values and other convenience methods. @@ -459,9 +470,9 @@ macro_rules! impl_as_byte_slice { } impl_as_byte_slice!(u16, u32, u64, usize,); -#[cfg(all(rustc_1_26, not(target_os = "emscripten")))] impl_as_byte_slice!(u128); +#[cfg(not(target_os = "emscripten"))] impl_as_byte_slice!(u128); impl_as_byte_slice!(i8, i16, i32, i64, isize,); -#[cfg(all(rustc_1_26, not(target_os = "emscripten")))] impl_as_byte_slice!(i128); +#[cfg(not(target_os = "emscripten"))] impl_as_byte_slice!(i128); macro_rules! impl_as_byte_slice_arrays { ($n:expr,) => {}; @@ -540,7 +551,7 @@ where Standard: Distribution { #[cfg(test)] mod test { - use rngs::mock::StepRng; + use crate::rngs::mock::StepRng; use super::*; #[cfg(all(not(feature="std"), feature="alloc"))] use alloc::boxed::Box; @@ -651,7 +662,7 @@ mod test { #[test] fn test_rng_trait_object() { - use distributions::{Distribution, Standard}; + use crate::distributions::{Distribution, Standard}; let mut rng = rng(109); let mut r = &mut rng as &mut dyn RngCore; r.next_u32(); @@ -663,7 +674,7 @@ mod test { #[test] #[cfg(feature="alloc")] fn test_rng_boxed_trait() { - use distributions::{Distribution, Standard}; + use crate::distributions::{Distribution, Standard}; let rng = rng(110); let mut r = Box::new(rng) as Box; r.next_u32(); diff --git a/src/prelude.rs b/src/prelude.rs index ca944cb259a..3c386e8629c 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -18,11 +18,11 @@ //! # let _: f32 = r.gen(); //! ``` -#[doc(no_inline)] pub use distributions::Distribution; -#[doc(no_inline)] pub use rngs::StdRng; +#[doc(no_inline)] pub use crate::distributions::Distribution; +#[doc(no_inline)] pub use crate::rngs::StdRng; #[cfg(feature="small_rng")] -#[doc(no_inline)] pub use rngs::SmallRng; -#[doc(no_inline)] #[cfg(feature="std")] pub use rngs::ThreadRng; -#[doc(no_inline)] pub use {Rng, RngCore, CryptoRng, SeedableRng}; -#[doc(no_inline)] #[cfg(feature="std")] pub use {random, thread_rng}; -#[doc(no_inline)] pub use seq::{SliceRandom, IteratorRandom}; +#[doc(no_inline)] pub use crate::rngs::SmallRng; +#[doc(no_inline)] #[cfg(feature="std")] pub use crate::rngs::ThreadRng; +#[doc(no_inline)] pub use crate::{Rng, RngCore, CryptoRng, SeedableRng}; +#[doc(no_inline)] #[cfg(feature="std")] pub use crate::{random, thread_rng}; +#[doc(no_inline)] pub use crate::seq::{SliceRandom, IteratorRandom}; diff --git a/src/rngs/adapter/read.rs b/src/rngs/adapter/read.rs index 53b741491ab..77b2a16d055 100644 --- a/src/rngs/adapter/read.rs +++ b/src/rngs/adapter/read.rs @@ -98,7 +98,7 @@ impl std::error::Error for ReadError { #[cfg(test)] mod test { use super::ReadRng; - use RngCore; + use crate::RngCore; #[test] fn test_reader_rng_u64() { diff --git a/src/rngs/adapter/reseeding.rs b/src/rngs/adapter/reseeding.rs index 2dccf0a20a2..57c6c7503dd 100644 --- a/src/rngs/adapter/reseeding.rs +++ b/src/rngs/adapter/reseeding.rs @@ -57,9 +57,6 @@ use rand_core::block::{BlockRngCore, BlockRng}; /// # Example /// /// ``` -/// # extern crate rand; -/// # extern crate rand_chacha; -/// # fn main() { /// use rand::prelude::*; /// use rand_chacha::ChaCha20Core; // Internal part of ChaChaRng that /// // implements BlockRngCore @@ -73,7 +70,6 @@ use rand_core::block::{BlockRngCore, BlockRng}; /// /// let mut cloned_rng = reseeding_rng.clone(); /// assert!(reseeding_rng.gen::() != cloned_rng.gen::()); -/// # } /// ``` /// /// [`ChaCha20Core`]: ../../../rand_chacha/struct.ChaCha20Core.html @@ -272,8 +268,6 @@ where R: BlockRngCore + SeedableRng + CryptoRng, #[cfg(all(unix, not(target_os="emscripten")))] mod fork { - extern crate libc; - use core::sync::atomic::{AtomicUsize, AtomicBool, Ordering}; #[allow(deprecated)] // Required for compatibility with Rust < 1.24. use core::sync::atomic::{ATOMIC_USIZE_INIT, ATOMIC_BOOL_INIT}; @@ -323,9 +317,9 @@ mod fork { #[cfg(test)] mod test { - use {Rng, SeedableRng}; - use rngs::std::Core; - use rngs::mock::StepRng; + use crate::{Rng, SeedableRng}; + use crate::rngs::std::Core; + use crate::rngs::mock::StepRng; use super::ReseedingRng; #[test] diff --git a/src/rngs/entropy.rs b/src/rngs/entropy.rs index 17c13f9d314..fdcc3be52c6 100644 --- a/src/rngs/entropy.rs +++ b/src/rngs/entropy.rs @@ -12,7 +12,7 @@ use rand_core::{RngCore, CryptoRng, Error}; #[allow(unused)] -use rngs::OsRng; +use crate::rngs::OsRng; /// An interface returning random data from external source(s), provided /// specifically for securely seeding algorithmic generators (PRNGs). diff --git a/src/rngs/os.rs b/src/rngs/os.rs index c7fc75f6941..46c3483d944 100644 --- a/src/rngs/os.rs +++ b/src/rngs/os.rs @@ -9,7 +9,7 @@ //! Interface to the random number generator of the operating system. // Note: keep this code in sync with the rand_os crate! -use getrandom::getrandom; +use crate::getrandom::getrandom; use rand_core::{CryptoRng, RngCore, Error, impls}; /// A random number generator that retrieves randomness from from the diff --git a/src/rngs/small.rs b/src/rngs/small.rs index 1ffb2fbd8a8..6958a0b40d9 100644 --- a/src/rngs/small.rs +++ b/src/rngs/small.rs @@ -8,12 +8,12 @@ //! A small fast RNG -use {RngCore, SeedableRng, Error}; +use rand_core::{RngCore, SeedableRng, Error}; -#[cfg(all(all(rustc_1_26, not(target_os = "emscripten")), target_pointer_width = "64"))] -type Rng = ::rand_pcg::Pcg64Mcg; -#[cfg(not(all(all(rustc_1_26, not(target_os = "emscripten")), target_pointer_width = "64")))] -type Rng = ::rand_pcg::Pcg32; +#[cfg(all(not(target_os = "emscripten"), target_pointer_width = "64"))] +type Rng = rand_pcg::Pcg64Mcg; +#[cfg(not(all(not(target_os = "emscripten"), target_pointer_width = "64")))] +type Rng = rand_pcg::Pcg32; /// A small-state, fast non-crypto PRNG /// diff --git a/src/rngs/std.rs b/src/rngs/std.rs index c9ea6ae84c0..22e08ae6b65 100644 --- a/src/rngs/std.rs +++ b/src/rngs/std.rs @@ -8,7 +8,7 @@ //! The standard RNG -use {RngCore, CryptoRng, Error, SeedableRng}; +use crate::{RngCore, CryptoRng, Error, SeedableRng}; #[cfg(target_os = "emscripten")] pub(crate) use rand_hc::Hc128Core as Core; #[cfg(not(target_os = "emscripten"))] pub(crate) use rand_chacha::ChaCha20Core as Core; @@ -74,8 +74,8 @@ impl CryptoRng for StdRng {} #[cfg(test)] mod test { - use {RngCore, SeedableRng}; - use rngs::StdRng; + use crate::{RngCore, SeedableRng}; + use crate::rngs::StdRng; #[test] fn test_stdrng_construction() { diff --git a/src/rngs/thread.rs b/src/rngs/thread.rs index e199c8f3901..2006f4176fa 100644 --- a/src/rngs/thread.rs +++ b/src/rngs/thread.rs @@ -11,9 +11,9 @@ use std::cell::UnsafeCell; use std::ptr::NonNull; -use {RngCore, CryptoRng, SeedableRng, Error}; -use rngs::adapter::ReseedingRng; -use rngs::OsRng; +use crate::{RngCore, CryptoRng, SeedableRng, Error}; +use crate::rngs::adapter::ReseedingRng; +use crate::rngs::OsRng; use super::std::Core; // Rationale for using `UnsafeCell` in `ThreadRng`: @@ -85,7 +85,7 @@ pub fn thread_rng() -> ThreadRng { impl Default for ThreadRng { fn default() -> ThreadRng { - ::prelude::thread_rng() + crate::prelude::thread_rng() } } @@ -116,8 +116,8 @@ impl CryptoRng for ThreadRng {} mod test { #[test] fn test_thread_rng() { - use Rng; - let mut r = ::thread_rng(); + use crate::Rng; + let mut r = crate::thread_rng(); r.gen::(); assert_eq!(r.gen_range(0, 1), 0); } diff --git a/src/seq/index.rs b/src/seq/index.rs index b6fc81e1bb1..d524329e31f 100644 --- a/src/seq/index.rs +++ b/src/seq/index.rs @@ -11,13 +11,13 @@ #[cfg(feature="alloc")] use core::slice; #[cfg(feature="std")] use std::vec; -#[cfg(all(feature="alloc", not(feature="std")))] use alloc::vec::{self, Vec}; +#[cfg(all(feature="alloc", not(feature="std")))] use crate::alloc::vec::{self, Vec}; // BTreeMap is not as fast in tests, but better than nothing. #[cfg(feature="std")] use std::collections::{HashSet}; -#[cfg(all(feature="alloc", not(feature="std")))] use alloc::collections::BTreeSet; +#[cfg(all(feature="alloc", not(feature="std")))] use crate::alloc::collections::BTreeSet; -#[cfg(feature="alloc")] use distributions::{Distribution, Uniform, uniform::SampleUniform}; -use Rng; +#[cfg(feature="alloc")] use crate::distributions::{Distribution, Uniform, uniform::SampleUniform}; +use crate::Rng; /// A vector of indices. /// @@ -326,11 +326,13 @@ where R: Rng + ?Sized, IndexVec: From> { #[cfg(test)] mod test { + #[cfg(feature="std")] use std::vec; + #[cfg(all(feature="alloc", not(feature="std")))] use crate::alloc::vec; use super::*; #[test] fn test_sample_boundaries() { - let mut r = ::test::rng(404); + let mut r = crate::test::rng(404); assert_eq!(sample_inplace(&mut r, 0, 0).len(), 0); assert_eq!(sample_inplace(&mut r, 1, 0).len(), 0); @@ -355,7 +357,7 @@ mod test { #[test] #[cfg(not(miri))] // Miri is too slow fn test_sample_alg() { - let seed_rng = ::test::rng; + let seed_rng = crate::test::rng; // We can't test which algorithm is used directly, but Floyd's alg // should produce different results from the others. (Also, `inplace` diff --git a/src/seq/mod.rs b/src/seq/mod.rs index 0b5a5b0a8bb..0ad0474b5f8 100644 --- a/src/seq/mod.rs +++ b/src/seq/mod.rs @@ -15,11 +15,11 @@ #[cfg(feature="alloc")] use core::ops::Index; -#[cfg(all(feature="alloc", not(feature="std")))] use alloc::vec::Vec; +#[cfg(all(feature="alloc", not(feature="std")))] use crate::alloc::vec::Vec; -use Rng; -#[cfg(feature="alloc")] use distributions::WeightedError; -#[cfg(feature="alloc")] use distributions::uniform::{SampleUniform, SampleBorrow}; +use crate::Rng; +#[cfg(feature="alloc")] use crate::distributions::WeightedError; +#[cfg(feature="alloc")] use crate::distributions::uniform::{SampleUniform, SampleBorrow}; /// Extension trait on slices, providing random mutation and sampling methods. /// @@ -362,7 +362,7 @@ impl SliceRandom for [T] { + Clone + Default, { - use distributions::{Distribution, WeightedIndex}; + use crate::distributions::{Distribution, WeightedIndex}; let distr = WeightedIndex::new(self.iter().map(weight))?; Ok(&self[distr.sample(rng)]) } @@ -381,7 +381,7 @@ impl SliceRandom for [T] { + Clone + Default, { - use distributions::{Distribution, WeightedIndex}; + use crate::distributions::{Distribution, WeightedIndex}; let distr = WeightedIndex::new(self.iter().map(weight))?; Ok(&mut self[distr.sample(rng)]) } @@ -467,13 +467,13 @@ fn gen_index(rng: &mut R, ubound: usize) -> usize { #[cfg(test)] mod test { use super::*; - #[cfg(feature = "alloc")] use Rng; + #[cfg(feature = "alloc")] use crate::Rng; #[cfg(all(feature="alloc", not(feature="std")))] use alloc::vec::Vec; #[test] fn test_slice_choose() { - let mut r = ::test::rng(107); + let mut r = crate::test::rng(107); let chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n']; let mut chosen = [0i32; 14]; // The below all use a binomial distribution with n=1000, p=1/14. @@ -554,7 +554,7 @@ mod test { #[test] #[cfg(not(miri))] // Miri is too slow fn test_iterator_choose() { - let r = &mut ::test::rng(109); + let r = &mut crate::test::rng(109); fn test_iter + Clone>(r: &mut R, iter: Iter) { let mut chosen = [0i32; 9]; for _ in 0..1000 { @@ -586,7 +586,7 @@ mod test { #[test] #[cfg(not(miri))] // Miri is too slow fn test_shuffle() { - let mut r = ::test::rng(108); + let mut r = crate::test::rng(108); let empty: &mut [isize] = &mut []; empty.shuffle(&mut r); let mut one = [1]; @@ -635,7 +635,7 @@ mod test { #[test] fn test_partial_shuffle() { - let mut r = ::test::rng(118); + let mut r = crate::test::rng(118); let mut empty: [u32; 0] = []; let res = empty.partial_shuffle(&mut r, 10); @@ -655,7 +655,7 @@ mod test { let min_val = 1; let max_val = 100; - let mut r = ::test::rng(401); + let mut r = crate::test::rng(401); let vals = (min_val..max_val).collect::>(); let small_sample = vals.iter().choose_multiple(&mut r, 5); let large_sample = vals.iter().choose_multiple(&mut r, vals.len() + 5); @@ -674,7 +674,7 @@ mod test { #[cfg(feature = "alloc")] #[cfg(not(miri))] // Miri is too slow fn test_weighted() { - let mut r = ::test::rng(406); + let mut r = crate::test::rng(406); const N_REPS: u32 = 3000; let weights = [1u32, 2, 3, 0, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7]; let total_weight = weights.iter().sum::() as f32; diff --git a/tests/wasm_bindgen/Cargo.toml b/tests/wasm_bindgen/Cargo.toml index b96f09bb6f2..eb6ee6f14a3 100644 --- a/tests/wasm_bindgen/Cargo.toml +++ b/tests/wasm_bindgen/Cargo.toml @@ -5,6 +5,7 @@ version = "0.1.0" authors = ["The Rand Project Developers"] publish = false license = "MIT/Apache-2.0" +edition = "2018" [lib] crate-type = ["cdylib"] diff --git a/tests/wasm_bindgen/src/lib.rs b/tests/wasm_bindgen/src/lib.rs index 9de50958a2c..9af0b9e535c 100644 --- a/tests/wasm_bindgen/src/lib.rs +++ b/tests/wasm_bindgen/src/lib.rs @@ -10,10 +10,6 @@ #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png")] -extern crate rand; -extern crate wasm_bindgen; -extern crate wasm_bindgen_test; - use rand::rngs::{OsRng, StdRng}; use rand::{Rng, SeedableRng}; use wasm_bindgen::prelude::*;