Skip to content

Commit c0221c8

Browse files
committed
Auto merge of #32882 - steveklabnik:rollup, r=steveklabnik
Rollup of 9 pull requests - Successful merges: #32768, #32802, #32815, #32823, #32849, #32854, #32862, #32870, #32873 - Failed merges:
2 parents b622c3e + 55e90bb commit c0221c8

File tree

11 files changed

+233
-65
lines changed

11 files changed

+233
-65
lines changed

src/doc/book/concurrency.md

+8-13
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 could have a data race in many
165+
As an example, here is a Rust program that would 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[i] += 1;
177+
data[0] += i;
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[i] += 1;
189+
data[0] += i;
190190
^~~~
191191
```
192192

@@ -195,11 +195,6 @@ 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-
203198
So, we need some type that lets us have more than one owning reference to a
204199
value. Usually, we'd use `Rc<T>` for this, which is a reference counted type
205200
that provides shared ownership. It has some runtime bookkeeping that keeps track
@@ -223,7 +218,7 @@ fn main() {
223218
224219
// use it in a thread
225220
thread::spawn(move || {
226-
data_ref[i] += 1;
221+
data_ref[0] += i;
227222
});
228223
}
229224
@@ -266,7 +261,7 @@ fn main() {
266261
for i in 0..3 {
267262
let data = data.clone();
268263
thread::spawn(move || {
269-
data[i] += 1;
264+
data[0] += i;
270265
});
271266
}
272267
@@ -281,7 +276,7 @@ And... still gives us an error.
281276

282277
```text
283278
<anon>:11:24 error: cannot borrow immutable borrowed content as mutable
284-
<anon>:11 data[i] += 1;
279+
<anon>:11 data[0] += i;
285280
^~~~
286281
```
287282

@@ -317,7 +312,7 @@ fn main() {
317312
let data = data.clone();
318313
thread::spawn(move || {
319314
let mut data = data.lock().unwrap();
320-
data[i] += 1;
315+
data[0] += i;
321316
});
322317
}
323318

@@ -360,7 +355,7 @@ Let's examine the body of the thread more closely:
360355
# let data = data.clone();
361356
thread::spawn(move || {
362357
let mut data = data.lock().unwrap();
363-
data[i] += 1;
358+
data[0] += i;
364359
});
365360
# }
366361
# thread::sleep(Duration::from_millis(50));

src/libcore/num/mod.rs

+53-41
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)