Skip to content

run rustfmt on librand folder #33937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/librand/chacha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

//! The ChaCha random number generator.

use {Rng, SeedableRng, Rand};
use {Rand, Rng, SeedableRng};

const KEY_WORDS: usize = 8; // 8 words for the 256-bit key
const STATE_WORDS: usize = 16;
Expand Down Expand Up @@ -216,7 +216,8 @@ mod tests {
let s = ::test::rng().gen_iter::<u32>().take(8).collect::<Vec<u32>>();
let mut ra: ChaChaRng = SeedableRng::from_seed(&*s);
let mut rb: ChaChaRng = SeedableRng::from_seed(&*s);
assert!(ra.gen_ascii_chars().take(100)
assert!(ra.gen_ascii_chars()
.take(100)
.eq(rb.gen_ascii_chars().take(100)));
}

Expand All @@ -225,7 +226,8 @@ mod tests {
let seed: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7];
let mut ra: ChaChaRng = SeedableRng::from_seed(seed);
let mut rb: ChaChaRng = SeedableRng::from_seed(seed);
assert!(ra.gen_ascii_chars().take(100)
assert!(ra.gen_ascii_chars()
.take(100)
.eq(rb.gen_ascii_chars().take(100)));
}

Expand Down
6 changes: 3 additions & 3 deletions src/librand/distributions/exponential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#[cfg(not(test))] // only necessary for no_std
use FloatMath;

use {Rng, Rand};
use distributions::{ziggurat, ziggurat_tables, Sample, IndependentSample};
use {Rand, Rng};
use distributions::{IndependentSample, Sample, ziggurat, ziggurat_tables};

/// A wrapper around an `f64` to generate Exp(1) random numbers.
///
Expand Down Expand Up @@ -88,7 +88,7 @@ impl IndependentSample<f64> for Exp {

#[cfg(test)]
mod tests {
use distributions::{Sample, IndependentSample};
use distributions::{IndependentSample, Sample};
use super::Exp;

#[test]
Expand Down
8 changes: 4 additions & 4 deletions src/librand/distributions/gamma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use self::ChiSquaredRepr::*;
#[cfg(not(test))] // only necessary for no_std
use FloatMath;

use {Rng, Open01};
use {Open01, Rng};
use super::normal::StandardNormal;
use super::{IndependentSample, Sample, Exp};
use super::{Exp, IndependentSample, Sample};

/// The Gamma distribution `Gamma(shape, scale)` distribution.
///
Expand Down Expand Up @@ -291,8 +291,8 @@ impl IndependentSample<f64> for StudentT {

#[cfg(test)]
mod tests {
use distributions::{Sample, IndependentSample};
use super::{ChiSquared, StudentT, FisherF};
use distributions::{IndependentSample, Sample};
use super::{ChiSquared, FisherF, StudentT};

#[test]
fn test_chi_squared_one() {
Expand Down
10 changes: 5 additions & 5 deletions src/librand/distributions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ use core::num::Float;

use core::marker::PhantomData;

use {Rng, Rand};
use {Rand, Rng};

pub use self::range::Range;
pub use self::gamma::{Gamma, ChiSquared, FisherF, StudentT};
pub use self::normal::{Normal, LogNormal};
pub use self::gamma::{ChiSquared, FisherF, Gamma, StudentT};
pub use self::normal::{LogNormal, Normal};
pub use self::exponential::Exp;

pub mod range;
Expand Down Expand Up @@ -266,8 +266,8 @@ fn ziggurat<R: Rng, P, Z>(rng: &mut R,

#[cfg(test)]
mod tests {
use {Rng, Rand};
use super::{RandSample, WeightedChoice, Weighted, Sample, IndependentSample};
use {Rand, Rng};
use super::{IndependentSample, RandSample, Sample, Weighted, WeightedChoice};

#[derive(PartialEq, Debug)]
struct ConstRand(usize);
Expand Down
8 changes: 4 additions & 4 deletions src/librand/distributions/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#[cfg(not(test))] // only necessary for no_std
use FloatMath;

use {Rng, Rand, Open01};
use distributions::{ziggurat, ziggurat_tables, Sample, IndependentSample};
use {Open01, Rand, Rng};
use distributions::{IndependentSample, Sample, ziggurat, ziggurat_tables};

/// A wrapper around an `f64` to generate N(0, 1) random numbers
/// (a.k.a. a standard normal, or Gaussian).
Expand Down Expand Up @@ -145,8 +145,8 @@ impl IndependentSample<f64> for LogNormal {

#[cfg(test)]
mod tests {
use distributions::{Sample, IndependentSample};
use super::{Normal, LogNormal};
use distributions::{IndependentSample, Sample};
use super::{LogNormal, Normal};

#[test]
fn test_normal() {
Expand Down
4 changes: 2 additions & 2 deletions src/librand/distributions/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use core::marker::Sized;
use Rng;
use distributions::{Sample, IndependentSample};
use distributions::{IndependentSample, Sample};

/// Sample values uniformly between two bounds.
///
Expand Down Expand Up @@ -148,7 +148,7 @@ float_impl! { f64 }

#[cfg(test)]
mod tests {
use distributions::{Sample, IndependentSample};
use distributions::{IndependentSample, Sample};
use super::Range;

#[should_panic]
Expand Down
16 changes: 10 additions & 6 deletions src/librand/isaac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use core::slice;
use core::iter::repeat;
use core::num::Wrapping as w;

use {Rng, SeedableRng, Rand};
use {Rand, Rng, SeedableRng};

type w32 = w<u32>;
type w64 = w<u64>;
Expand Down Expand Up @@ -591,22 +591,24 @@ mod tests {
use std::prelude::v1::*;

use {Rng, SeedableRng};
use super::{IsaacRng, Isaac64Rng};
use super::{Isaac64Rng, IsaacRng};

#[test]
fn test_rng_32_rand_seeded() {
let s = ::test::rng().gen_iter::<u32>().take(256).collect::<Vec<u32>>();
let mut ra: IsaacRng = SeedableRng::from_seed(&s[..]);
let mut rb: IsaacRng = SeedableRng::from_seed(&s[..]);
assert!(ra.gen_ascii_chars().take(100)
assert!(ra.gen_ascii_chars()
.take(100)
.eq(rb.gen_ascii_chars().take(100)));
}
#[test]
fn test_rng_64_rand_seeded() {
let s = ::test::rng().gen_iter::<u64>().take(256).collect::<Vec<u64>>();
let mut ra: Isaac64Rng = SeedableRng::from_seed(&s[..]);
let mut rb: Isaac64Rng = SeedableRng::from_seed(&s[..]);
assert!(ra.gen_ascii_chars().take(100)
assert!(ra.gen_ascii_chars()
.take(100)
.eq(rb.gen_ascii_chars().take(100)));
}

Expand All @@ -615,15 +617,17 @@ mod tests {
let seed: &[_] = &[1, 23, 456, 7890, 12345];
let mut ra: IsaacRng = SeedableRng::from_seed(seed);
let mut rb: IsaacRng = SeedableRng::from_seed(seed);
assert!(ra.gen_ascii_chars().take(100)
assert!(ra.gen_ascii_chars()
.take(100)
.eq(rb.gen_ascii_chars().take(100)));
}
#[test]
fn test_rng_64_seeded() {
let seed: &[_] = &[1, 23, 456, 7890, 12345];
let mut ra: Isaac64Rng = SeedableRng::from_seed(seed);
let mut rb: Isaac64Rng = SeedableRng::from_seed(seed);
assert!(ra.gen_ascii_chars().take(100)
assert!(ra.gen_ascii_chars()
.take(100)
.eq(rb.gen_ascii_chars().take(100)));
}

Expand Down
10 changes: 5 additions & 5 deletions src/librand/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ use core::f64;
use core::intrinsics;
use core::marker::PhantomData;

pub use isaac::{IsaacRng, Isaac64Rng};
pub use isaac::{Isaac64Rng, IsaacRng};
pub use chacha::ChaChaRng;

use distributions::{Range, IndependentSample};
use distributions::{IndependentSample, Range};
use distributions::range::SampleRange;

#[cfg(test)]
Expand All @@ -67,7 +67,7 @@ mod rand_impls;
// depend on libstd. This will go away when librand is integrated
// into libstd.
#[doc(hidden)]
trait FloatMath : Sized {
trait FloatMath: Sized {
fn exp(self) -> Self;
fn ln(self) -> Self;
fn sqrt(self) -> Self;
Expand Down Expand Up @@ -102,14 +102,14 @@ impl FloatMath for f64 {

/// A type that can be randomly generated using an `Rng`.
#[doc(hidden)]
pub trait Rand : Sized {
pub trait Rand: Sized {
/// Generates a random instance of this type using the specified source of
/// randomness.
fn rand<R: Rng>(rng: &mut R) -> Self;
}

/// A random number generator.
pub trait Rng : Sized {
pub trait Rng: Sized {
/// Return the next random u32.
///
/// This rarely needs to be called directly, prefer `r.gen()` to
Expand Down
11 changes: 6 additions & 5 deletions src/librand/reseeding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ impl<S, R: SeedableRng<S>, Rsdr: Reseeder<R> + Default>
self.bytes_generated = 0;
}

/// Create a new `ReseedingRng` from the given reseeder and
/// seed. This uses a default value for `generation_threshold`.
/// Create a new `ReseedingRng` from the given reseeder and
/// seed. This uses a default value for `generation_threshold`.
fn from_seed((rsdr, seed): (Rsdr, S)) -> ReseedingRng<R, Rsdr> {
ReseedingRng {
rng: SeedableRng::from_seed(seed),
Expand Down Expand Up @@ -122,8 +122,8 @@ impl Default for ReseedWithDefault {
mod tests {
use std::prelude::v1::*;

use super::{ReseedingRng, ReseedWithDefault};
use {SeedableRng, Rng};
use super::{ReseedWithDefault, ReseedingRng};
use {Rng, SeedableRng};

struct Counter {
i: u32,
Expand Down Expand Up @@ -166,7 +166,8 @@ mod tests {
fn test_rng_seeded() {
let mut ra: MyRng = SeedableRng::from_seed((ReseedWithDefault, 2));
let mut rb: MyRng = SeedableRng::from_seed((ReseedWithDefault, 2));
assert!(ra.gen_ascii_chars().take(100)
assert!(ra.gen_ascii_chars()
.take(100)
.eq(rb.gen_ascii_chars().take(100)));
}

Expand Down