From 5429f9440548378c0beb56e890f4b6afe693ae2b Mon Sep 17 00:00:00 2001 From: kjpgit Date: Tue, 17 Mar 2015 11:48:57 -0500 Subject: [PATCH 01/13] book: improve pointer box borrowing examples These two borrowing examples were confusing/misleading. This changes it to more clearly show how you _can_ borrow a box, and also uses & instead of &*. --- src/doc/trpl/pointers.md | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/doc/trpl/pointers.md b/src/doc/trpl/pointers.md index 29986d7f23577..f05d2891e70ee 100644 --- a/src/doc/trpl/pointers.md +++ b/src/doc/trpl/pointers.md @@ -560,38 +560,40 @@ fn main() { In this case, Rust knows that `x` is being *borrowed* by the `add_one()` function, and since it's only reading the value, allows it. -We can borrow `x` multiple times, as long as it's not simultaneous: +We can borrow `x` as read-only multiple times, even simultaneously: ```{rust} -fn add_one(x: &i32) -> i32 { - *x + 1 +fn add(x: &i32, y: &i32) -> i32 { + *x + *y } fn main() { let x = Box::new(5); - println!("{}", add_one(&*x)); - println!("{}", add_one(&*x)); - println!("{}", add_one(&*x)); + println!("{}", add(&x, &x)); + println!("{}", add(&x, &x)); } ``` -Or as long as it's not a mutable borrow. This will error: +We can mutably borrow `x` multiple times, but only if x itself is mutable, and +it may not be *simultaneously* borrowed: ```{rust,ignore} -fn add_one(x: &mut i32) -> i32 { - *x + 1 +fn increment(x: &mut i32) { + *x += 1; } fn main() { - let x = Box::new(5); + // If variable x is not "mut", this will not compile + let mut x = Box::new(5); - println!("{}", add_one(&*x)); // error: cannot borrow immutable dereference - // of `&`-pointer as mutable + increment(&mut x); + increment(&mut x); + println!("{}", x); } ``` -Notice we changed the signature of `add_one()` to request a mutable reference. +Notice the signature of `increment()` requests a mutable reference. ## Best practices From a7a28d709170f5dd14439c83d115e16a11c53c06 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Wed, 18 Mar 2015 17:38:11 -0700 Subject: [PATCH 02/13] Clarify in docs that BufRead::read_line appends Multiple people have been suprised by this aspect of read_line's behavior, which is not obvious from the docs. --- src/libstd/io/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index d9e8047104ad0..99c6592773400 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -592,7 +592,8 @@ pub trait BufRead: Read { read_until(self, byte, buf) } - /// Read all bytes until a newline byte (the 0xA byte) is reached. + /// Read all bytes until a newline byte (the 0xA byte) is reached, and + /// append them to the provided buffer. /// /// This function will continue to read (and buffer) bytes from the /// underlying stream until the newline delimiter (the 0xA byte) or EOF is From 13fd0a1c68b699a5d85e868cce4af7992fbd0d6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tero=20H=C3=A4nninen?= Date: Thu, 19 Mar 2015 08:51:52 +0200 Subject: [PATCH 03/13] Remove dead link to wiki in Makefile comments --- Makefile.in | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Makefile.in b/Makefile.in index a760155bbd91a..6fbc6fe49c2ed 100644 --- a/Makefile.in +++ b/Makefile.in @@ -99,11 +99,6 @@ # // Having trouble figuring out which test is failing? Turn off parallel tests # make check-stage1-std RUST_TEST_TASKS=1 # -# This is hardly all there is to know of The Rust Build System's -# mysteries. The tale continues on the wiki[1]. -# -# [1]: https://github.com/rust-lang/rust/wiki/Note-testsuite -# # If you really feel like getting your hands dirty, then: # # run `make nitty-gritty` From 5bfb5bab9a2b2e0ec7797ae8cc4486ba41ea98d4 Mon Sep 17 00:00:00 2001 From: Eduard Bopp Date: Sat, 21 Feb 2015 15:05:34 +0100 Subject: [PATCH 04/13] Allow Float::ldexp to be called as a method Fixes #22098. --- src/libstd/num/f32.rs | 8 ++++---- src/libstd/num/f64.rs | 8 ++++---- src/libstd/num/mod.rs | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index a7825c4f93aa8..bbe08080c6030 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -191,8 +191,8 @@ impl Float for f32 { /// Constructs a floating point number by multiplying `x` by 2 raised to the /// power of `exp` #[inline] - fn ldexp(x: f32, exp: int) -> f32 { - unsafe { cmath::ldexpf(x, exp as c_int) } + fn ldexp(self, exp: isize) -> f32 { + unsafe { cmath::ldexpf(self, exp as c_int) } } /// Breaks the number into a normalized fraction and a base-2 exponent, @@ -2208,8 +2208,8 @@ mod tests { let f1: f32 = FromStrRadix::from_str_radix("1p-123", 16).unwrap(); let f2: f32 = FromStrRadix::from_str_radix("1p-111", 16).unwrap(); let f3: f32 = FromStrRadix::from_str_radix("1.Cp-12", 16).unwrap(); - assert_eq!(Float::ldexp(1f32, -123), f1); - assert_eq!(Float::ldexp(1f32, -111), f2); + assert_eq!(1f32.ldexp(-123), f1); + assert_eq!(1f32.ldexp(-111), f2); assert_eq!(Float::ldexp(1.75f32, -12), f3); assert_eq!(Float::ldexp(0f32, -123), 0f32); diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index f3978cae48510..cab4b860a8d3e 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -200,8 +200,8 @@ impl Float for f64 { fn to_radians(self) -> f64 { num::Float::to_radians(self) } #[inline] - fn ldexp(x: f64, exp: int) -> f64 { - unsafe { cmath::ldexp(x, exp as c_int) } + fn ldexp(self, exp: isize) -> f64 { + unsafe { cmath::ldexp(self, exp as c_int) } } /// Breaks the number into a normalized fraction and a base-2 exponent, @@ -2215,8 +2215,8 @@ mod tests { let f1: f64 = FromStrRadix::from_str_radix("1p-123", 16).unwrap(); let f2: f64 = FromStrRadix::from_str_radix("1p-111", 16).unwrap(); let f3: f64 = FromStrRadix::from_str_radix("1.Cp-12", 16).unwrap(); - assert_eq!(Float::ldexp(1f64, -123), f1); - assert_eq!(Float::ldexp(1f64, -111), f2); + assert_eq!(1f64.ldexp(-123), f1); + assert_eq!(1f64.ldexp(-111), f2); assert_eq!(Float::ldexp(1.75f64, -12), f3); assert_eq!(Float::ldexp(0f64, -123), 0f64); diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 599f3f02a8b76..49a5545f2028e 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -702,7 +702,7 @@ pub trait Float /// ``` #[unstable(feature = "std_misc", reason = "pending integer conventions")] - fn ldexp(x: Self, exp: isize) -> Self; + fn ldexp(self, exp: isize) -> Self; /// Breaks the number into a normalized fraction and a base-2 exponent, /// satisfying: /// From e3cde9783b33ed4decd467602ff3d47505eadab5 Mon Sep 17 00:00:00 2001 From: Vladimir Pouzanov Date: Thu, 19 Mar 2015 17:01:15 +0000 Subject: [PATCH 05/13] Added missing impl_to_source! and impl_to_tokens! for ImplItem. This fixes several use cases that were broken after #23265 landed. --- src/libsyntax/ext/quote.rs | 2 ++ src/libsyntax/print/pprust.rs | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index c38556b078219..de00ea4deaea5 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -176,6 +176,7 @@ pub mod rt { impl_to_source! { ast::Arg, arg_to_string } impl_to_source! { Generics, generics_to_string } impl_to_source! { P, item_to_string } + impl_to_source! { P, impl_item_to_string } impl_to_source! { P, stmt_to_string } impl_to_source! { P, expr_to_string } impl_to_source! { P, pat_to_string } @@ -308,6 +309,7 @@ pub mod rt { impl_to_tokens! { ast::Ident } impl_to_tokens! { P } + impl_to_tokens! { P } impl_to_tokens! { P } impl_to_tokens! { ast::Arm } impl_to_tokens_lifetime! { &'a [P] } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index b58c121c5fd54..51478ccf859a6 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -355,6 +355,10 @@ pub fn item_to_string(i: &ast::Item) -> String { $to_string(|s| s.print_item(i)) } +pub fn impl_item_to_string(i: &ast::ImplItem) -> String { + $to_string(|s| s.print_impl_item(i)) +} + pub fn generics_to_string(generics: &ast::Generics) -> String { $to_string(|s| s.print_generics(generics)) } From bd1f562e19574fa3be5bec2aa661816ac830bb69 Mon Sep 17 00:00:00 2001 From: Vladimir Pouzanov Date: Thu, 19 Mar 2015 17:01:46 +0000 Subject: [PATCH 06/13] Added missing impl_to_source! and impl_to_tokens! for TraitItem. --- src/libsyntax/ext/quote.rs | 2 ++ src/libsyntax/print/pprust.rs | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index de00ea4deaea5..c11ffe66e6c39 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -177,6 +177,7 @@ pub mod rt { impl_to_source! { Generics, generics_to_string } impl_to_source! { P, item_to_string } impl_to_source! { P, impl_item_to_string } + impl_to_source! { P, trait_item_to_string } impl_to_source! { P, stmt_to_string } impl_to_source! { P, expr_to_string } impl_to_source! { P, pat_to_string } @@ -310,6 +311,7 @@ pub mod rt { impl_to_tokens! { ast::Ident } impl_to_tokens! { P } impl_to_tokens! { P } + impl_to_tokens! { P } impl_to_tokens! { P } impl_to_tokens! { ast::Arm } impl_to_tokens_lifetime! { &'a [P] } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 51478ccf859a6..239fea57d94d2 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -359,6 +359,10 @@ pub fn impl_item_to_string(i: &ast::ImplItem) -> String { $to_string(|s| s.print_impl_item(i)) } +pub fn trait_item_to_string(i: &ast::TraitItem) -> String { + $to_string(|s| s.print_trait_item(i)) +} + pub fn generics_to_string(generics: &ast::Generics) -> String { $to_string(|s| s.print_generics(generics)) } From 7cbc42849f7586d3c567d7ac8f202839f9b968e8 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 19 Mar 2015 15:42:53 -0400 Subject: [PATCH 07/13] RUST_TEST_TASKS -> RUST_TEST_THREADS We don't use 'task' anymore, these are now threads. Because this changes the name of a compiler option, this is [breaking-change] --- Makefile.in | 2 +- src/compiletest/compiletest.rs | 4 ++-- src/compiletest/header.rs | 2 +- src/libtest/lib.rs | 6 +++--- src/test/run-fail/test-tasks-invalid-value.rs | 4 ++-- src/test/run-pass/tcp-connect-timeouts.rs | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Makefile.in b/Makefile.in index a760155bbd91a..153092d26f656 100644 --- a/Makefile.in +++ b/Makefile.in @@ -97,7 +97,7 @@ # make check-stage1-rpass TESTNAME=my-shiny-new-test # # // Having trouble figuring out which test is failing? Turn off parallel tests -# make check-stage1-std RUST_TEST_TASKS=1 +# make check-stage1-std RUST_TEST_THREADS=1 # # This is hardly all there is to know of The Rust Build System's # mysteries. The tale continues on the wiki[1]. diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 7fbe772b7f5bd..01c4e99b77c70 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -224,7 +224,7 @@ pub fn run_tests(config: &Config) { // android debug-info test uses remote debugger // so, we test 1 task at once. // also trying to isolate problems with adb_run_wrapper.sh ilooping - env::set_var("RUST_TEST_TASKS","1"); + env::set_var("RUST_TEST_THREADS","1"); } match config.mode { @@ -232,7 +232,7 @@ pub fn run_tests(config: &Config) { // Some older versions of LLDB seem to have problems with multiple // instances running in parallel, so only run one test task at a // time. - env::set_var("RUST_TEST_TASKS", "1"); + env::set_var("RUST_TEST_THREADS", "1"); } _ => { /* proceed */ } } diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index 21cebc61b3a9d..6899fa13974e9 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -131,7 +131,7 @@ pub fn load_props(testfile: &Path) -> TestProps { true }); - for key in vec!["RUST_TEST_NOCAPTURE", "RUST_TEST_TASKS"] { + for key in vec!["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] { match env::var(key) { Ok(val) => if exec_env.iter().find(|&&(ref x, _)| *x == key.to_string()).is_none() { diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 02ddeea46bfc8..e4ccd49e807ac 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -338,7 +338,7 @@ The FILTER regex is tested against the name of all tests to run, and only those tests that match are run. By default, all tests are run in parallel. This can be altered with the -RUST_TEST_TASKS environment variable when running tests (set it to 1). +RUST_TEST_THRADS environment variable when running tests (set it to 1). All tests have their standard output and standard error captured by default. This can be overridden with the --nocapture flag or the RUST_TEST_NOCAPTURE=1 @@ -843,12 +843,12 @@ fn run_tests(opts: &TestOpts, fn get_concurrency() -> uint { use std::rt; - match env::var("RUST_TEST_TASKS") { + match env::var("RUST_TEST_THREADS") { Ok(s) => { let opt_n: Option = s.parse().ok(); match opt_n { Some(n) if n > 0 => n, - _ => panic!("RUST_TEST_TASKS is `{}`, should be a positive integer.", s) + _ => panic!("RUST_TEST_THREADS is `{}`, should be a positive integer.", s) } } Err(..) => { diff --git a/src/test/run-fail/test-tasks-invalid-value.rs b/src/test/run-fail/test-tasks-invalid-value.rs index 8c9cd2d63cb47..94ed641c79c93 100644 --- a/src/test/run-fail/test-tasks-invalid-value.rs +++ b/src/test/run-fail/test-tasks-invalid-value.rs @@ -8,12 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// This checks that RUST_TEST_TASKS not being 1, 2, ... is detected +// This checks that RUST_TEST_THREADS not being 1, 2, ... is detected // properly. // error-pattern:should be a positive integer // compile-flags: --test -// exec-env:RUST_TEST_TASKS=foo +// exec-env:RUST_TEST_THREADS=foo // ignore-pretty: does not work well with `--test` #[test] diff --git a/src/test/run-pass/tcp-connect-timeouts.rs b/src/test/run-pass/tcp-connect-timeouts.rs index d1a3edcfbc529..5462a996f73d9 100644 --- a/src/test/run-pass/tcp-connect-timeouts.rs +++ b/src/test/run-pass/tcp-connect-timeouts.rs @@ -10,7 +10,7 @@ // ignore-pretty // compile-flags:--test -// exec-env:RUST_TEST_TASKS=1 +// exec-env:RUST_TEST_THREADS=1 // Tests for the connect_timeout() function on a TcpStream. This runs with only // one test task to ensure that errors are timeouts, not file descriptor From 973b788f408ffc502f13ec4b9e9716b9cbd3f531 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Thu, 19 Mar 2015 13:34:18 -0700 Subject: [PATCH 08/13] Update docs for ToUppercase/ToLowercase structs `uppercase` and `lowercase` are currently named `to_uppercase` and `to_lowercase`. Also adds a link to the `char` type documentation which has much more detail on these iterators. --- src/libunicode/char.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libunicode/char.rs b/src/libunicode/char.rs index e24ade58a5224..5e1070c6dc503 100644 --- a/src/libunicode/char.rs +++ b/src/libunicode/char.rs @@ -462,7 +462,8 @@ impl CharExt for char { } /// An iterator over the lowercase mapping of a given character, returned from -/// the `lowercase` method on characters. +/// the [`to_lowercase` method](../primitive.char.html#method.to_lowercase) on +/// characters. #[stable(feature = "rust1", since = "1.0.0")] pub struct ToLowercase(Option); @@ -473,7 +474,8 @@ impl Iterator for ToLowercase { } /// An iterator over the uppercase mapping of a given character, returned from -/// the `uppercase` method on characters. +/// the [`to_uppercase` method](../primitive.char.html#method.to_uppercase) on +/// characters. #[stable(feature = "rust1", since = "1.0.0")] pub struct ToUppercase(Option); From 109803f6d5a07f3aed2e647703087a46df48decd Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 19 Mar 2015 18:06:54 -0400 Subject: [PATCH 09/13] Remove incorrect statement about raw pointers. Fixes #21709 --- src/doc/trpl/unsafe.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/doc/trpl/unsafe.md b/src/doc/trpl/unsafe.md index 4e14085599b60..11f0b8e1ddbf9 100644 --- a/src/doc/trpl/unsafe.md +++ b/src/doc/trpl/unsafe.md @@ -93,10 +93,6 @@ offered by the Rust language and libraries. For example, they - are plain-old-data, that is, they don't move ownership, again unlike `Box`, hence the Rust compiler cannot protect against bugs like use-after-free; -- are considered sendable (if their contents is considered sendable), - so the compiler offers no assistance with ensuring their use is - thread-safe; for example, one can concurrently access a `*mut i32` - from two threads without synchronization. - lack any form of lifetimes, unlike `&`, and so the compiler cannot reason about dangling pointers; and - have no guarantees about aliasing or mutability other than mutation From d081b241ff79c276e6839ffb94447ce6dd3cfab3 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 19 Mar 2015 18:11:35 -0400 Subject: [PATCH 10/13] Reference Drop in FFI chapter Fixes #22002 --- src/doc/trpl/ffi.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/doc/trpl/ffi.md b/src/doc/trpl/ffi.md index 20b0ffc1b2862..018f35337f3c0 100644 --- a/src/doc/trpl/ffi.md +++ b/src/doc/trpl/ffi.md @@ -170,6 +170,8 @@ Foreign libraries often hand off ownership of resources to the calling code. When this occurs, we must use Rust's destructors to provide safety and guarantee the release of these resources (especially in the case of panic). +For more about destructors, see the [Drop trait](../std/ops/trait.Drop.html). + # Callbacks from C code to Rust functions Some external libraries require the usage of callbacks to report back their From 3e3408de0f73f7df7c8a626c64ff4d704f08353d Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 19 Mar 2015 16:53:06 -0400 Subject: [PATCH 11/13] Comment on when ReadDir is Err Fixes #23426 --- src/libstd/fs/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libstd/fs/mod.rs b/src/libstd/fs/mod.rs index ba89b3a0ea63f..0aae59921967d 100644 --- a/src/libstd/fs/mod.rs +++ b/src/libstd/fs/mod.rs @@ -73,6 +73,11 @@ pub struct Metadata(fs_imp::FileAttr); /// will yield instances of `io::Result`. Through a `DirEntry` /// information like the entry's path and possibly other metadata can be /// learned. +/// +/// # Failure +/// +/// This `io::Result` will be an `Err` if there's some sort of intermittent +/// IO error during iteration. #[stable(feature = "rust1", since = "1.0.0")] pub struct ReadDir(fs_imp::ReadDir); From b4a72a403a9dfcb3ba906606b3ea0b8363884cdf Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 19 Mar 2015 16:38:06 -0400 Subject: [PATCH 12/13] Document environment variables Fixes #16330 --- man/rustc.1 | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/man/rustc.1 b/man/rustc.1 index f37e660019093..33ef3f9ee4acb 100644 --- a/man/rustc.1 +++ b/man/rustc.1 @@ -242,6 +242,28 @@ full debug info with variable and type information. \fBopt\-level\fR=\fIVAL\fR Optimize with possible levels 0\[en]3 +.SH ENVIRONMENT VARIABLES + +Some of these affect the output of the compiler, while others affect programs +which link to the standard library. + +.TP +\fBRUST_TEST_THREADS\fR +The test framework Rust provides executes tests in parallel. This variable sets +the maximum number of threads used for this purpose. + +.TP +\fBRUST_TEST_NOCAPTURE\fR +A synonym for the --nocapture flag. + +.TP +\fBRUST_MIN_STACK\fR +Sets the minimum stack size for new threads. + +.TP +\fBRUST_BACKTRACE\fR +If set, produces a backtrace in the output of a program which panics. + .SH "EXAMPLES" To build an executable from a source file with a main function: $ rustc \-o hello hello.rs From 71321ff33fa3fe71cc1df541b3d0547b4e208923 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 19 Mar 2015 18:38:16 -0400 Subject: [PATCH 13/13] Remove rt::default_sched_threads and RUST_THREADS. As @alexcrichton says, this was really a libgreen thing, and isn't relevant now. As this removes a technically-public function, this is a [breaking-change] Conflicts: src/libtest/lib.rs --- src/libstd/rt/mod.rs | 2 +- src/libstd/rt/util.rs | 23 ----------------------- src/libtest/lib.rs | 9 +++++++-- 3 files changed, 8 insertions(+), 26 deletions(-) diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index 90cc189b9a0f0..5e8abfd0a3f89 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -30,7 +30,7 @@ use thunk::Thunk; use usize; // Reexport some of our utilities which are expected by other crates. -pub use self::util::{default_sched_threads, min_stack, running_on_valgrind}; +pub use self::util::{min_stack, running_on_valgrind}; pub use self::unwind::{begin_unwind, begin_unwind_fmt}; // Reexport some functionality from liballoc. diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index e72fd7b33202d..f1c43a07e6e38 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -58,29 +58,6 @@ pub fn min_stack() -> uint { return amt; } -/// Get's the number of scheduler threads requested by the environment -/// either `RUST_THREADS` or `num_cpus`. -#[allow(deprecated)] -pub fn default_sched_threads() -> uint { - use os; - match env::var("RUST_THREADS") { - Ok(nstr) => { - let opt_n: Option = nstr.parse().ok(); - match opt_n { - Some(n) if n > 0 => n, - _ => panic!("`RUST_THREADS` is `{}`, should be a positive integer", nstr) - } - } - Err(..) => { - if limit_thread_creation_due_to_osx_and_valgrind() { - 1 - } else { - os::num_cpus() - } - } - } -} - // Indicates whether we should perform expensive sanity checks, including rtassert! // // FIXME: Once the runtime matures remove the `true` below to turn off rtassert, diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index e4ccd49e807ac..51decbab8587d 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -44,6 +44,7 @@ #![feature(std_misc)] #![feature(libc)] #![feature(set_stdio)] +#![feature(os)] extern crate getopts; extern crate serialize; @@ -841,8 +842,8 @@ fn run_tests(opts: &TestOpts, Ok(()) } +#[allow(deprecated)] fn get_concurrency() -> uint { - use std::rt; match env::var("RUST_TEST_THREADS") { Ok(s) => { let opt_n: Option = s.parse().ok(); @@ -852,7 +853,11 @@ fn get_concurrency() -> uint { } } Err(..) => { - rt::default_sched_threads() + if std::rt::util::limit_thread_creation_due_to_osx_and_valgrind() { + 1 + } else { + std::os::num_cpus() + } } } }