Skip to content
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

Rollup of PRs in the queue; Friday #23548

Merged
merged 28 commits into from
Mar 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5429f94
book: improve pointer box borrowing examples
kjpgit Mar 17, 2015
a7a28d7
Clarify in docs that BufRead::read_line appends
mbrubeck Mar 19, 2015
13fd0a1
Remove dead link to wiki in Makefile comments
Mar 19, 2015
5bfb5ba
Allow Float::ldexp to be called as a method
milibopp Feb 21, 2015
e3cde97
Added missing impl_to_source! and impl_to_tokens! for ImplItem.
farcaller Mar 19, 2015
bd1f562
Added missing impl_to_source! and impl_to_tokens! for TraitItem.
farcaller Mar 19, 2015
7cbc428
RUST_TEST_TASKS -> RUST_TEST_THREADS
steveklabnik Mar 19, 2015
973b788
Update docs for ToUppercase/ToLowercase structs
mbrubeck Mar 19, 2015
109803f
Remove incorrect statement about raw pointers.
steveklabnik Mar 19, 2015
d081b24
Reference Drop in FFI chapter
steveklabnik Mar 19, 2015
3e3408d
Comment on when ReadDir is Err
steveklabnik Mar 19, 2015
b4a72a4
Document environment variables
steveklabnik Mar 19, 2015
97f03e7
Rollup merge of #23489 - michaelwoerister:span-artihmetic-overflow-bu…
Manishearth Mar 20, 2015
4294327
Rollup merge of #23254 - jbcrail:saturating-math-docs, r=steveklabnik
Manishearth Mar 20, 2015
71321ff
Remove rt::default_sched_threads and RUST_THREADS.
steveklabnik Mar 19, 2015
3e43373
Rollup merge of #23504 - alexcrichton:parse-error-not-unit, r=aturon
Manishearth Mar 20, 2015
e2d32b7
Rollup merge of #23525 - steveklabnik:test_tasks, r=alexcrichton
Manishearth Mar 20, 2015
17c1a46
Rollup merge of #23529 - steveklabnik:gh23426, r=alexcrichton
Manishearth Mar 20, 2015
baf6b3a
Rollup merge of #23531 - steveklabnik:gh21709, r=alexcrichton
Manishearth Mar 20, 2015
1ceb26b
Rollup merge of #22631 - aepsil0n:issue-22098, r=aturon
Manishearth Mar 20, 2015
dbe084b
Rollup merge of #23447 - kjpgit:kjp/pointerexample, r=steveklabnik
Manishearth Mar 20, 2015
90e7f47
Rollup merge of #23499 - mbrubeck:doc-edit, r=huonw
Manishearth Mar 20, 2015
c785e7e
Rollup merge of #23510 - lgvz:makefile, r=Manishearth
Manishearth Mar 20, 2015
2ac03bc
Rollup merge of #23518 - farcaller:fix_quote_method, r=eddyb
Manishearth Mar 20, 2015
17f3f3e
Rollup merge of #23526 - mbrubeck:uppercase, r=steveklabnik
Manishearth Mar 20, 2015
83a95b0
Rollup merge of #23527 - steveklabnik:gh16330, r=alexcrichton
Manishearth Mar 20, 2015
0711006
Rollup merge of #23532 - steveklabnik:gh22002, r=alexcrichton
Manishearth Mar 20, 2015
6107e4c
Rollup merge of #23534 - steveklabnik:remove_sched_threads, r=alexcr…
Manishearth Mar 20, 2015
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
7 changes: 1 addition & 6 deletions Makefile.in
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
20 changes: 20 additions & 0 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,16 @@ pub trait Int

/// Saturating integer addition. Computes `self + other`, saturating at
/// the numeric bounds instead of overflowing.
///
/// # Examples
///
/// ```
/// use std::num::Int;
///
/// assert_eq!(5u16.saturating_add(65534), 65535);
/// assert_eq!((-5i16).saturating_add(-32767), -32768);
/// assert_eq!(100u32.saturating_add(4294967294), 4294967295);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
fn saturating_add(self, other: Self) -> Self {
Expand All @@ -357,6 +367,16 @@ pub trait Int

/// Saturating integer subtraction. Computes `self - other`, saturating at
/// the numeric bounds instead of overflowing.
///
/// # Examples
///
/// ```
/// use std::num::Int;
///
/// assert_eq!(5u16.saturating_sub(65534), 0);
/// assert_eq!(5i16.saturating_sub(-32767), 32767);
/// assert_eq!(100u32.saturating_sub(4294967294), 0);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
fn saturating_sub(self, other: Self) -> Self {
Expand Down
15 changes: 15 additions & 0 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,27 @@ impl<'a, 'b, 'tcx> DecodeContext<'a, 'b, 'tcx> {
pub fn tr_span(&self, span: Span) -> Span {
let imported_filemaps = &self.cdata.codemap_import_info[..];

let span = if span.lo > span.hi {
// Currently macro expansion sometimes produces invalid Span values
// where lo > hi. In order not to crash the compiler when trying to
// translate these values, let's transform them into something we
// can handle (and which will produce useful debug locations at
// least some of the time).
// This workaround is only necessary as long as macro expansion is
// not fixed. FIXME(#23480)
codemap::mk_sp(span.lo, span.lo)
} else {
span
};

let filemap_index = {
// Optimize for the case that most spans within a translated item
// originate from the same filemap.
let last_filemap_index = self.last_filemap_index.get();

if span.lo >= imported_filemaps[last_filemap_index].original_start_pos &&
span.lo <= imported_filemaps[last_filemap_index].original_end_pos &&
span.hi >= imported_filemaps[last_filemap_index].original_start_pos &&
span.hi <= imported_filemaps[last_filemap_index].original_end_pos {
last_filemap_index
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/libstd/fs/mod.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
1 change: 1 addition & 0 deletions src/libstd/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub use self::ip::{Ipv4Addr, Ipv6Addr, Ipv6MulticastScope};
pub use self::addr::{SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs};
pub use self::tcp::{TcpStream, TcpListener};
pub use self::udp::UdpSocket;
pub use self::parser::AddrParseError;

mod ip;
mod addr;
Expand Down
27 changes: 16 additions & 11 deletions src/libstd/net/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,35 +296,40 @@ impl<'a> Parser<'a> {
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl FromStr for Ipv4Addr {
type Err = ParseError;
fn from_str(s: &str) -> Result<Ipv4Addr, ParseError> {
type Err = AddrParseError;
fn from_str(s: &str) -> Result<Ipv4Addr, AddrParseError> {
match Parser::new(s).read_till_eof(|p| p.read_ipv4_addr()) {
Some(s) => Ok(s),
None => Err(ParseError)
None => Err(AddrParseError(()))
}
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl FromStr for Ipv6Addr {
type Err = ParseError;
fn from_str(s: &str) -> Result<Ipv6Addr, ParseError> {
type Err = AddrParseError;
fn from_str(s: &str) -> Result<Ipv6Addr, AddrParseError> {
match Parser::new(s).read_till_eof(|p| p.read_ipv6_addr()) {
Some(s) => Ok(s),
None => Err(ParseError)
None => Err(AddrParseError(()))
}
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl FromStr for SocketAddr {
type Err = ParseError;
fn from_str(s: &str) -> Result<SocketAddr, ParseError> {
type Err = AddrParseError;
fn from_str(s: &str) -> Result<SocketAddr, AddrParseError> {
match Parser::new(s).read_till_eof(|p| p.read_socket_addr()) {
Some(s) => Ok(s),
None => Err(ParseError),
None => Err(AddrParseError(())),
}
}
}

#[derive(Debug, Clone, PartialEq, Copy)]
pub struct ParseError;
/// An error returned when parsing an IP address or a socket address.
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Debug, Clone, PartialEq)]
pub struct AddrParseError(());
8 changes: 4 additions & 4 deletions src/libstd/num/f32.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading