Skip to content

Commit 16e1fce

Browse files
committed
Auto merge of #24433 - alexcrichton:rollup, r=alexcrichton
2 parents 8415fa2 + e053571 commit 16e1fce

File tree

273 files changed

+1564
-25824
lines changed

Some content is hidden

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

273 files changed

+1564
-25824
lines changed

src/compiletest/compiletest.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212

1313
#![feature(box_syntax)]
1414
#![feature(collections)]
15-
#![feature(old_io)]
1615
#![feature(rustc_private)]
17-
#![feature(unboxed_closures)]
1816
#![feature(std_misc)]
1917
#![feature(test)]
2018
#![feature(path_ext)]
2119
#![feature(str_char)]
20+
#![feature(libc)]
2221

2322
#![deny(warnings)]
2423

24+
extern crate libc;
2525
extern crate test;
2626
extern crate getopts;
2727

@@ -42,6 +42,7 @@ pub mod header;
4242
pub mod runtest;
4343
pub mod common;
4444
pub mod errors;
45+
mod raise_fd_limit;
4546

4647
pub fn main() {
4748
let config = parse_config(env::args().collect());
@@ -245,11 +246,7 @@ pub fn run_tests(config: &Config) {
245246
// sadly osx needs some file descriptor limits raised for running tests in
246247
// parallel (especially when we have lots and lots of child processes).
247248
// For context, see #8904
248-
#[allow(deprecated)]
249-
fn raise_fd_limit() {
250-
std::old_io::test::raise_fd_limit();
251-
}
252-
raise_fd_limit();
249+
unsafe { raise_fd_limit::raise_fd_limit(); }
253250
// Prevent issue #21352 UAC blocking .exe containing 'patch' etc. on Windows
254251
// If #11207 is resolved (adding manifest to .exe) this becomes unnecessary
255252
env::set_var("__COMPAT_LAYER", "RunAsInvoker");

src/compiletest/raise_fd_limit.rs

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
/// darwin_fd_limit exists to work around an issue where launchctl on Mac OS X
12+
/// defaults the rlimit maxfiles to 256/unlimited. The default soft limit of 256
13+
/// ends up being far too low for our multithreaded scheduler testing, depending
14+
/// on the number of cores available.
15+
///
16+
/// This fixes issue #7772.
17+
#[cfg(any(target_os = "macos", target_os = "ios"))]
18+
#[allow(non_camel_case_types)]
19+
pub unsafe fn raise_fd_limit() {
20+
use libc;
21+
use std::cmp;
22+
use std::io;
23+
use std::mem::size_of_val;
24+
use std::ptr::null_mut;
25+
26+
type rlim_t = libc::uint64_t;
27+
28+
#[repr(C)]
29+
struct rlimit {
30+
rlim_cur: rlim_t,
31+
rlim_max: rlim_t
32+
}
33+
extern {
34+
// name probably doesn't need to be mut, but the C function doesn't
35+
// specify const
36+
fn sysctl(name: *mut libc::c_int, namelen: libc::c_uint,
37+
oldp: *mut libc::c_void, oldlenp: *mut libc::size_t,
38+
newp: *mut libc::c_void, newlen: libc::size_t) -> libc::c_int;
39+
fn getrlimit(resource: libc::c_int, rlp: *mut rlimit) -> libc::c_int;
40+
fn setrlimit(resource: libc::c_int, rlp: *const rlimit) -> libc::c_int;
41+
}
42+
static CTL_KERN: libc::c_int = 1;
43+
static KERN_MAXFILESPERPROC: libc::c_int = 29;
44+
static RLIMIT_NOFILE: libc::c_int = 8;
45+
46+
// The strategy here is to fetch the current resource limits, read the
47+
// kern.maxfilesperproc sysctl value, and bump the soft resource limit for
48+
// maxfiles up to the sysctl value.
49+
50+
// Fetch the kern.maxfilesperproc value
51+
let mut mib: [libc::c_int; 2] = [CTL_KERN, KERN_MAXFILESPERPROC];
52+
let mut maxfiles: libc::c_int = 0;
53+
let mut size: libc::size_t = size_of_val(&maxfiles) as libc::size_t;
54+
if sysctl(&mut mib[0], 2, &mut maxfiles as *mut _ as *mut _, &mut size,
55+
null_mut(), 0) != 0 {
56+
let err = io::Error::last_os_error();
57+
panic!("raise_fd_limit: error calling sysctl: {}", err);
58+
}
59+
60+
// Fetch the current resource limits
61+
let mut rlim = rlimit{rlim_cur: 0, rlim_max: 0};
62+
if getrlimit(RLIMIT_NOFILE, &mut rlim) != 0 {
63+
let err = io::Error::last_os_error();
64+
panic!("raise_fd_limit: error calling getrlimit: {}", err);
65+
}
66+
67+
// Bump the soft limit to the smaller of kern.maxfilesperproc and the hard
68+
// limit
69+
rlim.rlim_cur = cmp::min(maxfiles as rlim_t, rlim.rlim_max);
70+
71+
// Set our newly-increased resource limit
72+
if setrlimit(RLIMIT_NOFILE, &rlim) != 0 {
73+
let err = io::Error::last_os_error();
74+
panic!("raise_fd_limit: error calling setrlimit: {}", err);
75+
}
76+
}
77+
78+
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
79+
pub unsafe fn raise_fd_limit() {}

src/compiletest/runtest.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use std::net::TcpStream;
2929
use std::path::{Path, PathBuf};
3030
use std::process::{Command, Output, ExitStatus};
3131
use std::str;
32-
use std::time::Duration;
3332
use test::MetricMap;
3433

3534
pub fn run(config: Config, testfile: &Path) {
@@ -452,11 +451,7 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
452451
.expect(&format!("failed to exec `{:?}`", config.adb_path));
453452
loop {
454453
//waiting 1 second for gdbserver start
455-
#[allow(deprecated)]
456-
fn sleep() {
457-
::std::old_io::timer::sleep(Duration::milliseconds(1000));
458-
}
459-
sleep();
454+
::std::thread::sleep_ms(1000);
460455
if TcpStream::connect("127.0.0.1:5039").is_ok() {
461456
break
462457
}

src/doc/index.md

+6-14
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ Rust, its syntax, and its concepts. Upon completing the book, you'll be an
1515
intermediate Rust developer, and will have a good grasp of the fundamental
1616
ideas behind Rust.
1717

18+
[Rust By Example][rbe] was originally a community resource, but was then
19+
donated to the Rust project. As the name implies, it teaches you Rust through a
20+
series of small examples.
21+
22+
[rbe]: rustbyexample.com
23+
1824
# Community & Getting Help
1925

2026
If you need help with something, or just want to talk about Rust with others,
@@ -76,17 +82,3 @@ We have [API documentation for the entire standard
7682
library](std/index.html). There's a list of crates on the left with more
7783
specific sections, or you can use the search bar at the top to search for
7884
something if you know its name.
79-
80-
# External documentation
81-
82-
*Note: While these are great resources for learning Rust, they may track a
83-
particular version of Rust that is likely not exactly the same as that for
84-
which this documentation was generated.*
85-
86-
* [Rust by Example] - Short examples of common tasks in Rust (tracks the master
87-
branch).
88-
* [Rust for Rubyists] - The first community tutorial for Rust. Tracks the last
89-
stable release. Not just for Ruby programmers.
90-
91-
[Rust by Example]: http://rustbyexample.com/
92-
[Rust for Rubyists]: http://www.rustforrubyists.com/

src/doc/intro.md

+4
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ safe concurrent programs.
389389
Here's an example of a concurrent Rust program:
390390
391391
```{rust}
392+
# #![feature(scoped)]
392393
use std::thread;
393394
394395
fn main() {
@@ -421,6 +422,7 @@ problem.
421422
Let's see an example. This Rust code will not compile:
422423
423424
```{rust,ignore}
425+
# #![feature(scoped)]
424426
use std::thread;
425427
426428
fn main() {
@@ -467,6 +469,7 @@ that our mutation doesn't cause a data race.
467469
Here's what using a Mutex looks like:
468470
469471
```{rust}
472+
# #![feature(scoped)]
470473
use std::thread;
471474
use std::sync::Mutex;
472475
@@ -527,6 +530,7 @@ As an example, Rust's ownership system is _entirely_ at compile time. The
527530
safety check that makes this an error about moved values:
528531
529532
```{rust,ignore}
533+
# #![feature(scoped)]
530534
use std::thread;
531535
532536
fn main() {

src/doc/trpl/comments.md

+18-20
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,45 @@
11
% Comments
22

3-
Now that we have some functions, it's a good idea to learn about comments.
3+
Now that we have some functions, its a good idea to learn about comments.
44
Comments are notes that you leave to other programmers to help explain things
55
about your code. The compiler mostly ignores them.
66

77
Rust has two kinds of comments that you should care about: *line comments*
88
and *doc comments*.
99

10-
```{rust}
11-
// Line comments are anything after '//' and extend to the end of the line.
10+
```rust
11+
// Line comments are anything after ‘//’ and extend to the end of the line.
1212

1313
let x = 5; // this is also a line comment.
1414

1515
// If you have a long explanation for something, you can put line comments next
16-
// to each other. Put a space between the // and your comment so that it's
16+
// to each other. Put a space between the // and your comment so that its
1717
// more readable.
1818
```
1919

2020
The other kind of comment is a doc comment. Doc comments use `///` instead of
2121
`//`, and support Markdown notation inside:
2222

23-
```{rust}
24-
/// `hello` is a function that prints a greeting that is personalized based on
25-
/// the name given.
26-
///
27-
/// # Arguments
28-
///
29-
/// * `name` - The name of the person you'd like to greet.
23+
```rust
24+
/// Adds one to the number given.
3025
///
3126
/// # Examples
3227
///
33-
/// ```rust
34-
/// let name = "Steve";
35-
/// hello(name); // prints "Hello, Steve!"
3628
/// ```
37-
fn hello(name: &str) {
38-
println!("Hello, {}!", name);
29+
/// let five = 5;
30+
///
31+
/// assert_eq!(6, add_one(5));
32+
/// ```
33+
fn add_one(x: i32) -> i32 {
34+
x + 1
3935
}
4036
```
4137

42-
When writing doc comments, adding sections for any arguments, return values,
43-
and providing some examples of usage is very, very helpful. Don't worry about
44-
the `&str`, we'll get to it soon.
38+
When writing doc comments, providing some examples of usage is very, very
39+
helpful. You’ll notice we’ve used a new macro here: `assert_eq!`. This compares
40+
two values, and `panic!`s if they’re not equal to each other. It’s very helpful
41+
in documentation. There’s another macro, `assert!`, which `panic!`s if the
42+
value passed to it is `false`.
4543

4644
You can use the [`rustdoc`](documentation.html) tool to generate HTML documentation
47-
from these doc comments.
45+
from these doc comments, and also to run the code examples as tests!

src/doc/trpl/concurrency.md

+8-41
Original file line numberDiff line numberDiff line change
@@ -56,68 +56,35 @@ place!
5656

5757
## Threads
5858

59-
Rust's standard library provides a library for 'threads', which allow you to
59+
Rust's standard library provides a library for threads, which allow you to
6060
run Rust code in parallel. Here's a basic example of using `std::thread`:
6161

6262
```
6363
use std::thread;
6464
6565
fn main() {
66-
thread::scoped(|| {
66+
thread::spawn(|| {
6767
println!("Hello from a thread!");
6868
});
6969
}
7070
```
7171

72-
The `thread::scoped()` method accepts a closure, which is executed in a new
73-
thread. It's called `scoped` because this thread returns a join guard:
72+
The `thread::spawn()` method accepts a closure, which is executed in a
73+
new thread. It returns a handle to the thread, that can be used to
74+
wait for the child thread to finish and extract its result:
7475

7576
```
7677
use std::thread;
7778
7879
fn main() {
79-
let guard = thread::scoped(|| {
80-
println!("Hello from a thread!");
80+
let handle = thread::spawn(|| {
81+
"Hello from a thread!"
8182
});
8283
83-
// guard goes out of scope here
84+
println!("{}", handle.join().unwrap());
8485
}
8586
```
8687

87-
When `guard` goes out of scope, it will block execution until the thread is
88-
finished. If we didn't want this behaviour, we could use `thread::spawn()`:
89-
90-
```
91-
use std::thread;
92-
93-
fn main() {
94-
thread::spawn(|| {
95-
println!("Hello from a thread!");
96-
});
97-
98-
thread::sleep_ms(50);
99-
}
100-
```
101-
102-
We need to `sleep` here because when `main()` ends, it kills all of the
103-
running threads.
104-
105-
[`scoped`](std/thread/struct.Builder.html#method.scoped) has an interesting
106-
type signature:
107-
108-
```text
109-
fn scoped<'a, T, F>(self, f: F) -> JoinGuard<'a, T>
110-
where T: Send + 'a,
111-
F: FnOnce() -> T,
112-
F: Send + 'a
113-
```
114-
115-
Specifically, `F`, the closure that we pass to execute in the new thread. It
116-
has two restrictions: It must be a `FnOnce` from `()` to `T`. Using `FnOnce`
117-
allows the closure to take ownership of any data it mentions from the parent
118-
thread. The other restriction is that `F` must be `Send`. We aren't allowed to
119-
transfer this ownership unless the type thinks that's okay.
120-
12188
Many languages have the ability to execute threads, but it's wildly unsafe.
12289
There are entire books about how to prevent errors that occur from shared
12390
mutable state. Rust helps out with its type system here as well, by preventing

src/doc/trpl/enums.md

-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,5 @@ matching, a tool that will let us deconstruct sum types (the type theory term
143143
for enums) like `Ordering` in a very elegant way that avoids all these messy
144144
and brittle `if`/`else`s.
145145

146-
147-
[arity]: ./glossary.html#arity
148146
[match]: ./match.html
149147
[generics]: ./generics.html

src/doc/trpl/error-handling.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,5 +297,5 @@ It's worth noting that you can only use `try!` from a function that returns a
297297
`Result`, which means that you cannot use `try!` inside of `main()`, because
298298
`main()` doesn't return anything.
299299

300-
`try!` makes use of [`FromError`](../std/error/#the-fromerror-trait) to determine
300+
`try!` makes use of [`From<Error>`](../std/convert/trait.From.hml) to determine
301301
what to return in the error case.

0 commit comments

Comments
 (0)