Skip to content

Commit

Permalink
Auto merge of #23548 - Manishearth:rollup, r=Manishearth
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Mar 20, 2015
2 parents fda8673 + 6107e4c commit 0834bd1
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 70 deletions.
7 changes: 1 addition & 6 deletions Makefile.in
Expand Up @@ -97,12 +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
#
# 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
# make check-stage1-std RUST_TEST_THREADS=1
#
# If you really feel like getting your hands dirty, then:
#
Expand Down
22 changes: 22 additions & 0 deletions man/rustc.1
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/compiletest/compiletest.rs
Expand Up @@ -224,15 +224,15 @@ 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 {
DebugInfoLldb => {
// 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 */ }
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/header.rs
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions src/doc/trpl/ffi.md
Expand Up @@ -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
Expand Down
28 changes: 15 additions & 13 deletions src/doc/trpl/pointers.md
Expand Up @@ -561,38 +561,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

Expand Down
4 changes: 0 additions & 4 deletions src/doc/trpl/unsafe.md
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/libstd/fs/mod.rs
Expand Up @@ -73,6 +73,11 @@ pub struct Metadata(fs_imp::FileAttr);
/// will yield instances of `io::Result<DirEntry>`. 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);

Expand Down
3 changes: 2 additions & 1 deletion src/libstd/io/mod.rs
Expand Up @@ -584,7 +584,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
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/num/f32.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -2207,8 +2207,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);
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/num/f64.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -2214,8 +2214,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);
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/num/mod.rs
Expand Up @@ -699,7 +699,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:
///
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/rt/mod.rs
Expand Up @@ -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.
Expand Down
23 changes: 0 additions & 23 deletions src/libstd/rt/util.rs
Expand Up @@ -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<uint> = 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,
Expand Down
4 changes: 4 additions & 0 deletions src/libsyntax/ext/quote.rs
Expand Up @@ -176,6 +176,8 @@ pub mod rt {
impl_to_source! { ast::Arg, arg_to_string }
impl_to_source! { Generics, generics_to_string }
impl_to_source! { P<ast::Item>, item_to_string }
impl_to_source! { P<ast::ImplItem>, impl_item_to_string }
impl_to_source! { P<ast::TraitItem>, trait_item_to_string }
impl_to_source! { P<ast::Stmt>, stmt_to_string }
impl_to_source! { P<ast::Expr>, expr_to_string }
impl_to_source! { P<ast::Pat>, pat_to_string }
Expand Down Expand Up @@ -308,6 +310,8 @@ pub mod rt {

impl_to_tokens! { ast::Ident }
impl_to_tokens! { P<ast::Item> }
impl_to_tokens! { P<ast::ImplItem> }
impl_to_tokens! { P<ast::TraitItem> }
impl_to_tokens! { P<ast::Pat> }
impl_to_tokens! { ast::Arm }
impl_to_tokens_lifetime! { &'a [P<ast::Item>] }
Expand Down
8 changes: 8 additions & 0 deletions src/libsyntax/print/pprust.rs
Expand Up @@ -355,6 +355,14 @@ 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 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))
}
Expand Down
15 changes: 10 additions & 5 deletions src/libtest/lib.rs
Expand Up @@ -44,6 +44,7 @@
#![feature(std_misc)]
#![feature(libc)]
#![feature(set_stdio)]
#![feature(os)]

extern crate getopts;
extern crate serialize;
Expand Down Expand Up @@ -338,7 +339,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
Expand Down Expand Up @@ -841,18 +842,22 @@ fn run_tests<F>(opts: &TestOpts,
Ok(())
}

#[allow(deprecated)]
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<uint> = 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(..) => {
rt::default_sched_threads()
if std::rt::util::limit_thread_creation_due_to_osx_and_valgrind() {
1
} else {
std::os::num_cpus()
}
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/libunicode/char.rs
Expand Up @@ -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<char>);

Expand All @@ -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<char>);

Expand Down
4 changes: 2 additions & 2 deletions src/test/run-fail/test-tasks-invalid-value.rs
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/tcp-connect-timeouts.rs
Expand Up @@ -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
Expand Down

0 comments on commit 0834bd1

Please sign in to comment.