diff --git a/.travis.yml b/.travis.yml index 16facb724b8..27b72757c81 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,11 @@ matrix: - cargo test --tests --no-default-features - cargo test --package rand_core --no-default-features - cargo test --features serde1,log + - rust: 1.9.0 + install: + script: + # Ensure minimum rustc version for rand_core. + - cargo test --package rand_core --lib - rust: stable os: osx install: diff --git a/rand_core/README.md b/rand_core/README.md index 29492224ca7..451a21db707 100644 --- a/rand_core/README.md +++ b/rand_core/README.md @@ -4,7 +4,7 @@ [![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-lang-nursery/rand?svg=true)](https://ci.appveyor.com/project/alexcrichton/rand) [![Latest version](https://img.shields.io/crates/v/rand_core.svg)](https://crates.io/crates/rand_core) [![Documentation](https://docs.rs/rand_core/badge.svg)](https://docs.rs/rand_core) -[![Minimum rustc version](https://img.shields.io/badge/rustc-1.22+-yellow.svg)](https://github.com/rust-lang-nursery/rand#rust-version-requirements) +[![Minimum rustc version](https://img.shields.io/badge/rustc-1.9+-yellow.svg)](https://github.com/rust-lang-nursery/rand#rust-version-requirements) Core traits and error types of the [rand] library, plus tools for implementing RNGs. @@ -53,6 +53,16 @@ default features will also enable `std` support in `rand_core`. The `serde1` feature can be used to derive `Serialize` and `Deserialize` for RNG implementations that use the `BlockRng` or `BlockRng64` wrappers. +### Rust version requirements + +`rand_core` works with a wide range of Rustc versions, with the oldest supported +version being **Rustc 1.9.0**. The optional `serde1` feature requires a higher +Rustc version, as it depends on the minimum version supported by Serde. + +Travis CI always has a build with a pinned version of Rustc matching the oldest +supported Rust release. The current policy is that this can be updated in any +`rand_core` release if required, but the change must be noted in the changelog. + # License diff --git a/rand_core/src/error.rs b/rand_core/src/error.rs index 34cfbf8c8e4..d2a98590a4b 100644 --- a/rand_core/src/error.rs +++ b/rand_core/src/error.rs @@ -97,13 +97,14 @@ pub struct Error { impl Error { /// Create a new instance, with specified kind and a message. + #[cfg(feature="std")] pub fn new(kind: ErrorKind, msg: &'static str) -> Self { - #[cfg(feature="std")] { - Error { kind, msg, cause: None } - } - #[cfg(not(feature="std"))] { - Error { kind, msg } - } + Error { kind: kind, msg: msg, cause: None } + } + /// Create a new instance, with specified kind and a message. + #[cfg(not(feature="std"))] + pub fn new(kind: ErrorKind, msg: &'static str) -> Self { + Error { kind: kind, msg: msg, cause: None } } /// Create a new instance, with specified kind, message, and a @@ -119,7 +120,7 @@ impl Error { pub fn with_cause(kind: ErrorKind, msg: &'static str, cause: E) -> Self where E: Into> { - Error { kind, msg, cause: Some(cause.into()) } + Error { kind: kind, msg: msg, cause: Some(cause.into()) } } /// Create a new instance, with specified kind, message, and a @@ -128,7 +129,7 @@ impl Error { /// In `no_std` mode the *cause* is ignored. #[cfg(not(feature="std"))] pub fn with_cause(kind: ErrorKind, msg: &'static str, _cause: E) -> Self { - Error { kind, msg } + Error { kind: kind, msg: msg } } /// Take the cause, if any. This allows the embedded cause to be extracted. @@ -139,18 +140,24 @@ impl Error { } } +#[cfg(feature="std")] impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - #[cfg(feature="std")] { - if let Some(ref cause) = self.cause { - return write!(f, "{} ({}); cause: {}", - self.msg, self.kind.description(), cause); - } + if let Some(ref cause) = self.cause { + return write!(f, "{} ({}); cause: {}", + self.msg, self.kind.description(), cause); } write!(f, "{} ({})", self.msg, self.kind.description()) } } +#[cfg(not(feature="std"))] +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{} ({})", self.msg, self.kind.description()) + } +} + #[cfg(feature="std")] impl stdError for Error { fn description(&self) -> &str { diff --git a/rand_core/src/impls.rs b/rand_core/src/impls.rs index 530a2ed7d65..93604772fe5 100644 --- a/rand_core/src/impls.rs +++ b/rand_core/src/impls.rs @@ -212,7 +212,7 @@ impl BlockRng { pub fn new(core: R) -> BlockRng{ let results_empty = R::Results::default(); BlockRng { - core, + core: core, index: results_empty.as_ref().len(), results: results_empty, } @@ -355,7 +355,7 @@ impl SeedableRng for BlockRng { } fn from_rng(rng: S) -> Result { - Ok(Self::new(R::from_rng(rng)?)) + Ok(Self::new(try!(R::from_rng(rng)))) } } @@ -400,7 +400,7 @@ impl BlockRng64 { pub fn new(core: R) -> BlockRng64{ let results_empty = R::Results::default(); BlockRng64 { - core, + core: core, index: results_empty.as_ref().len(), half_used: false, results: results_empty, @@ -534,7 +534,7 @@ impl SeedableRng for BlockRng64 { } fn from_rng(rng: S) -> Result { - Ok(Self::new(R::from_rng(rng)?)) + Ok(Self::new(try!(R::from_rng(rng)))) } } diff --git a/rand_core/src/lib.rs b/rand_core/src/lib.rs index 74d4e591ed8..5a1ada441c8 100644 --- a/rand_core/src/lib.rs +++ b/rand_core/src/lib.rs @@ -381,7 +381,7 @@ pub trait SeedableRng: Sized { /// [`OsRng`]: ../rand/os/struct.OsRng.html fn from_rng(mut rng: R) -> Result { let mut seed = Self::Seed::default(); - rng.try_fill_bytes(seed.as_mut())?; + try!(rng.try_fill_bytes(seed.as_mut())); Ok(Self::from_seed(seed)) } }