Skip to content

Move rustc_version dep to autocfg #664

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
Dec 14, 2018
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ wasm-bindgen = { version = "0.2.12", optional = true }
average = "0.9.2"

[build-dependencies]
rustc_version = "0.2"
autocfg = "0.1"

[package.metadata.docs.rs]
all-features = true
18 changes: 7 additions & 11 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
extern crate rustc_version;
use rustc_version::{version, Version};
extern crate autocfg;

fn main() {
if version().unwrap() >= Version::parse("1.25.0").unwrap() {
println!("cargo:rustc-cfg=rust_1_25");
}
if version().unwrap() >= Version::parse("1.26.0").unwrap() {
println!("cargo:rustc-cfg=rust_1_26");
}
if version().unwrap() >= Version::parse("1.27.0").unwrap() {
println!("cargo:rustc-cfg=rust_1_27");
}
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);
}
2 changes: 1 addition & 1 deletion rand_chacha/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ appveyor = { repository = "rust-random/rand" }
rand_core = { path = "../rand_core", version = ">=0.2, <0.4", default-features=false }

[build-dependencies]
rustc_version = "0.2"
autocfg = "0.1"
9 changes: 4 additions & 5 deletions rand_chacha/build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
extern crate rustc_version;
use rustc_version::{version, Version};
extern crate autocfg;

fn main() {
if version().unwrap() >= Version::parse("1.26.0").unwrap() {
println!("cargo:rustc-cfg=rust_1_26");
}
println!("cargo:rerun-if-changed=build.rs");
let ac = autocfg::new();
ac.emit_rustc_version(1, 26);
}
6 changes: 3 additions & 3 deletions rand_chacha/src/chacha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl ChaChaRng {
/// byte-offset.
///
/// Note: this function is currently only available with Rust 1.26 or later.
#[cfg(rust_1_26)]
#[cfg(rustc_1_26)]
pub fn get_word_pos(&self) -> u128 {
let mut c = (self.0.core.state[13] as u64) << 32
| (self.0.core.state[12] as u64);
Expand All @@ -135,7 +135,7 @@ impl ChaChaRng {
/// 60 bits.
///
/// Note: this function is currently only available with Rust 1.26 or later.
#[cfg(rust_1_26)]
#[cfg(rustc_1_26)]
pub fn set_word_pos(&mut self, word_offset: u128) {
let index = (word_offset as usize) & 0xF;
let counter = (word_offset >> 4) as u64;
Expand Down Expand Up @@ -330,7 +330,7 @@ mod test {
}

#[test]
#[cfg(rust_1_26)]
#[cfg(rustc_1_26)]
fn test_chacha_true_values_c() {
// Test vector 4 from
// https://tools.ietf.org/html/draft-nir-cfrg-chacha20-poly1305-04
Expand Down
2 changes: 1 addition & 1 deletion rand_pcg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ serde_derive = { version = "^1.0.38", optional = true }
bincode = { version = "1", features = ["i128"] }

[build-dependencies]
rustc_version = "0.2"
autocfg = "0.1"
9 changes: 4 additions & 5 deletions rand_pcg/build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
extern crate rustc_version;
use rustc_version::{version, Version};
extern crate autocfg;

fn main() {
if version().unwrap() >= Version::parse("1.26.0").unwrap() {
println!("cargo:rustc-cfg=rust_1_26");
}
println!("cargo:rerun-if-changed=build.rs");
let ac = autocfg::new();
ac.emit_rustc_version(1, 26);
}
4 changes: 2 additions & 2 deletions rand_pcg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extern crate rand_core;
#[cfg(feature="serde1")] #[macro_use] extern crate serde_derive;

mod pcg64;
#[cfg(rust_1_26)] mod pcg128;
#[cfg(rustc_1_26)] mod pcg128;

pub use self::pcg64::{Pcg32, Lcg64Xsh32};
#[cfg(rust_1_26)] pub use self::pcg128::{Pcg64Mcg, Mcg128Xsl64};
#[cfg(rustc_1_26)] pub use self::pcg128::{Pcg64Mcg, Mcg128Xsl64};
2 changes: 1 addition & 1 deletion rand_pcg/tests/mcg128xsl64.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg(rust_1_26)]
#![cfg(rustc_1_26)]
extern crate rand_pcg;
extern crate rand_core;
#[cfg(all(feature="serde1", test))] extern crate bincode;
Expand Down
4 changes: 2 additions & 2 deletions src/deprecated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ impl SeedableRng for ChaChaRng {
}

impl ChaChaRng {
#[cfg(rust_1_26)]
#[cfg(rustc_1_26)]
pub fn get_word_pos(&self) -> u128 {
self.0.get_word_pos()
}

#[cfg(rust_1_26)]
#[cfg(rustc_1_26)]
pub fn set_word_pos(&mut self, word_offset: u128) {
self.0.set_word_pos(word_offset)
}
Expand Down
8 changes: 4 additions & 4 deletions src/distributions/integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Distribution<u64> for Standard {
}
}

#[cfg(rust_1_26)]
#[cfg(rustc_1_26)]
impl Distribution<u128> for Standard {
#[inline]
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> u128 {
Expand Down Expand Up @@ -85,7 +85,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(rust_1_26)] impl_int_from_uint! { i128, u128 }
#[cfg(rustc_1_26)] impl_int_from_uint! { i128, u128 }
impl_int_from_uint! { isize, usize }

#[cfg(feature="simd_support")]
Expand Down Expand Up @@ -147,15 +147,15 @@ mod tests {
rng.sample::<i16, _>(Standard);
rng.sample::<i32, _>(Standard);
rng.sample::<i64, _>(Standard);
#[cfg(rust_1_26)]
#[cfg(rustc_1_26)]
rng.sample::<i128, _>(Standard);

rng.sample::<usize, _>(Standard);
rng.sample::<u8, _>(Standard);
rng.sample::<u16, _>(Standard);
rng.sample::<u32, _>(Standard);
rng.sample::<u64, _>(Standard);
#[cfg(rust_1_26)]
#[cfg(rustc_1_26)]
rng.sample::<u128, _>(Standard);
}
}
6 changes: 3 additions & 3 deletions src/distributions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
//! [`Weibull`]: struct.Weibull.html
//! [`WeightedIndex`]: struct.WeightedIndex.html

#[cfg(any(rust_1_26, features="nightly"))]
#[cfg(any(rustc_1_26, features="nightly"))]
use core::iter;
use Rng;

Expand Down Expand Up @@ -316,7 +316,7 @@ impl<'a, D, R, T> Iterator for DistIter<'a, D, R, T>
}
}

#[cfg(rust_1_26)]
#[cfg(rustc_1_26)]
impl<'a, D, R, T> iter::FusedIterator for DistIter<'a, D, R, T>
where D: Distribution<T>, R: Rng + 'a {}

Expand All @@ -328,7 +328,7 @@ impl<'a, D, R, T> iter::TrustedLen for DistIter<'a, D, R, T>
/// A generic random value distribution, implemented for many primitive types.
/// Usually generates values with a numerically uniform distribution, and with a
/// range appropriate to the type.
///
///
/// ## Built-in Implementations
///
/// Assuming the provided `Rng` is well-behaved, these implementations
Expand Down
26 changes: 13 additions & 13 deletions src/distributions/uniform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@

#[cfg(feature = "std")]
use std::time::Duration;
#[cfg(all(not(feature = "std"), rust_1_25))]
#[cfg(all(not(feature = "std"), rustc_1_25))]
use core::time::Duration;

use Rng;
Expand Down Expand Up @@ -277,7 +277,7 @@ impl<X: SampleUniform> From<::core::ops::Range<X>> for Uniform<X> {
}
}

#[cfg(rust_1_27)]
#[cfg(rustc_1_27)]
impl<X: SampleUniform> From<::core::ops::RangeInclusive<X>> for Uniform<X> {
fn from(r: ::core::ops::RangeInclusive<X>) -> Uniform<X> {
Uniform::new_inclusive(r.start(), r.end())
Expand Down Expand Up @@ -472,15 +472,15 @@ uniform_int_impl! { i8, i8, u8, i32, u32 }
uniform_int_impl! { i16, i16, u16, i32, u32 }
uniform_int_impl! { i32, i32, u32, i32, u32 }
uniform_int_impl! { i64, i64, u64, i64, u64 }
#[cfg(rust_1_26)]
#[cfg(rustc_1_26)]
uniform_int_impl! { i128, i128, u128, u128, u128 }
uniform_int_impl! { isize, isize, usize, isize, usize }
uniform_int_impl! { u8, i8, u8, i32, u32 }
uniform_int_impl! { u16, i16, u16, i32, u32 }
uniform_int_impl! { u32, i32, u32, i32, u32 }
uniform_int_impl! { u64, i64, u64, i64, u64 }
uniform_int_impl! { usize, isize, usize, isize, usize }
#[cfg(rust_1_26)]
#[cfg(rustc_1_26)]
uniform_int_impl! { u128, u128, u128, i128, u128 }

#[cfg(all(feature = "simd_support", feature = "nightly"))]
Expand Down Expand Up @@ -835,14 +835,14 @@ uniform_float_impl! { f64x8, u64x8, f64, u64, 64 - 52 }
///
/// [`UniformSampler`]: trait.UniformSampler.html
/// [`Uniform`]: struct.Uniform.html
#[cfg(any(feature = "std", rust_1_25))]
#[cfg(any(feature = "std", rustc_1_25))]
#[derive(Clone, Copy, Debug)]
pub struct UniformDuration {
mode: UniformDurationMode,
offset: u32,
}

#[cfg(any(feature = "std", rust_1_25))]
#[cfg(any(feature = "std", rustc_1_25))]
#[derive(Debug, Copy, Clone)]
enum UniformDurationMode {
Small {
Expand All @@ -859,12 +859,12 @@ enum UniformDurationMode {
}
}

#[cfg(any(feature = "std", rust_1_25))]
#[cfg(any(feature = "std", rustc_1_25))]
impl SampleUniform for Duration {
type Sampler = UniformDuration;
}

#[cfg(any(feature = "std", rust_1_25))]
#[cfg(any(feature = "std", rustc_1_25))]
impl UniformSampler for UniformDuration {
type X = Duration;

Expand Down Expand Up @@ -989,7 +989,7 @@ mod tests {
fn test_integers() {
use core::{i8, i16, i32, i64, isize};
use core::{u8, u16, u32, u64, usize};
#[cfg(rust_1_26)]
#[cfg(rustc_1_26)]
use core::{i128, u128};

let mut rng = ::test::rng(251);
Expand Down Expand Up @@ -1053,7 +1053,7 @@ mod tests {
}
t!(i8, i16, i32, i64, isize,
u8, u16, u32, u64, usize);
#[cfg(rust_1_26)]
#[cfg(rustc_1_26)]
t!(i128, u128);

#[cfg(all(feature = "simd_support", feature = "nightly"))]
Expand Down Expand Up @@ -1208,11 +1208,11 @@ mod tests {


#[test]
#[cfg(any(feature = "std", rust_1_25))]
#[cfg(any(feature = "std", rustc_1_25))]
fn test_durations() {
#[cfg(feature = "std")]
use std::time::Duration;
#[cfg(all(not(feature = "std"), rust_1_25))]
#[cfg(all(not(feature = "std"), rustc_1_25))]
use core::time::Duration;

let mut rng = ::test::rng(253);
Expand Down Expand Up @@ -1283,7 +1283,7 @@ mod tests {
assert_eq!(r.inner.scale, 5.0);
}

#[cfg(rust_1_27)]
#[cfg(rustc_1_27)]
#[test]
fn test_uniform_from_std_range_inclusive() {
let r = Uniform::from(2u32..=6);
Expand Down
6 changes: 3 additions & 3 deletions src/distributions/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ macro_rules! wmul_impl {
wmul_impl! { u8, u16, 8 }
wmul_impl! { u16, u32, 16 }
wmul_impl! { u32, u64, 32 }
#[cfg(rust_1_26)]
#[cfg(rustc_1_26)]
wmul_impl! { u64, u128, 64 }

// This code is a translation of the __mulddi3 function in LLVM's
Expand Down Expand Up @@ -125,9 +125,9 @@ macro_rules! wmul_impl_large {
)+
};
}
#[cfg(not(rust_1_26))]
#[cfg(not(rustc_1_26))]
wmul_impl_large! { u64, 32 }
#[cfg(rust_1_26)]
#[cfg(rustc_1_26)]
wmul_impl_large! { u128, 64 }

macro_rules! wmul_impl_usize {
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,13 +549,13 @@ macro_rules! impl_as_byte_slice {
impl_as_byte_slice!(u16);
impl_as_byte_slice!(u32);
impl_as_byte_slice!(u64);
#[cfg(rust_1_26)] impl_as_byte_slice!(u128);
#[cfg(rustc_1_26)] impl_as_byte_slice!(u128);
impl_as_byte_slice!(usize);
impl_as_byte_slice!(i8);
impl_as_byte_slice!(i16);
impl_as_byte_slice!(i32);
impl_as_byte_slice!(i64);
#[cfg(rust_1_26)] impl_as_byte_slice!(i128);
#[cfg(rustc_1_26)] impl_as_byte_slice!(i128);
impl_as_byte_slice!(isize);

macro_rules! impl_as_byte_slice_arrays {
Expand Down
4 changes: 2 additions & 2 deletions src/rngs/small.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

use {RngCore, SeedableRng, Error};

#[cfg(all(rust_1_26, target_pointer_width = "64"))]
#[cfg(all(rustc_1_26, target_pointer_width = "64"))]
type Rng = ::rand_pcg::Pcg64Mcg;
#[cfg(not(all(rust_1_26, target_pointer_width = "64")))]
#[cfg(not(all(rustc_1_26, target_pointer_width = "64")))]
type Rng = ::rand_pcg::Pcg32;

/// An RNG recommended when small state, cheap initialization and good
Expand Down