Skip to content

Commit de96865

Browse files
authored
Merge pull request #824 from vks/edition-2018
Use Rust 2018 and remove `build.rs`
2 parents 535ef93 + 67f3179 commit de96865

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+291
-368
lines changed

Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ Random number generators and other randomness functionality.
1212
"""
1313
keywords = ["random", "rng"]
1414
categories = ["algorithms", "no-std"]
15-
build = "build.rs"
1615
exclude = ["/utils/*", "/.travis.yml", "/appveyor.yml", ".gitignore"]
1716
autobenches = true
17+
edition = "2018"
1818

1919
[badges]
2020
travis-ci = { repository = "rust-random/rand" }
@@ -86,8 +86,5 @@ rand_xoshiro = { path = "rand_xoshiro", version = "0.3" }
8686
rand_isaac = { path = "rand_isaac", version = "0.2" }
8787
rand_xorshift = { path = "rand_xorshift", version = "0.2" }
8888

89-
[build-dependencies]
90-
autocfg = "0.1"
91-
9289
[package.metadata.docs.rs]
9390
all-features = true

benches/generators.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@
1010
#![allow(non_snake_case)]
1111

1212
extern crate test;
13-
extern crate rand;
14-
extern crate rand_isaac;
15-
extern crate rand_chacha;
16-
extern crate rand_hc;
17-
extern crate rand_pcg;
18-
extern crate rand_xorshift;
19-
extern crate rand_xoshiro;
2013

2114
const RAND_BENCH_N: u64 = 1000;
2215
const BYTES_LEN: usize = 1024;

benches/misc.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#![feature(test)]
1010

1111
extern crate test;
12-
extern crate rand;
13-
extern crate rand_pcg;
1412

1513
const RAND_BENCH_N: u64 = 1000;
1614

@@ -25,7 +23,7 @@ fn misc_gen_bool_const(b: &mut Bencher) {
2523
let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
2624
b.iter(|| {
2725
let mut accum = true;
28-
for _ in 0..::RAND_BENCH_N {
26+
for _ in 0..crate::RAND_BENCH_N {
2927
accum ^= rng.gen_bool(0.18);
3028
}
3129
accum
@@ -38,7 +36,7 @@ fn misc_gen_bool_var(b: &mut Bencher) {
3836
b.iter(|| {
3937
let mut accum = true;
4038
let mut p = 0.18;
41-
for _ in 0..::RAND_BENCH_N {
39+
for _ in 0..crate::RAND_BENCH_N {
4240
accum ^= rng.gen_bool(p);
4341
p += 0.0001;
4442
}
@@ -51,7 +49,7 @@ fn misc_gen_ratio_const(b: &mut Bencher) {
5149
let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
5250
b.iter(|| {
5351
let mut accum = true;
54-
for _ in 0..::RAND_BENCH_N {
52+
for _ in 0..crate::RAND_BENCH_N {
5553
accum ^= rng.gen_ratio(2, 3);
5654
}
5755
accum
@@ -63,7 +61,7 @@ fn misc_gen_ratio_var(b: &mut Bencher) {
6361
let mut rng = Pcg32::from_rng(&mut thread_rng()).unwrap();
6462
b.iter(|| {
6563
let mut accum = true;
66-
for i in 2..(::RAND_BENCH_N as u32 + 2) {
64+
for i in 2..(crate::RAND_BENCH_N as u32 + 2) {
6765
accum ^= rng.gen_ratio(i, i + 1);
6866
}
6967
accum
@@ -76,7 +74,7 @@ fn misc_bernoulli_const(b: &mut Bencher) {
7674
b.iter(|| {
7775
let d = rand::distributions::Bernoulli::new(0.18).unwrap();
7876
let mut accum = true;
79-
for _ in 0..::RAND_BENCH_N {
77+
for _ in 0..crate::RAND_BENCH_N {
8078
accum ^= rng.sample(d);
8179
}
8280
accum
@@ -89,7 +87,7 @@ fn misc_bernoulli_var(b: &mut Bencher) {
8987
b.iter(|| {
9088
let mut accum = true;
9189
let mut p = 0.18;
92-
for _ in 0..::RAND_BENCH_N {
90+
for _ in 0..crate::RAND_BENCH_N {
9391
let d = Bernoulli::new(p).unwrap();
9492
accum ^= rng.sample(d);
9593
p += 0.0001;

benches/seq.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#![allow(non_snake_case)]
1111

1212
extern crate test;
13-
extern crate rand;
14-
extern crate rand_pcg;
1513

1614
use test::Bencher;
1715

@@ -49,7 +47,7 @@ fn seq_slice_choose_1_of_1000(b: &mut Bencher) {
4947
}
5048
s
5149
});
52-
b.bytes = size_of::<usize>() as u64 * ::RAND_BENCH_N;
50+
b.bytes = size_of::<usize>() as u64 * crate::RAND_BENCH_N;
5351
}
5452

5553
macro_rules! seq_slice_choose_multiple {
@@ -91,7 +89,7 @@ fn seq_iter_choose_from_1000(b: &mut Bencher) {
9189
}
9290
s
9391
});
94-
b.bytes = size_of::<usize>() as u64 * ::RAND_BENCH_N;
92+
b.bytes = size_of::<usize>() as u64 * crate::RAND_BENCH_N;
9593
}
9694

9795
#[derive(Clone)]

build.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.

examples/monte-carlo.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
2727
#![cfg(feature = "std")]
2828

29-
30-
extern crate rand;
31-
3229
use rand::distributions::{Distribution, Uniform};
3330

3431
fn main() {

examples/monty-hall.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
2929
#![cfg(feature = "std")]
3030

31-
32-
extern crate rand;
33-
3431
use rand::distributions::{Distribution, Uniform};
3532
use rand::Rng;
3633

rand_chacha/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ChaCha random number generator
1212
"""
1313
keywords = ["random", "rng", "chacha"]
1414
categories = ["algorithms", "no-std"]
15-
build = "build.rs"
15+
edition = "2018"
1616

1717
[badges]
1818
travis-ci = { repository = "rust-random/rand" }
@@ -22,9 +22,6 @@ appveyor = { repository = "rust-random/rand" }
2222
rand_core = { path = "../rand_core", version = "0.5" }
2323
c2-chacha = { version = "0.2.2", default-features = false }
2424

25-
[build-dependencies]
26-
autocfg = "0.1"
27-
2825
[features]
2926
default = ["std", "simd"]
3027
std = ["c2-chacha/std"]

rand_chacha/build.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

rand_chacha/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818

1919
#![cfg_attr(not(feature = "std"), no_std)]
2020

21-
extern crate c2_chacha;
22-
pub extern crate rand_core;
21+
pub use rand_core;
2322

2423
mod chacha;
2524

26-
pub use chacha::{ChaCha12Core, ChaCha12Rng, ChaCha20Core, ChaCha20Rng, ChaCha8Core, ChaCha8Rng};
25+
pub use crate::chacha::{ChaCha12Core, ChaCha12Rng, ChaCha20Core, ChaCha20Rng, ChaCha8Core, ChaCha8Rng};
2726

2827
/// ChaCha with 20 rounds
2928
pub type ChaChaRng = ChaCha20Rng;

rand_core/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Core random number generator traits and tools for implementation.
1212
"""
1313
keywords = ["random", "rng"]
1414
categories = ["algorithms", "no-std"]
15+
edition = "2018"
1516

1617
[badges]
1718
travis-ci = { repository = "rust-random/rand" }
@@ -20,9 +21,8 @@ appveyor = { repository = "rust-random/rand" }
2021
[features]
2122
std = ["alloc", "getrandom", "getrandom/std"] # use std library; should be default but for above bug
2223
alloc = [] # enables Vec and Box support without std
23-
serde1 = ["serde", "serde_derive"] # enables serde for BlockRng wrapper
24+
serde1 = ["serde"] # enables serde for BlockRng wrapper
2425

2526
[dependencies]
26-
serde = { version = "1", optional = true }
27-
serde_derive = { version = "^1.0.38", optional = true }
27+
serde = { version = "1", features = ["derive"], optional = true }
2828
getrandom = { version = "0.1", optional = true }

rand_core/src/block.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@
5252
5353
use core::convert::AsRef;
5454
use core::{fmt, ptr};
55-
use {RngCore, CryptoRng, SeedableRng, Error};
56-
use impls::{fill_via_u32_chunks, fill_via_u64_chunks};
55+
#[cfg(feature="serde1")] use serde::{Serialize, Deserialize};
56+
use crate::{RngCore, CryptoRng, SeedableRng, Error};
57+
use crate::impls::{fill_via_u32_chunks, fill_via_u64_chunks};
5758

5859
/// A trait for RNGs which do not generate random numbers individually, but in
5960
/// blocks (typically `[u32; N]`). This technique is commonly used by

rand_core/src/impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use core::ptr::copy_nonoverlapping;
2222
use core::slice;
2323
use core::cmp::min;
2424
use core::mem::size_of;
25-
use RngCore;
25+
use crate::RngCore;
2626

2727

2828
/// Implement `next_u64` via `next_u32`, little-endian order.

rand_core/src/lib.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,12 @@
3838
#![cfg_attr(not(feature="std"), no_std)]
3939
#![cfg_attr(all(feature="alloc", not(feature="std")), feature(alloc))]
4040

41-
#[cfg(feature="std")] extern crate core;
42-
#[cfg(all(feature = "alloc", not(feature="std")))] extern crate alloc;
43-
#[cfg(feature="serde1")] extern crate serde;
44-
#[cfg(feature="serde1")] #[macro_use] extern crate serde_derive;
45-
4641

4742
use core::default::Default;
4843
use core::convert::AsMut;
4944
use core::ptr::copy_nonoverlapping;
5045

46+
#[cfg(all(feature="alloc", not(feature="std")))] extern crate alloc;
5147
#[cfg(all(feature="alloc", not(feature="std")))] use alloc::boxed::Box;
5248

5349
pub use error::Error;
@@ -435,7 +431,7 @@ impl<R: RngCore + ?Sized> RngCore for Box<R> {
435431
}
436432

437433
#[cfg(feature="std")]
438-
impl std::io::Read for RngCore {
434+
impl std::io::Read for dyn RngCore {
439435
fn read(&mut self, buf: &mut [u8]) -> Result<usize, std::io::Error> {
440436
self.try_fill_bytes(buf)?;
441437
Ok(buf.len())

rand_distr/benches/distributions.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
#![feature(test)]
1010

11-
extern crate test;
12-
1311
const RAND_BENCH_N: u64 = 1000;
1412

1513
use std::mem::size_of;

rand_jitter/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ repository = "https://github.com/rust-random/rand"
88
documentation = "https://docs.rs/rand_jitter"
99
description = "Random number generator based on timing jitter"
1010
keywords = ["random", "rng", "os"]
11+
edition = "2018"
1112

1213
[badges]
1314
travis-ci = { repository = "rust-random/rand" }

rand_jitter/benches/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![feature(test)]
2-
extern crate test;
3-
extern crate rand_jitter;
2+
#![cfg(std)]
43

54
use test::Bencher;
65
use rand_jitter::rand_core::RngCore;

rand_jitter/src/dummy_log.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

rand_jitter/src/lib.rs

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,10 @@
5454
// compiler not optimize out code which does influence timing jitter, but is
5555
// technically dead code.
5656
#![no_std]
57-
pub extern crate rand_core;
5857
#[cfg(feature = "std")]
5958
extern crate std;
60-
#[cfg(feature = "log")]
61-
#[macro_use] extern crate log;
62-
#[cfg(any(target_os = "macos", target_os = "ios"))]
63-
extern crate libc;
64-
#[cfg(target_os = "windows")]
65-
extern crate winapi;
59+
60+
pub use rand_core;
6661

6762
// Coming from https://crates.io/crates/doc-comment
6863
#[cfg(test)]
@@ -76,21 +71,47 @@ macro_rules! doc_comment {
7671
#[cfg(test)]
7772
doc_comment!(include_str!("../README.md"));
7873

79-
#[cfg(not(feature = "log"))]
80-
#[macro_use] mod dummy_log;
74+
#[allow(unused)]
75+
macro_rules! trace { ($($x:tt)*) => (
76+
#[cfg(feature = "log")] {
77+
log::trace!($($x)*)
78+
}
79+
) }
80+
#[allow(unused)]
81+
macro_rules! debug { ($($x:tt)*) => (
82+
#[cfg(feature = "log")] {
83+
log::debug!($($x)*)
84+
}
85+
) }
86+
#[allow(unused)]
87+
macro_rules! info { ($($x:tt)*) => (
88+
#[cfg(feature = "log")] {
89+
log::info!($($x)*)
90+
}
91+
) }
92+
#[allow(unused)]
93+
macro_rules! warn { ($($x:tt)*) => (
94+
#[cfg(feature = "log")] {
95+
log::warn!($($x)*)
96+
}
97+
) }
98+
#[allow(unused)]
99+
macro_rules! error { ($($x:tt)*) => (
100+
#[cfg(feature = "log")] {
101+
log::error!($($x)*)
102+
}
103+
) }
104+
81105
#[cfg(feature = "std")]
82106
mod platform;
83107
mod error;
84108

85109
use rand_core::{RngCore, Error, impls};
86-
pub use error::TimerError;
110+
pub use crate::error::TimerError;
87111

88112
use core::{fmt, mem, ptr};
89113
#[cfg(feature = "std")]
90114
use std::sync::atomic::{AtomicUsize, Ordering};
91-
#[cfg(feature = "std")]
92-
#[allow(deprecated)] // Required for compatibility with Rust < 1.24.
93-
use std::sync::atomic::ATOMIC_USIZE_INIT;
94115

95116
const MEMORY_BLOCKS: usize = 64;
96117
const MEMORY_BLOCKSIZE: usize = 32;
@@ -185,8 +206,7 @@ impl Clone for JitterRng {
185206

186207
// Initialise to zero; must be positive
187208
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
188-
#[allow(deprecated)]
189-
static JITTER_ROUNDS: AtomicUsize = ATOMIC_USIZE_INIT;
209+
static JITTER_ROUNDS: AtomicUsize = AtomicUsize::new(0);
190210

191211
impl JitterRng {
192212
/// Create a new `JitterRng`. Makes use of `std::time` for a timer, or a

rand_jitter/tests/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
extern crate rand_jitter;
2-
extern crate rand_core;
3-
41
use rand_jitter::JitterRng;
52
#[cfg(feature = "std")]
63
use rand_core::RngCore;

rand_pcg/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,3 @@ serde = { version = "1", features = ["derive"], optional = true }
3030
# deps yet, see: https://github.com/rust-lang/cargo/issues/1596
3131
# We require at least 1.1.2 for i128 auto-detection
3232
bincode = { version = "1.1.2" }
33-
34-
[build-dependencies]
35-
autocfg = "0.1"

0 commit comments

Comments
 (0)