Skip to content

Commit 2df92a3

Browse files
jethrogbJethro Beekman
authored andcommitted
---
yaml --- r: 272593 b: refs/heads/auto c: ed218f6 h: refs/heads/master i: 272591: 48c673c
1 parent 793b767 commit 2df92a3

File tree

14 files changed

+81
-286
lines changed

14 files changed

+81
-286
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: 24c5c2770203b0ddeb20b96fd7f165bf6ac551c4
11+
refs/heads/auto: ed218f62b7b8688916f12e67784a49a7b683e582
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1

branches/auto/src/doc/book/concurrency.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ The same [ownership system](ownership.html) that helps prevent using pointers
162162
incorrectly also helps rule out data races, one of the worst kinds of
163163
concurrency bugs.
164164

165-
As an example, here is a Rust program that would have a data race in many
165+
As an example, here is a Rust program that could have a data race in many
166166
languages. It will not compile:
167167

168168
```ignore
@@ -174,7 +174,7 @@ fn main() {
174174
175175
for i in 0..3 {
176176
thread::spawn(move || {
177-
data[0] += i;
177+
data[i] += 1;
178178
});
179179
}
180180
@@ -186,7 +186,7 @@ This gives us an error:
186186

187187
```text
188188
8:17 error: capture of moved value: `data`
189-
data[0] += i;
189+
data[i] += 1;
190190
^~~~
191191
```
192192

@@ -195,6 +195,11 @@ thread, and the thread takes ownership of the reference, we'd have three owners!
195195
`data` gets moved out of `main` in the first call to `spawn()`, so subsequent
196196
calls in the loop cannot use this variable.
197197

198+
Note that this specific example will not cause a data race since different array
199+
indices are being accessed. But this can't be determined at compile time, and in
200+
a similar situation where `i` is a constant or is random, you would have a data
201+
race.
202+
198203
So, we need some type that lets us have more than one owning reference to a
199204
value. Usually, we'd use `Rc<T>` for this, which is a reference counted type
200205
that provides shared ownership. It has some runtime bookkeeping that keeps track
@@ -218,7 +223,7 @@ fn main() {
218223
219224
// use it in a thread
220225
thread::spawn(move || {
221-
data_ref[0] += i;
226+
data_ref[i] += 1;
222227
});
223228
}
224229
@@ -261,7 +266,7 @@ fn main() {
261266
for i in 0..3 {
262267
let data = data.clone();
263268
thread::spawn(move || {
264-
data[0] += i;
269+
data[i] += 1;
265270
});
266271
}
267272
@@ -276,7 +281,7 @@ And... still gives us an error.
276281

277282
```text
278283
<anon>:11:24 error: cannot borrow immutable borrowed content as mutable
279-
<anon>:11 data[0] += i;
284+
<anon>:11 data[i] += 1;
280285
^~~~
281286
```
282287

@@ -312,7 +317,7 @@ fn main() {
312317
let data = data.clone();
313318
thread::spawn(move || {
314319
let mut data = data.lock().unwrap();
315-
data[0] += i;
320+
data[i] += 1;
316321
});
317322
}
318323

@@ -355,7 +360,7 @@ Let's examine the body of the thread more closely:
355360
# let data = data.clone();
356361
thread::spawn(move || {
357362
let mut data = data.lock().unwrap();
358-
data[0] += i;
363+
data[i] += 1;
359364
});
360365
# }
361366
# thread::sleep(Duration::from_millis(50));

branches/auto/src/libcore/num/mod.rs

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ macro_rules! int_impl {
149149
/// Basic usage:
150150
///
151151
/// ```
152-
/// assert_eq!(u32::from_str_radix("A", 16), Ok(10));
152+
/// assert_eq!(i32::from_str_radix("A", 16), Ok(10));
153153
/// ```
154154
#[stable(feature = "rust1", since = "1.0.0")]
155155
pub fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError> {
@@ -163,9 +163,9 @@ macro_rules! int_impl {
163163
/// Basic usage:
164164
///
165165
/// ```
166-
/// let n = 0b01001100u8;
166+
/// let n = -0b1000_0000i8;
167167
///
168-
/// assert_eq!(n.count_ones(), 3);
168+
/// assert_eq!(n.count_ones(), 1);
169169
/// ```
170170
#[stable(feature = "rust1", since = "1.0.0")]
171171
#[inline]
@@ -178,9 +178,9 @@ macro_rules! int_impl {
178178
/// Basic usage:
179179
///
180180
/// ```
181-
/// let n = 0b01001100u8;
181+
/// let n = -0b1000_0000i8;
182182
///
183-
/// assert_eq!(n.count_zeros(), 5);
183+
/// assert_eq!(n.count_zeros(), 7);
184184
/// ```
185185
#[stable(feature = "rust1", since = "1.0.0")]
186186
#[inline]
@@ -196,9 +196,9 @@ macro_rules! int_impl {
196196
/// Basic usage:
197197
///
198198
/// ```
199-
/// let n = 0b0101000u16;
199+
/// let n = -1i16;
200200
///
201-
/// assert_eq!(n.leading_zeros(), 10);
201+
/// assert_eq!(n.leading_zeros(), 0);
202202
/// ```
203203
#[stable(feature = "rust1", since = "1.0.0")]
204204
#[inline]
@@ -214,9 +214,9 @@ macro_rules! int_impl {
214214
/// Basic usage:
215215
///
216216
/// ```
217-
/// let n = 0b0101000u16;
217+
/// let n = -4i8;
218218
///
219-
/// assert_eq!(n.trailing_zeros(), 3);
219+
/// assert_eq!(n.trailing_zeros(), 2);
220220
/// ```
221221
#[stable(feature = "rust1", since = "1.0.0")]
222222
#[inline]
@@ -232,10 +232,10 @@ macro_rules! int_impl {
232232
/// Basic usage:
233233
///
234234
/// ```
235-
/// let n = 0x0123456789ABCDEFu64;
236-
/// let m = 0x3456789ABCDEF012u64;
235+
/// let n = 0x0123456789ABCDEFi64;
236+
/// let m = -0x76543210FEDCBA99i64;
237237
///
238-
/// assert_eq!(n.rotate_left(12), m);
238+
/// assert_eq!(n.rotate_left(32), m);
239239
/// ```
240240
#[stable(feature = "rust1", since = "1.0.0")]
241241
#[inline]
@@ -252,10 +252,10 @@ macro_rules! int_impl {
252252
/// Basic usage:
253253
///
254254
/// ```
255-
/// let n = 0x0123456789ABCDEFu64;
256-
/// let m = 0xDEF0123456789ABCu64;
255+
/// let n = 0x0123456789ABCDEFi64;
256+
/// let m = -0xFEDCBA987654322i64;
257257
///
258-
/// assert_eq!(n.rotate_right(12), m);
258+
/// assert_eq!(n.rotate_right(4), m);
259259
/// ```
260260
#[stable(feature = "rust1", since = "1.0.0")]
261261
#[inline]
@@ -270,8 +270,8 @@ macro_rules! int_impl {
270270
/// Basic usage:
271271
///
272272
/// ```
273-
/// let n = 0x0123456789ABCDEFu64;
274-
/// let m = 0xEFCDAB8967452301u64;
273+
/// let n = 0x0123456789ABCDEFi64;
274+
/// let m = -0x1032547698BADCFFi64;
275275
///
276276
/// assert_eq!(n.swap_bytes(), m);
277277
/// ```
@@ -291,12 +291,12 @@ macro_rules! int_impl {
291291
/// Basic usage:
292292
///
293293
/// ```
294-
/// let n = 0x0123456789ABCDEFu64;
294+
/// let n = 0x0123456789ABCDEFi64;
295295
///
296296
/// if cfg!(target_endian = "big") {
297-
/// assert_eq!(u64::from_be(n), n)
297+
/// assert_eq!(i64::from_be(n), n)
298298
/// } else {
299-
/// assert_eq!(u64::from_be(n), n.swap_bytes())
299+
/// assert_eq!(i64::from_be(n), n.swap_bytes())
300300
/// }
301301
/// ```
302302
#[stable(feature = "rust1", since = "1.0.0")]
@@ -315,12 +315,12 @@ macro_rules! int_impl {
315315
/// Basic usage:
316316
///
317317
/// ```
318-
/// let n = 0x0123456789ABCDEFu64;
318+
/// let n = 0x0123456789ABCDEFi64;
319319
///
320320
/// if cfg!(target_endian = "little") {
321-
/// assert_eq!(u64::from_le(n), n)
321+
/// assert_eq!(i64::from_le(n), n)
322322
/// } else {
323-
/// assert_eq!(u64::from_le(n), n.swap_bytes())
323+
/// assert_eq!(i64::from_le(n), n.swap_bytes())
324324
/// }
325325
/// ```
326326
#[stable(feature = "rust1", since = "1.0.0")]
@@ -339,7 +339,7 @@ macro_rules! int_impl {
339339
/// Basic usage:
340340
///
341341
/// ```
342-
/// let n = 0x0123456789ABCDEFu64;
342+
/// let n = 0x0123456789ABCDEFi64;
343343
///
344344
/// if cfg!(target_endian = "big") {
345345
/// assert_eq!(n.to_be(), n)
@@ -363,7 +363,7 @@ macro_rules! int_impl {
363363
/// Basic usage:
364364
///
365365
/// ```
366-
/// let n = 0x0123456789ABCDEFu64;
366+
/// let n = 0x0123456789ABCDEFi64;
367367
///
368368
/// if cfg!(target_endian = "little") {
369369
/// assert_eq!(n.to_le(), n)
@@ -385,8 +385,8 @@ macro_rules! int_impl {
385385
/// Basic usage:
386386
///
387387
/// ```
388-
/// assert_eq!(5u16.checked_add(65530), Some(65535));
389-
/// assert_eq!(6u16.checked_add(65530), None);
388+
/// assert_eq!(7i16.checked_add(32760), Some(32767));
389+
/// assert_eq!(8i16.checked_add(32760), None);
390390
/// ```
391391
#[stable(feature = "rust1", since = "1.0.0")]
392392
#[inline]
@@ -421,8 +421,8 @@ macro_rules! int_impl {
421421
/// Basic usage:
422422
///
423423
/// ```
424-
/// assert_eq!(5u8.checked_mul(51), Some(255));
425-
/// assert_eq!(5u8.checked_mul(52), None);
424+
/// assert_eq!(6i8.checked_mul(21), Some(126));
425+
/// assert_eq!(6i8.checked_mul(22), None);
426426
/// ```
427427
#[stable(feature = "rust1", since = "1.0.0")]
428428
#[inline]
@@ -753,8 +753,8 @@ macro_rules! int_impl {
753753
/// Basic usage:
754754
///
755755
/// ```
756-
/// assert_eq!(1u8.wrapping_shl(7), 128);
757-
/// assert_eq!(1u8.wrapping_shl(8), 1);
756+
/// assert_eq!((-1i8).wrapping_shl(7), -128);
757+
/// assert_eq!((-1i8).wrapping_shl(8), -1);
758758
/// ```
759759
#[stable(feature = "num_wrapping", since = "1.2.0")]
760760
#[inline(always)]
@@ -778,8 +778,8 @@ macro_rules! int_impl {
778778
/// Basic usage:
779779
///
780780
/// ```
781-
/// assert_eq!(128u8.wrapping_shr(7), 1);
782-
/// assert_eq!(128u8.wrapping_shr(8), 128);
781+
/// assert_eq!((-128i8).wrapping_shr(7), -1);
782+
/// assert_eq!((-128i8).wrapping_shr(8), -128);
783783
/// ```
784784
#[stable(feature = "num_wrapping", since = "1.2.0")]
785785
#[inline(always)]
@@ -1193,15 +1193,13 @@ macro_rules! uint_impl {
11931193
///
11941194
/// Leading and trailing whitespace represent an error.
11951195
///
1196-
/// # Arguments
1197-
///
1198-
/// * src - A string slice
1199-
/// * radix - The base to use. Must lie in the range [2 .. 36]
1196+
/// # Examples
12001197
///
1201-
/// # Return value
1198+
/// Basic usage:
12021199
///
1203-
/// `Err(ParseIntError)` if the string did not represent a valid number.
1204-
/// Otherwise, `Ok(n)` where `n` is the integer represented by `src`.
1200+
/// ```
1201+
/// assert_eq!(u32::from_str_radix("A", 16), Ok(10));
1202+
/// ```
12051203
#[stable(feature = "rust1", since = "1.0.0")]
12061204
pub fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError> {
12071205
from_str_radix(src, radix)
@@ -1745,7 +1743,7 @@ macro_rules! uint_impl {
17451743
/// Basic usage:
17461744
///
17471745
/// ```
1748-
/// assert_eq!(100i8.wrapping_rem(10), 0);
1746+
/// assert_eq!(100u8.wrapping_rem(10), 0);
17491747
/// ```
17501748
#[stable(feature = "num_wrapping", since = "1.2.0")]
17511749
#[inline(always)]
@@ -1783,6 +1781,13 @@ macro_rules! uint_impl {
17831781
/// where `mask` removes any high-order bits of `rhs` that
17841782
/// would cause the shift to exceed the bitwidth of the type.
17851783
///
1784+
/// Note that this is *not* the same as a rotate-left; the
1785+
/// RHS of a wrapping shift-left is restricted to the range
1786+
/// of the type, rather than the bits shifted out of the LHS
1787+
/// being returned to the other end. The primitive integer
1788+
/// types all implement a `rotate_left` function, which may
1789+
/// be what you want instead.
1790+
///
17861791
/// # Examples
17871792
///
17881793
/// Basic usage:
@@ -1801,6 +1806,13 @@ macro_rules! uint_impl {
18011806
/// where `mask` removes any high-order bits of `rhs` that
18021807
/// would cause the shift to exceed the bitwidth of the type.
18031808
///
1809+
/// Note that this is *not* the same as a rotate-right; the
1810+
/// RHS of a wrapping shift-right is restricted to the range
1811+
/// of the type, rather than the bits shifted out of the LHS
1812+
/// being returned to the other end. The primitive integer
1813+
/// types all implement a `rotate_right` function, which may
1814+
/// be what you want instead.
1815+
///
18041816
/// # Examples
18051817
///
18061818
/// Basic usage:

0 commit comments

Comments
 (0)