Skip to content

Commit aeabca1

Browse files
committed
---
yaml --- r: 229197 b: refs/heads/try c: d5b522e h: refs/heads/master i: 229195: 80fc1f3 v: v3
1 parent 3715206 commit aeabca1

File tree

176 files changed

+574
-926
lines changed

Some content is hidden

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

176 files changed

+574
-926
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: aca2057ed5fb7af3f8905b2bc01f72fa001c35c8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: 8228240ca88371150314d5474b6795c5410c7a8e
4+
refs/heads/try: d5b522e20e4aa862a62e086706187a51c9478a59
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/mk/main.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
######################################################################
1414

1515
# The version number
16-
CFG_RELEASE_NUM=1.4.0
16+
CFG_RELEASE_NUM=1.3.0
1717

1818
# An optional number to put after the label, e.g. '.2' -> '-beta.2'
1919
# NB Make sure it starts with a dot to conform to semver pre-release

branches/try/src/doc/trpl/concurrency.md

Lines changed: 61 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -135,28 +135,34 @@ This gives us an error:
135135
^~~~
136136
```
137137

138-
In this case, we know that our code _should_ be safe, but Rust isn't sure. And
139-
it's actually not safe: if we had a reference to `data` in each thread, and the
140-
thread takes ownership of the reference, we have three owners! That's bad. We
141-
can fix this by using the `Arc<T>` type, which is an atomic reference counted
142-
pointer. The 'atomic' part means that it's safe to share across threads.
138+
Rust knows this wouldn't be safe! If we had a reference to `data` in each
139+
thread, and the thread takes ownership of the reference, we'd have three
140+
owners!
141+
142+
So, we need some type that lets us have more than one reference to a value and
143+
that we can share between threads, that is it must implement `Sync`.
144+
145+
We'll use `Arc<T>`, rust's standard atomic reference count type, which
146+
wraps a value up with some extra runtime bookkeeping which allows us to
147+
share the ownership of the value between multiple references at the same time.
148+
149+
The bookkeeping consists of a count of how many of these references exist to
150+
the value, hence the reference count part of the name.
151+
152+
The Atomic part means `Arc<T>` can safely be accessed from multiple threads.
153+
To do this the compiler guarantees that mutations of the internal count use
154+
indivisible operations which can't have data races.
143155

144-
`Arc<T>` assumes one more property about its contents to ensure that it is safe
145-
to share across threads: it assumes its contents are `Sync`. But in our
146-
case, we want to be able to mutate the value. We need a type that can ensure
147-
only one person at a time can mutate what's inside. For that, we can use the
148-
`Mutex<T>` type. Here's the second version of our code. It still doesn't work,
149-
but for a different reason:
150156

151157
```ignore
152158
use std::thread;
153-
use std::sync::Mutex;
159+
use std::sync::Arc;
154160
155161
fn main() {
156-
let mut data = Mutex::new(vec![1, 2, 3]);
162+
let mut data = Arc::new(vec![1, 2, 3]);
157163
158164
for i in 0..3 {
159-
let data = data.lock().unwrap();
165+
let data = data.clone();
160166
thread::spawn(move || {
161167
data[i] += 1;
162168
});
@@ -166,29 +172,29 @@ fn main() {
166172
}
167173
```
168174

169-
Here's the error:
175+
We now call `clone()` on our `Arc<T>`, which increases the internal count.
176+
This handle is then moved into the new thread.
177+
178+
And... still gives us an error.
170179

171180
```text
172-
<anon>:9:9: 9:22 error: the trait `core::marker::Send` is not implemented for the type `std::sync::mutex::MutexGuard<'_, collections::vec::Vec<u32>>` [E0277]
173-
<anon>:11 thread::spawn(move || {
174-
^~~~~~~~~~~~~
175-
<anon>:9:9: 9:22 note: `std::sync::mutex::MutexGuard<'_, collections::vec::Vec<u32>>` cannot be sent between threads safely
176-
<anon>:11 thread::spawn(move || {
177-
^~~~~~~~~~~~~
181+
<anon>:11:24 error: cannot borrow immutable borrowed content as mutable
182+
<anon>:11 data[i] += 1;
183+
^~~~
178184
```
179185

180-
You see, [`Mutex`](../std/sync/struct.Mutex.html) has a
181-
[`lock`](../std/sync/struct.Mutex.html#method.lock)
182-
method which has this signature:
186+
`Arc<T>` assumes one more property about its contents to ensure that it is safe
187+
to share across threads: it assumes its contents are `Sync`. This is true for
188+
our value if it's immutable, but we want to be able to mutate it, so we need
189+
something else to persuade the borrow checker we know what we're doing.
183190

184-
```ignore
185-
fn lock(&self) -> LockResult<MutexGuard<T>>
186-
```
191+
It looks like we need some type that allows us to safely mutate a shared value,
192+
for example a type that that can ensure only one thread at a time is able to
193+
mutate the value inside it at any one time.
187194

188-
Because `Send` is not implemented for `MutexGuard<T>`, we can't transfer the
189-
guard across thread boundaries, which gives us our error.
195+
For that, we can use the `Mutex<T>` type!
190196

191-
We can use `Arc<T>` to fix this. Here's the working version:
197+
Here's the working version:
192198

193199
```rust
194200
use std::sync::{Arc, Mutex};
@@ -209,9 +215,31 @@ fn main() {
209215
}
210216
```
211217

212-
We now call `clone()` on our `Arc`, which increases the internal count. This
213-
handle is then moved into the new thread. Let's examine the body of the
214-
thread more closely:
218+
219+
If we'd tried to use `Mutex<T>` without wrapping it in an `Arc<T>` we would have
220+
seen another error like:
221+
222+
```text
223+
error: the trait `core::marker::Send` is not implemented for the type `std::sync::mutex::MutexGuard<'_, collections::vec::Vec<u32>>` [E0277]
224+
thread::spawn(move || {
225+
^~~~~~~~~~~~~
226+
note: `std::sync::mutex::MutexGuard<'_, collections::vec::Vec<u32>>` cannot be sent between threads safely
227+
thread::spawn(move || {
228+
^~~~~~~~~~~~~
229+
```
230+
231+
You see, [`Mutex`](../std/sync/struct.Mutex.html) has a
232+
[`lock`](../std/sync/struct.Mutex.html#method.lock)
233+
method which has this signature:
234+
235+
```ignore
236+
fn lock(&self) -> LockResult<MutexGuard<T>>
237+
```
238+
239+
and because `Send` is not implemented for `MutexGuard<T>`, we couldn't have
240+
transferred the guard across thread boundaries on it's own.
241+
242+
Let's examine the body of the thread more closely:
215243

216244
```rust
217245
# use std::sync::{Arc, Mutex};

branches/try/src/liballoc/arc.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@
7171
7272
use boxed::Box;
7373

74-
#[cfg(stage0)]
75-
use core::prelude::v1::*;
74+
use core::prelude::*;
7675

7776
use core::atomic;
7877
use core::atomic::Ordering::{Relaxed, Release, Acquire, SeqCst};

branches/try/src/liballoc/boxed.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@
5353
5454
#![stable(feature = "rust1", since = "1.0.0")]
5555

56-
#[cfg(stage0)]
57-
use core::prelude::v1::*;
56+
use core::prelude::*;
5857

5958
use heap;
6059
use raw_vec::RawVec;

branches/try/src/liballoc/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
#![feature(coerce_unsized)]
7676
#![feature(core)]
7777
#![feature(core_intrinsics)]
78+
#![feature(core_prelude)]
7879
#![feature(core_slice_ext)]
7980
#![feature(custom_attribute)]
8081
#![feature(fundamental)]
@@ -92,17 +93,17 @@
9293
#![feature(unsize)]
9394
#![feature(core_slice_ext)]
9495
#![feature(core_str_ext)]
95-
#![cfg_attr(stage0, feature(core, core_prelude))]
9696

9797
#![cfg_attr(test, feature(test, alloc, rustc_private, box_raw))]
9898
#![cfg_attr(all(not(feature = "external_funcs"), not(feature = "external_crate")),
9999
feature(libc))]
100100

101+
#[macro_use]
102+
extern crate core;
103+
101104
#[cfg(all(not(feature = "external_funcs"), not(feature = "external_crate")))]
102105
extern crate libc;
103106

104-
#[cfg(stage0)] #[macro_use] extern crate core;
105-
106107
// Allow testing this library
107108

108109
#[cfg(test)] #[macro_use] extern crate std;

branches/try/src/liballoc/rc.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@
150150
151151
#![stable(feature = "rust1", since = "1.0.0")]
152152

153-
#[cfg(stage0)]
154-
use core::prelude::v1::*;
153+
use core::prelude::*;
155154

156155
#[cfg(not(test))]
157156
use boxed::Box;

branches/try/src/libcollections/binary_heap.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@
151151
#![allow(missing_docs)]
152152
#![stable(feature = "rust1", since = "1.0.0")]
153153

154-
#[cfg(stage0)]
155-
use core::prelude::v1::*;
154+
use core::prelude::*;
156155

157156
use core::iter::{FromIterator};
158157
use core::mem::swap;

branches/try/src/libcollections/bit.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@
8686
//! println!("There are {} primes below {}", num_primes, max_prime);
8787
//! ```
8888
89-
#[cfg(stage0)]
90-
use core::prelude::v1::*;
89+
use core::prelude::*;
9190

9291
use core::cmp::Ordering;
9392
use core::cmp;

branches/try/src/libcollections/btree/map.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717

1818
use self::Entry::*;
1919

20-
#[cfg(stage0)]
21-
use core::prelude::v1::*;
20+
use core::prelude::*;
2221

2322
use core::cmp::Ordering;
2423
use core::fmt::Debug;
@@ -531,8 +530,7 @@ enum Continuation<A, B> {
531530
/// to nodes. By using this module much better safety guarantees can be made, and more search
532531
/// boilerplate gets cut out.
533532
mod stack {
534-
#[cfg(stage0)]
535-
use core::prelude::v1::*;
533+
use core::prelude::*;
536534
use core::marker;
537535
use core::mem;
538536
use core::ops::{Deref, DerefMut};

branches/try/src/libcollections/btree/node.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ pub use self::SearchResult::*;
1616
pub use self::ForceResult::*;
1717
pub use self::TraversalItem::*;
1818

19-
#[cfg(stage0)]
20-
use core::prelude::v1::*;
19+
use core::prelude::*;
2120

2221
use core::cmp::Ordering::{Greater, Less, Equal};
2322
use core::intrinsics::arith_offset;

branches/try/src/libcollections/btree/set.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
// This is pretty much entirely stolen from TreeSet, since BTreeMap has an identical interface
1212
// to TreeMap
1313

14-
#[cfg(stage0)]
15-
use core::prelude::v1::*;
14+
use core::prelude::*;
1615

1716
use core::cmp::Ordering::{self, Less, Greater, Equal};
1817
use core::fmt::Debug;

branches/try/src/libcollections/enum_set.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
reason = "matches collection reform specification, \
1818
waiting for dust to settle")]
1919

20-
#[cfg(stage0)]
21-
use core::prelude::v1::*;
22-
20+
use core::prelude::*;
2321
use core::marker;
2422
use core::fmt;
2523
use core::iter::{FromIterator};

branches/try/src/libcollections/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
#![feature(alloc)]
3434
#![feature(box_patterns)]
3535
#![feature(box_syntax)]
36+
#![feature(core)]
3637
#![feature(core_intrinsics)]
38+
#![feature(core_prelude)]
3739
#![feature(core_slice_ext)]
3840
#![feature(core_str_ext)]
3941
#![feature(heap_api)]
@@ -60,12 +62,12 @@
6062
#![feature(utf8_error)]
6163
#![cfg_attr(test, feature(rand, test))]
6264
#![cfg_attr(not(test), feature(str_words))]
63-
#![cfg_attr(stage0, feature(core, core_prelude))]
6465

6566
#![feature(no_std)]
6667
#![no_std]
6768

68-
#[cfg(stage0)] #[macro_use] extern crate core;
69+
#[macro_use]
70+
extern crate core;
6971

7072
extern crate rustc_unicode;
7173
extern crate alloc;

branches/try/src/libcollections/linked_list.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121

2222
#![stable(feature = "rust1", since = "1.0.0")]
2323

24-
#[cfg(stage0)]
25-
use core::prelude::v1::*;
24+
use core::prelude::*;
2625

2726
use alloc::boxed::Box;
2827
use core::cmp::Ordering;

branches/try/src/libcollections/string.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
1313
#![stable(feature = "rust1", since = "1.0.0")]
1414

15-
#[cfg(stage0)]
16-
use core::prelude::v1::*;
15+
use core::prelude::*;
1716

1817
use core::fmt;
1918
use core::hash;

branches/try/src/libcollections/vec.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@
5858
5959
#![stable(feature = "rust1", since = "1.0.0")]
6060

61-
#[cfg(stage0)]
62-
use core::prelude::v1::*;
63-
61+
use core::prelude::*;
6462
use alloc::raw_vec::RawVec;
6563
use alloc::boxed::Box;
6664
use alloc::heap::EMPTY;

branches/try/src/libcollections/vec_deque.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
1919
#![stable(feature = "rust1", since = "1.0.0")]
2020

21-
#[cfg(stage0)]
22-
use core::prelude::v1::*;
21+
use core::prelude::*;
2322

2423
use core::cmp::Ordering;
2524
use core::fmt;

branches/try/src/libcollections/vec_map.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020

2121
use self::Entry::*;
2222

23-
#[cfg(stage0)]
24-
use core::prelude::v1::*;
23+
use core::prelude::*;
2524

2625
use core::cmp::{max, Ordering};
2726
use core::fmt;

branches/try/src/libcore/fmt/builders.rs

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

11-
use prelude::v1::*;
11+
use prelude::*;
1212
use fmt::{self, Write, FlagV1};
1313

1414
struct PadAdapter<'a, 'b: 'a> {

branches/try/src/libcore/fmt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
#![stable(feature = "rust1", since = "1.0.0")]
1414

15-
use prelude::v1::*;
15+
use prelude::*;
1616

1717
use cell::{Cell, RefCell, Ref, RefMut, BorrowState};
1818
use marker::PhantomData;

branches/try/src/libcore/fmt/num.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
// FIXME: #6220 Implement floating point formatting
1414

15-
use prelude::v1::*;
15+
use prelude::*;
1616

1717
use fmt;
1818
use num::Zero;

branches/try/src/libcore/hash/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
6363
#![stable(feature = "rust1", since = "1.0.0")]
6464

65-
use prelude::v1::*;
65+
use prelude::*;
6666

6767
use mem;
6868

@@ -183,7 +183,7 @@ pub fn hash<T: Hash, H: Hasher + Default>(value: &T) -> u64 {
183183
//////////////////////////////////////////////////////////////////////////////
184184

185185
mod impls {
186-
use prelude::v1::*;
186+
use prelude::*;
187187

188188
use slice;
189189
use super::*;

0 commit comments

Comments
 (0)