Skip to content

Commit 0aa3b88

Browse files
committed
auto merge of #12650 : huonw/rust/librand, r=alexcrichton
Move std::rand to a separate rand crate This functionality is not super-core and so doesn't need to be included in std. It's possible that std may need rand (it does a little bit now, for io::test) in which case the functionality required could be moved to a secret hidden module and reexposed by librand. Unfortunately, using #[deprecated] here is hard: there's too much to mock to make it feasible, since we have to ensure that programs still typecheck to reach the linting phase. Also, deprecates/removes `rand::rng` (this time using `#[deprecated]`), since it's too easy to accidentally use inside a loop, making things very slow (have to read randomness from the OS and seed the RNG each time.)
2 parents 74bfa71 + 689f197 commit 0aa3b88

File tree

91 files changed

+329
-280
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+329
-280
lines changed

mk/crates.mk

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@
5050
################################################################################
5151

5252
TARGET_CRATES := std extra green rustuv native flate arena glob term semver \
53-
uuid serialize sync getopts collections num test time
53+
uuid serialize sync getopts collections num test time rand
5454
HOST_CRATES := syntax rustc rustdoc fourcc hexfloat
5555
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
5656
TOOLS := compiletest rustdoc rustc
5757

5858
DEPS_std := native:rustrt native:compiler-rt
59-
DEPS_extra := std term sync serialize getopts collections time
60-
DEPS_green := std native:context_switch
59+
DEPS_extra := std term sync serialize getopts collections time rand
60+
DEPS_green := std rand native:context_switch
6161
DEPS_rustuv := std native:uv native:uv_support
6262
DEPS_native := std
6363
DEPS_syntax := std term serialize collections
@@ -71,15 +71,16 @@ DEPS_glob := std
7171
DEPS_serialize := std collections
7272
DEPS_term := std collections
7373
DEPS_semver := std
74-
DEPS_uuid := std serialize
74+
DEPS_uuid := std serialize rand
7575
DEPS_sync := std
7676
DEPS_getopts := std
77-
DEPS_collections := std
77+
DEPS_collections := std rand
7878
DEPS_fourcc := syntax std
7979
DEPS_hexfloat := syntax std
80-
DEPS_num := std
80+
DEPS_num := std rand
8181
DEPS_test := std extra collections getopts serialize term
8282
DEPS_time := std serialize
83+
DEPS_rand := std
8384

8485
TOOL_DEPS_compiletest := test green rustuv getopts
8586
TOOL_DEPS_rustdoc := rustdoc native

src/doc/guide-tasks.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ concurrency at this writing:
5050
* [`sync::DuplexStream`] - An extension of `pipes::stream` that allows both sending and receiving,
5151
* [`sync::SyncChan`] - An extension of `pipes::stream` that provides synchronous message sending,
5252
* [`sync::SyncPort`] - An extension of `pipes::stream` that acknowledges each message received,
53-
* [`sync::rendezvous`] - Creates a stream whose channel, upon sending a message, blocks until the
53+
* [`sync::rendezvous`] - Creates a stream whose channel, upon sending a message, blocks until the
5454
message is received.
5555
* [`sync::Arc`] - The Arc (atomically reference counted) type, for safely sharing immutable data,
5656
* [`sync::RWArc`] - A dual-mode Arc protected by a reader-writer lock,
5757
* [`sync::MutexArc`] - An Arc with mutable data protected by a blocking mutex,
5858
* [`sync::Semaphore`] - A counting, blocking, bounded-waiting semaphore,
59-
* [`sync::Mutex`] - A blocking, bounded-waiting, mutual exclusion lock with an associated
59+
* [`sync::Mutex`] - A blocking, bounded-waiting, mutual exclusion lock with an associated
6060
FIFO condition variable,
6161
* [`sync::RWLock`] - A blocking, no-starvation, reader-writer lock with an associated condvar,
6262
* [`sync::Barrier`] - A barrier enables multiple tasks to synchronize the beginning
@@ -343,8 +343,8 @@ a single large vector of floats. Each task needs the full vector to perform its
343343

344344
~~~
345345
# extern crate sync;
346+
extern crate rand;
346347
# use std::vec;
347-
# use std::rand;
348348
use sync::Arc;
349349
350350
fn pnorm(nums: &~[f64], p: uint) -> f64 {
@@ -376,9 +376,9 @@ created by the line
376376

377377
~~~
378378
# extern crate sync;
379+
# extern crate rand;
379380
# use sync::Arc;
380381
# use std::vec;
381-
# use std::rand;
382382
# fn main() {
383383
# let numbers = vec::from_fn(1000000, |_| rand::random::<f64>());
384384
let numbers_arc=Arc::new(numbers);
@@ -389,9 +389,9 @@ and a clone of it is sent to each task
389389

390390
~~~
391391
# extern crate sync;
392+
# extern crate rand;
392393
# use sync::Arc;
393394
# use std::vec;
394-
# use std::rand;
395395
# fn main() {
396396
# let numbers=vec::from_fn(1000000, |_| rand::random::<f64>());
397397
# let numbers_arc = Arc::new(numbers);
@@ -406,9 +406,9 @@ Each task recovers the underlying data by
406406

407407
~~~
408408
# extern crate sync;
409+
# extern crate rand;
409410
# use sync::Arc;
410411
# use std::vec;
411-
# use std::rand;
412412
# fn main() {
413413
# let numbers=vec::from_fn(1000000, |_| rand::random::<f64>());
414414
# let numbers_arc=Arc::new(numbers);

src/doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2529,7 +2529,7 @@ of type `ABC` can be randomly generated and converted to a string:
25292529
#[deriving(Eq)]
25302530
struct Circle { radius: f64 }
25312531
2532-
#[deriving(Rand, Show)]
2532+
#[deriving(Clone, Show)]
25332533
enum ABC { A, B, C }
25342534
~~~
25352535

src/etc/generate-deriving-span-tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
4040
#[feature(struct_variant)];
4141
extern crate extra;
42+
extern crate rand;
4243
4344
{error_deriving}
4445
struct Error;

src/etc/ziggurat_tables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# except according to those terms.
1212

1313
# This creates the tables used for distributions implemented using the
14-
# ziggurat algorithm in `std::rand::distributions;`. They are
14+
# ziggurat algorithm in `rand::distributions;`. They are
1515
# (basically) the tables as used in the ZIGNOR variant (Doornik 2005).
1616
# They are changed rarely, so the generated file should be checked in
1717
# to git.

src/libcollections/bitv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,8 +947,8 @@ mod tests {
947947

948948
use std::uint;
949949
use std::vec;
950-
use std::rand;
951-
use std::rand::Rng;
950+
use rand;
951+
use rand::Rng;
952952

953953
static BENCH_BITS : uint = 1 << 14;
954954

src/libcollections/deque.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ pub mod bench {
4444
extern crate test;
4545
use self::test::BenchHarness;
4646
use std::container::MutableMap;
47-
use std::{vec, rand};
48-
use std::rand::Rng;
47+
use std::vec;
48+
use rand;
49+
use rand::Rng;
4950

5051
pub fn insert_rand_n<M:MutableMap<uint,uint>>(n: uint,
5152
map: &mut M,

src/libcollections/dlist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ mod tests {
633633
extern crate test;
634634
use self::test::BenchHarness;
635635
use deque::Deque;
636-
use std::rand;
636+
use rand;
637637
use super::{DList, Node, ListInsertion};
638638

639639
pub fn check_links<T>(list: &DList<T>) {

src/libcollections/hashmap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ use std::iter::{FilterMap, Chain, Repeat, Zip};
6161
use std::iter;
6262
use std::mem::replace;
6363
use std::num;
64-
use std::rand::Rng;
65-
use std::rand;
64+
use rand::Rng;
65+
use rand;
6666
use std::vec::{Items, MutItems};
6767
use std::vec_ng::Vec;
6868
use std::vec_ng;

src/libcollections/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#[allow(unrecognized_lint)];
2424
#[allow(default_type_param_usage)];
2525

26+
extern crate rand;
27+
2628
#[cfg(test)] extern crate test;
2729

2830
pub use bitv::Bitv;

0 commit comments

Comments
 (0)