Skip to content

Commit

Permalink
Fix no_std and alloc builds
Browse files Browse the repository at this point in the history
  • Loading branch information
vks committed Jun 12, 2019
1 parent 8a2ee19 commit 294d16c
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions rand_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use core::default::Default;
use core::convert::AsMut;
use core::ptr::copy_nonoverlapping;

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

pub use error::Error;
Expand Down
2 changes: 1 addition & 1 deletion src/distributions/uniform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ use crate::distributions::utils::{WideningMultiply, FloatSIMDUtils, FloatAsSIMD,

#[cfg(not(feature = "std"))]
#[allow(unused_imports)] // rustc doesn't detect that this is actually used
use distributions::utils::Float;
use crate::distributions::utils::Float;


#[cfg(feature="simd_support")]
Expand Down
4 changes: 3 additions & 1 deletion src/distributions/weighted/alias_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
use super::WeightedError;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use crate::alloc::vec::Vec;
#[cfg(not(feature = "std"))]
use crate::alloc::vec;
use core::fmt;
use core::iter::Sum;
use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
Expand Down
4 changes: 2 additions & 2 deletions src/distributions/weighted/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ pub mod alias_method;
use crate::Rng;
use crate::distributions::Distribution;
use crate::distributions::uniform::{UniformSampler, SampleUniform, SampleBorrow};
use ::core::cmp::PartialOrd;
use core::cmp::PartialOrd;
use core::fmt;

// Note that this whole module is only imported if feature="alloc" is enabled.
#[cfg(not(feature="std"))] use alloc::vec::Vec;
#[cfg(not(feature="std"))] use crate::alloc::vec::Vec;

/// A distribution using weighted sampling to pick a discretely selected
/// item.
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
#![cfg_attr(all(feature="alloc", not(feature="std")), feature(alloc))]
#![cfg_attr(all(feature="simd_support", feature="nightly"), feature(stdsimd))]

#![cfg(all(feature="alloc", not(feature="std")))]
extern crate alloc;

#[cfg(feature = "getrandom")]
use getrandom_package as getrandom;

Expand Down
5 changes: 3 additions & 2 deletions src/seq/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#[cfg(feature="alloc")] use core::slice;

#[cfg(feature="std")] use std::vec;
#[cfg(all(feature="alloc", not(feature="std")))] use alloc::vec::{self, Vec};
#[cfg(all(feature="alloc", not(feature="std")))] use crate::alloc::vec::{self, Vec};
// BTreeMap is not as fast in tests, but better than nothing.
#[cfg(feature="std")] use std::collections::{HashSet};
#[cfg(all(feature="alloc", not(feature="std")))] use alloc::collections::BTreeSet;
#[cfg(all(feature="alloc", not(feature="std")))] use crate::alloc::collections::BTreeSet;

#[cfg(feature="alloc")] use crate::distributions::{Distribution, Uniform, uniform::SampleUniform};
use crate::Rng;
Expand Down Expand Up @@ -326,6 +326,7 @@ where R: Rng + ?Sized, IndexVec: From<Vec<X>> {

#[cfg(test)]
mod test {
use crate::alloc::vec;
use super::*;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/seq/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#[cfg(feature="alloc")] use core::ops::Index;

#[cfg(all(feature="alloc", not(feature="std")))] use alloc::vec::Vec;
#[cfg(all(feature="alloc", not(feature="std")))] use crate::alloc::vec::Vec;

use crate::Rng;
#[cfg(feature="alloc")] use crate::distributions::WeightedError;
Expand Down

0 comments on commit 294d16c

Please sign in to comment.