Skip to content

Commit c070b43

Browse files
committed
Lower Rustc version requirement to 1.9 for rand_core
1 parent bd34459 commit c070b43

File tree

5 files changed

+41
-19
lines changed

5 files changed

+41
-19
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ matrix:
1414
- cargo test --tests --no-default-features
1515
- cargo test --package rand_core --no-default-features
1616
- cargo test --features serde1,log
17+
- rust: 1.9.0
18+
install:
19+
script:
20+
# Ensure minimum rustc version for rand_core.
21+
- cargo test --package rand_core --lib
1722
- rust: stable
1823
os: osx
1924
install:

rand_core/README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-lang-nursery/rand?svg=true)](https://ci.appveyor.com/project/alexcrichton/rand)
55
[![Latest version](https://img.shields.io/crates/v/rand_core.svg)](https://crates.io/crates/rand_core)
66
[![Documentation](https://docs.rs/rand_core/badge.svg)](https://docs.rs/rand_core)
7-
[![Minimum rustc version](https://img.shields.io/badge/rustc-1.22+-yellow.svg)](https://github.com/rust-lang-nursery/rand#rust-version-requirements)
7+
[![Minimum rustc version](https://img.shields.io/badge/rustc-1.9+-yellow.svg)](https://github.com/rust-lang-nursery/rand#rust-version-requirements)
88

99
Core traits and error types of the [rand] library, plus tools for implementing
1010
RNGs.
@@ -53,6 +53,16 @@ default features will also enable `std` support in `rand_core`.
5353
The `serde1` feature can be used to derive `Serialize` and `Deserialize` for RNG
5454
implementations that use the `BlockRng` or `BlockRng64` wrappers.
5555

56+
### Rust version requirements
57+
58+
`rand_core` works with a wide range of Rustc versions, with the oldest supported
59+
version being **Rustc 1.9.0**. The optional `serde1` feature requires a higher
60+
Rustc version, as it depends on the minimum version supported by Serde.
61+
62+
Travis CI always has a build with a pinned version of Rustc matching the oldest
63+
supported Rust release. The current policy is that this can be updated in any
64+
`rand_core` release if required, but the change must be noted in the changelog.
65+
5666

5767
# License
5868

rand_core/src/error.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,14 @@ pub struct Error {
9797

9898
impl Error {
9999
/// Create a new instance, with specified kind and a message.
100+
#[cfg(feature="std")]
100101
pub fn new(kind: ErrorKind, msg: &'static str) -> Self {
101-
#[cfg(feature="std")] {
102-
Error { kind, msg, cause: None }
103-
}
104-
#[cfg(not(feature="std"))] {
105-
Error { kind, msg }
106-
}
102+
Error { kind: kind, msg: msg, cause: None }
103+
}
104+
/// Create a new instance, with specified kind and a message.
105+
#[cfg(not(feature="std"))]
106+
pub fn new(kind: ErrorKind, msg: &'static str) -> Self {
107+
Error { kind: kind, msg: msg, cause: None }
107108
}
108109

109110
/// Create a new instance, with specified kind, message, and a
@@ -119,7 +120,7 @@ impl Error {
119120
pub fn with_cause<E>(kind: ErrorKind, msg: &'static str, cause: E) -> Self
120121
where E: Into<Box<stdError + Send + Sync>>
121122
{
122-
Error { kind, msg, cause: Some(cause.into()) }
123+
Error { kind: kind, msg: msg, cause: Some(cause.into()) }
123124
}
124125

125126
/// Create a new instance, with specified kind, message, and a
@@ -128,7 +129,7 @@ impl Error {
128129
/// In `no_std` mode the *cause* is ignored.
129130
#[cfg(not(feature="std"))]
130131
pub fn with_cause<E>(kind: ErrorKind, msg: &'static str, _cause: E) -> Self {
131-
Error { kind, msg }
132+
Error { kind: kind, msg: msg }
132133
}
133134

134135
/// Take the cause, if any. This allows the embedded cause to be extracted.
@@ -139,18 +140,24 @@ impl Error {
139140
}
140141
}
141142

143+
#[cfg(feature="std")]
142144
impl fmt::Display for Error {
143145
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
144-
#[cfg(feature="std")] {
145-
if let Some(ref cause) = self.cause {
146-
return write!(f, "{} ({}); cause: {}",
147-
self.msg, self.kind.description(), cause);
148-
}
146+
if let Some(ref cause) = self.cause {
147+
return write!(f, "{} ({}); cause: {}",
148+
self.msg, self.kind.description(), cause);
149149
}
150150
write!(f, "{} ({})", self.msg, self.kind.description())
151151
}
152152
}
153153

154+
#[cfg(not(feature="std"))]
155+
impl fmt::Display for Error {
156+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
157+
write!(f, "{} ({})", self.msg, self.kind.description())
158+
}
159+
}
160+
154161
#[cfg(feature="std")]
155162
impl stdError for Error {
156163
fn description(&self) -> &str {

rand_core/src/impls.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl<R: BlockRngCore> BlockRng<R> {
212212
pub fn new(core: R) -> BlockRng<R>{
213213
let results_empty = R::Results::default();
214214
BlockRng {
215-
core,
215+
core: core,
216216
index: results_empty.as_ref().len(),
217217
results: results_empty,
218218
}
@@ -355,7 +355,7 @@ impl<R: BlockRngCore + SeedableRng> SeedableRng for BlockRng<R> {
355355
}
356356

357357
fn from_rng<S: RngCore>(rng: S) -> Result<Self, Error> {
358-
Ok(Self::new(R::from_rng(rng)?))
358+
Ok(Self::new(try!(R::from_rng(rng))))
359359
}
360360
}
361361

@@ -400,7 +400,7 @@ impl<R: BlockRngCore> BlockRng64<R> {
400400
pub fn new(core: R) -> BlockRng64<R>{
401401
let results_empty = R::Results::default();
402402
BlockRng64 {
403-
core,
403+
core: core,
404404
index: results_empty.as_ref().len(),
405405
half_used: false,
406406
results: results_empty,
@@ -534,7 +534,7 @@ impl<R: BlockRngCore + SeedableRng> SeedableRng for BlockRng64<R> {
534534
}
535535

536536
fn from_rng<S: RngCore>(rng: S) -> Result<Self, Error> {
537-
Ok(Self::new(R::from_rng(rng)?))
537+
Ok(Self::new(try!(R::from_rng(rng))))
538538
}
539539
}
540540

rand_core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ pub trait SeedableRng: Sized {
381381
/// [`OsRng`]: ../rand/os/struct.OsRng.html
382382
fn from_rng<R: RngCore>(mut rng: R) -> Result<Self, Error> {
383383
let mut seed = Self::Seed::default();
384-
rng.try_fill_bytes(seed.as_mut())?;
384+
try!(rng.try_fill_bytes(seed.as_mut()));
385385
Ok(Self::from_seed(seed))
386386
}
387387
}

0 commit comments

Comments
 (0)