Skip to content

Commit 6ac3799

Browse files
committed
Test fixes and rebase conflicts
1 parent b283881 commit 6ac3799

34 files changed

+155
-168
lines changed

src/doc/trpl/concurrency.md

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ place!
5757
## Threads
5858

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

6262
```
63-
use std::thread::Thread;
63+
use std::thread;
6464
6565
fn main() {
66-
Thread::scoped(|| {
66+
thread::scoped(|| {
6767
println!("Hello from a thread!");
6868
});
6969
}
@@ -73,10 +73,10 @@ The `Thread::scoped()` method accepts a closure, which is executed in a new
7373
thread. It's called `scoped` because this thread returns a join guard:
7474

7575
```
76-
use std::thread::Thread;
76+
use std::thread;
7777
7878
fn main() {
79-
let guard = Thread::scoped(|| {
79+
let guard = thread::scoped(|| {
8080
println!("Hello from a thread!");
8181
});
8282
@@ -85,40 +85,22 @@ fn main() {
8585
```
8686

8787
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()`:
88+
finished. If we didn't want this behaviour, we could use `thread::spawn()`:
8989

9090
```
91-
use std::thread::Thread;
91+
use std::thread;
9292
use std::old_io::timer;
9393
use std::time::Duration;
9494
9595
fn main() {
96-
Thread::spawn(|| {
96+
thread::spawn(|| {
9797
println!("Hello from a thread!");
9898
});
9999
100100
timer::sleep(Duration::milliseconds(50));
101101
}
102102
```
103103

104-
Or call `.detach()`:
105-
106-
```
107-
use std::thread::Thread;
108-
use std::old_io::timer;
109-
use std::time::Duration;
110-
111-
fn main() {
112-
let guard = Thread::scoped(|| {
113-
println!("Hello from a thread!");
114-
});
115-
116-
guard.detach();
117-
118-
timer::sleep(Duration::milliseconds(50));
119-
}
120-
```
121-
122104
We need to `sleep` here because when `main()` ends, it kills all of the
123105
running threads.
124106

@@ -164,15 +146,15 @@ As an example, here is a Rust program that would have a data race in many
164146
languages. It will not compile:
165147

166148
```ignore
167-
use std::thread::Thread;
149+
use std::thread;
168150
use std::old_io::timer;
169151
use std::time::Duration;
170152
171153
fn main() {
172154
let mut data = vec![1u32, 2, 3];
173155
174156
for i in 0..2 {
175-
Thread::spawn(move || {
157+
thread::spawn(move || {
176158
data[i] += 1;
177159
});
178160
}
@@ -203,7 +185,7 @@ only one person at a time can mutate what's inside. For that, we can use the
203185
but for a different reason:
204186

205187
```ignore
206-
use std::thread::Thread;
188+
use std::thread;
207189
use std::old_io::timer;
208190
use std::time::Duration;
209191
use std::sync::Mutex;
@@ -213,7 +195,7 @@ fn main() {
213195
214196
for i in 0..2 {
215197
let data = data.lock().unwrap();
216-
Thread::spawn(move || {
198+
thread::spawn(move || {
217199
data[i] += 1;
218200
});
219201
}
@@ -255,7 +237,7 @@ We can use `Arc<T>` to fix this. Here's the working version:
255237

256238
```
257239
use std::sync::{Arc, Mutex};
258-
use std::thread::Thread;
240+
use std::thread;
259241
use std::old_io::timer;
260242
use std::time::Duration;
261243
@@ -264,7 +246,7 @@ fn main() {
264246
265247
for i in 0us..2 {
266248
let data = data.clone();
267-
Thread::spawn(move || {
249+
thread::spawn(move || {
268250
let mut data = data.lock().unwrap();
269251
data[i] += 1;
270252
});
@@ -280,14 +262,14 @@ thread more closely:
280262

281263
```
282264
# use std::sync::{Arc, Mutex};
283-
# use std::thread::Thread;
265+
# use std::thread;
284266
# use std::old_io::timer;
285267
# use std::time::Duration;
286268
# fn main() {
287269
# let data = Arc::new(Mutex::new(vec![1u32, 2, 3]));
288270
# for i in 0us..2 {
289271
# let data = data.clone();
290-
Thread::spawn(move || {
272+
thread::spawn(move || {
291273
let mut data = data.lock().unwrap();
292274
data[i] += 1;
293275
});
@@ -315,7 +297,7 @@ than waiting for a specific time:
315297

316298
```
317299
use std::sync::{Arc, Mutex};
318-
use std::thread::Thread;
300+
use std::thread;
319301
use std::sync::mpsc;
320302
321303
fn main() {
@@ -326,7 +308,7 @@ fn main() {
326308
for _ in 0..10 {
327309
let (data, tx) = (data.clone(), tx.clone());
328310
329-
Thread::spawn(move || {
311+
thread::spawn(move || {
330312
let mut data = data.lock().unwrap();
331313
*data += 1;
332314
@@ -348,7 +330,7 @@ is `Send` over the channel!
348330

349331
```
350332
use std::sync::{Arc, Mutex};
351-
use std::thread::Thread;
333+
use std::thread;
352334
use std::sync::mpsc;
353335
354336
fn main() {
@@ -357,7 +339,7 @@ fn main() {
357339
for _ in 0..10 {
358340
let tx = tx.clone();
359341
360-
Thread::spawn(move || {
342+
thread::spawn(move || {
361343
let answer = 42u32;
362344
363345
tx.send(answer);
@@ -378,9 +360,9 @@ A `panic!` will crash the currently executing thread. You can use Rust's
378360
threads as a simple isolation mechanism:
379361

380362
```
381-
use std::thread::Thread;
363+
use std::thread;
382364
383-
let result = Thread::scoped(move || {
365+
let result = thread::spawn(move || {
384366
panic!("oops!");
385367
}).join();
386368

src/libcore/cmp.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ pub trait PartialEq<Rhs: ?Sized = Self> {
8787
/// - symmetric: `a == b` implies `b == a`; and
8888
/// - transitive: `a == b` and `b == c` implies `a == c`.
8989
///
90-
/// This property cannot be checked by the compiler, and therefore `Eq` implies `PartialEq`, and
91-
/// has no extra methods.
90+
/// This property cannot be checked by the compiler, and therefore `Eq` implies
91+
/// `PartialEq`, and has no extra methods.
9292
#[stable(feature = "rust1", since = "1.0.0")]
9393
pub trait Eq: PartialEq<Self> {
9494
// FIXME #13101: this method is used solely by #[deriving] to
@@ -100,6 +100,7 @@ pub trait Eq: PartialEq<Self> {
100100
// This should never be implemented by hand.
101101
#[doc(hidden)]
102102
#[inline(always)]
103+
#[stable(feature = "rust1", since = "1.0.0")]
103104
fn assert_receiver_is_total_eq(&self) {}
104105
}
105106

@@ -408,7 +409,7 @@ pub fn max<T: Ord>(v1: T, v2: T) -> T {
408409
/// ```
409410
/// use std::cmp;
410411
///
411-
/// let result = cmp::partial_min(std::f64::NAN, &1.0);
412+
/// let result = cmp::partial_min(std::f64::NAN, 1.0);
412413
/// assert_eq!(result, None);
413414
/// ```
414415
#[inline]
@@ -439,7 +440,7 @@ pub fn partial_min<T: PartialOrd>(v1: T, v2: T) -> Option<T> {
439440
/// ```
440441
/// use std::cmp;
441442
///
442-
/// let result = cmp::partial_max(std::f64::NAN, &1.0);
443+
/// let result = cmp::partial_max(std::f64::NAN, 1.0);
443444
/// assert_eq!(result, None);
444445
/// ```
445446
#[inline]

src/libgetopts/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
#![feature(collections)]
9393
#![feature(int_uint)]
9494
#![feature(staged_api)]
95+
#![feature(str_words)]
9596
#![cfg_attr(test, feature(rustc_private))]
9697

9798
#[cfg(test)] #[macro_use] extern crate log;

src/librustc_driver/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#![feature(rustc_private)]
3838
#![feature(unsafe_destructor)]
3939
#![feature(staged_api)]
40-
#![feature(std_misc)]
4140
#![feature(unicode)]
4241

4342
extern crate arena;
@@ -73,7 +72,7 @@ use rustc::metadata;
7372
use rustc::util::common::time;
7473

7574
use std::cmp::Ordering::Equal;
76-
use std::old_io;
75+
use std::old_io::{self, stdio};
7776
use std::iter::repeat;
7877
use std::env;
7978
use std::sync::mpsc::channel;
@@ -780,7 +779,7 @@ pub fn monitor<F:FnOnce()+Send>(f: F) {
780779
cfg = cfg.stack_size(STACK_SIZE);
781780
}
782781

783-
match cfg.scoped(move || { std::old_io::stdio::set_stderr(box w); f() }).join() {
782+
match cfg.spawn(move || { stdio::set_stderr(box w); f() }).unwrap().join() {
784783
Ok(()) => { /* fallthrough */ }
785784
Err(value) => {
786785
// Thread panicked without emitting a fatal diagnostic

src/librustc_trans/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ fn run_work_multithreaded(sess: &Session,
939939
}
940940

941941
tx.take().unwrap().send(()).unwrap();
942-
});
942+
}).unwrap();
943943
}
944944

945945
let mut panicked = false;

src/librustdoc/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#![feature(std_misc)]
3535
#![feature(test)]
3636
#![feature(unicode)]
37+
#![feature(str_words)]
3738

3839
extern crate arena;
3940
extern crate getopts;
@@ -55,6 +56,7 @@ use std::env;
5556
use std::old_io::File;
5657
use std::old_io;
5758
use std::rc::Rc;
59+
use std::sync::mpsc::channel;
5860
use externalfiles::ExternalHtml;
5961
use serialize::Decodable;
6062
use serialize::json::{self, Json};
@@ -125,8 +127,8 @@ pub fn main() {
125127
let res = std::thread::Builder::new().stack_size(STACK_SIZE).scoped(move || {
126128
let s = env::args().collect::<Vec<_>>();
127129
main_args(&s)
128-
}).join();
129-
env::set_exit_status(res.ok().unwrap() as i32);
130+
}).unwrap().join();
131+
env::set_exit_status(res as i32);
130132
}
131133

132134
pub fn opts() -> Vec<getopts::OptGroup> {
@@ -365,12 +367,14 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche
365367
let cr = Path::new(cratefile);
366368
info!("starting to run rustc");
367369

368-
let (mut krate, analysis) = std::thread::spawn(move || {
370+
let (tx, rx) = channel();
371+
std::thread::spawn(move || {
369372
use rustc::session::config::Input;
370373

371374
let cr = cr;
372-
core::run_core(paths, cfgs, externs, Input::File(cr), triple)
375+
tx.send(core::run_core(paths, cfgs, externs, Input::File(cr), triple)).unwrap();
373376
}).join().map_err(|_| "rustc failed").unwrap();
377+
let (mut krate, analysis) = rx.recv().unwrap();
374378
info!("finished with rustc");
375379
let mut analysis = Some(analysis);
376380
ANALYSISKEY.with(|s| {

src/libstd/sys/windows/thread.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use boxed::Box;
11+
use prelude::v1::*;
12+
1213
use cmp;
1314
use io;
1415
use mem;

0 commit comments

Comments
 (0)