Skip to content

Rollup of 9 pull requests #32882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Apr 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
73389f6
add regression test for #32505
nikomatsakis Apr 7, 2016
69289c9
Add doc example for Iter and IterMut
GuillaumeGomez Apr 7, 2016
a6e86ec
Read "is-like-msvc" target option from JSON
pravic Apr 8, 2016
4d8fac0
Add data race to concurrency docs
allonsy Apr 8, 2016
ca966b6
Add some missing commas and missing titles/formatting
GuillaumeGomez Apr 9, 2016
2944fab
Improve import resolution diagnostics
jseyfried Apr 9, 2016
178c396
Update tests
jseyfried Apr 9, 2016
44ddaa2
Add regression test
jseyfried Apr 9, 2016
b2db973
Bit-magic for faster is_char_boundary
raphlinus Apr 10, 2016
0fa0a6b
Fix Windows UNC paths in std::path docs
jethrogb Apr 10, 2016
ed218f6
Match signed/unsigned integer type docs
jethrogb Apr 11, 2016
7eeb8c4
Rollup merge of #32768 - GuillaumeGomez:slice_doc, r=steveklabnik
steveklabnik Apr 11, 2016
47cc036
Rollup merge of #32802 - nikomatsakis:issue-32505, r=eddyb
steveklabnik Apr 11, 2016
b5fc27c
Rollup merge of #32815 - allonsy:master, r=GuillaumeGomez
steveklabnik Apr 11, 2016
9989a95
Rollup merge of #32823 - pravic:target-json, r=alexcrichton
steveklabnik Apr 11, 2016
c9c8509
Rollup merge of #32849 - jseyfried:import_resolution_diagnostics, r=e…
steveklabnik Apr 11, 2016
7ba7e02
Rollup merge of #32854 - GuillaumeGomez:result_doc, r=steveklabnik
steveklabnik Apr 11, 2016
c584283
Rollup merge of #32862 - raphlinus:master, r=bluss
steveklabnik Apr 11, 2016
24c5c27
Rollup merge of #32870 - jethrogb:patch-1, r=GuillaumeGomez
steveklabnik Apr 11, 2016
55e90bb
Rollup merge of #32873 - jethrogb:patch-2, r=steveklabnik
steveklabnik Apr 11, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions src/doc/book/concurrency.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ The same [ownership system](ownership.html) that helps prevent using pointers
incorrectly also helps rule out data races, one of the worst kinds of
concurrency bugs.

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

```ignore
Expand All @@ -174,7 +174,7 @@ fn main() {

for i in 0..3 {
thread::spawn(move || {
data[i] += 1;
data[0] += i;
});
}

Expand All @@ -186,7 +186,7 @@ This gives us an error:

```text
8:17 error: capture of moved value: `data`
data[i] += 1;
data[0] += i;
^~~~
```

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

Note that this specific example will not cause a data race since different array
indices are being accessed. But this can't be determined at compile time, and in
a similar situation where `i` is a constant or is random, you would have a data
race.

So, we need some type that lets us have more than one owning reference to a
value. Usually, we'd use `Rc<T>` for this, which is a reference counted type
that provides shared ownership. It has some runtime bookkeeping that keeps track
Expand All @@ -223,7 +218,7 @@ fn main() {

// use it in a thread
thread::spawn(move || {
data_ref[i] += 1;
data_ref[0] += i;
});
}

Expand Down Expand Up @@ -266,7 +261,7 @@ fn main() {
for i in 0..3 {
let data = data.clone();
thread::spawn(move || {
data[i] += 1;
data[0] += i;
});
}

Expand All @@ -281,7 +276,7 @@ And... still gives us an error.

```text
<anon>:11:24 error: cannot borrow immutable borrowed content as mutable
<anon>:11 data[i] += 1;
<anon>:11 data[0] += i;
^~~~
```

Expand Down Expand Up @@ -317,7 +312,7 @@ fn main() {
let data = data.clone();
thread::spawn(move || {
let mut data = data.lock().unwrap();
data[i] += 1;
data[0] += i;
});
}

Expand Down Expand Up @@ -360,7 +355,7 @@ Let's examine the body of the thread more closely:
# let data = data.clone();
thread::spawn(move || {
let mut data = data.lock().unwrap();
data[i] += 1;
data[0] += i;
});
# }
# thread::sleep(Duration::from_millis(50));
Expand Down
94 changes: 53 additions & 41 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ macro_rules! int_impl {
/// Basic usage:
///
/// ```
/// assert_eq!(u32::from_str_radix("A", 16), Ok(10));
/// assert_eq!(i32::from_str_radix("A", 16), Ok(10));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError> {
Expand All @@ -163,9 +163,9 @@ macro_rules! int_impl {
/// Basic usage:
///
/// ```
/// let n = 0b01001100u8;
/// let n = -0b1000_0000i8;
///
/// assert_eq!(n.count_ones(), 3);
/// assert_eq!(n.count_ones(), 1);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand All @@ -178,9 +178,9 @@ macro_rules! int_impl {
/// Basic usage:
///
/// ```
/// let n = 0b01001100u8;
/// let n = -0b1000_0000i8;
///
/// assert_eq!(n.count_zeros(), 5);
/// assert_eq!(n.count_zeros(), 7);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand All @@ -196,9 +196,9 @@ macro_rules! int_impl {
/// Basic usage:
///
/// ```
/// let n = 0b0101000u16;
/// let n = -1i16;
///
/// assert_eq!(n.leading_zeros(), 10);
/// assert_eq!(n.leading_zeros(), 0);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand All @@ -214,9 +214,9 @@ macro_rules! int_impl {
/// Basic usage:
///
/// ```
/// let n = 0b0101000u16;
/// let n = -4i8;
///
/// assert_eq!(n.trailing_zeros(), 3);
/// assert_eq!(n.trailing_zeros(), 2);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand All @@ -232,10 +232,10 @@ macro_rules! int_impl {
/// Basic usage:
///
/// ```
/// let n = 0x0123456789ABCDEFu64;
/// let m = 0x3456789ABCDEF012u64;
/// let n = 0x0123456789ABCDEFi64;
/// let m = -0x76543210FEDCBA99i64;
///
/// assert_eq!(n.rotate_left(12), m);
/// assert_eq!(n.rotate_left(32), m);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand All @@ -252,10 +252,10 @@ macro_rules! int_impl {
/// Basic usage:
///
/// ```
/// let n = 0x0123456789ABCDEFu64;
/// let m = 0xDEF0123456789ABCu64;
/// let n = 0x0123456789ABCDEFi64;
/// let m = -0xFEDCBA987654322i64;
///
/// assert_eq!(n.rotate_right(12), m);
/// assert_eq!(n.rotate_right(4), m);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand All @@ -270,8 +270,8 @@ macro_rules! int_impl {
/// Basic usage:
///
/// ```
/// let n = 0x0123456789ABCDEFu64;
/// let m = 0xEFCDAB8967452301u64;
/// let n = 0x0123456789ABCDEFi64;
/// let m = -0x1032547698BADCFFi64;
///
/// assert_eq!(n.swap_bytes(), m);
/// ```
Expand All @@ -291,12 +291,12 @@ macro_rules! int_impl {
/// Basic usage:
///
/// ```
/// let n = 0x0123456789ABCDEFu64;
/// let n = 0x0123456789ABCDEFi64;
///
/// if cfg!(target_endian = "big") {
/// assert_eq!(u64::from_be(n), n)
/// assert_eq!(i64::from_be(n), n)
/// } else {
/// assert_eq!(u64::from_be(n), n.swap_bytes())
/// assert_eq!(i64::from_be(n), n.swap_bytes())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -315,12 +315,12 @@ macro_rules! int_impl {
/// Basic usage:
///
/// ```
/// let n = 0x0123456789ABCDEFu64;
/// let n = 0x0123456789ABCDEFi64;
///
/// if cfg!(target_endian = "little") {
/// assert_eq!(u64::from_le(n), n)
/// assert_eq!(i64::from_le(n), n)
/// } else {
/// assert_eq!(u64::from_le(n), n.swap_bytes())
/// assert_eq!(i64::from_le(n), n.swap_bytes())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -339,7 +339,7 @@ macro_rules! int_impl {
/// Basic usage:
///
/// ```
/// let n = 0x0123456789ABCDEFu64;
/// let n = 0x0123456789ABCDEFi64;
///
/// if cfg!(target_endian = "big") {
/// assert_eq!(n.to_be(), n)
Expand All @@ -363,7 +363,7 @@ macro_rules! int_impl {
/// Basic usage:
///
/// ```
/// let n = 0x0123456789ABCDEFu64;
/// let n = 0x0123456789ABCDEFi64;
///
/// if cfg!(target_endian = "little") {
/// assert_eq!(n.to_le(), n)
Expand All @@ -385,8 +385,8 @@ macro_rules! int_impl {
/// Basic usage:
///
/// ```
/// assert_eq!(5u16.checked_add(65530), Some(65535));
/// assert_eq!(6u16.checked_add(65530), None);
/// assert_eq!(7i16.checked_add(32760), Some(32767));
/// assert_eq!(8i16.checked_add(32760), None);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand Down Expand Up @@ -421,8 +421,8 @@ macro_rules! int_impl {
/// Basic usage:
///
/// ```
/// assert_eq!(5u8.checked_mul(51), Some(255));
/// assert_eq!(5u8.checked_mul(52), None);
/// assert_eq!(6i8.checked_mul(21), Some(126));
/// assert_eq!(6i8.checked_mul(22), None);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand Down Expand Up @@ -753,8 +753,8 @@ macro_rules! int_impl {
/// Basic usage:
///
/// ```
/// assert_eq!(1u8.wrapping_shl(7), 128);
/// assert_eq!(1u8.wrapping_shl(8), 1);
/// assert_eq!((-1i8).wrapping_shl(7), -128);
/// assert_eq!((-1i8).wrapping_shl(8), -1);
/// ```
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[inline(always)]
Expand All @@ -778,8 +778,8 @@ macro_rules! int_impl {
/// Basic usage:
///
/// ```
/// assert_eq!(128u8.wrapping_shr(7), 1);
/// assert_eq!(128u8.wrapping_shr(8), 128);
/// assert_eq!((-128i8).wrapping_shr(7), -1);
/// assert_eq!((-128i8).wrapping_shr(8), -128);
/// ```
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[inline(always)]
Expand Down Expand Up @@ -1193,15 +1193,13 @@ macro_rules! uint_impl {
///
/// Leading and trailing whitespace represent an error.
///
/// # Arguments
///
/// * src - A string slice
/// * radix - The base to use. Must lie in the range [2 .. 36]
/// # Examples
///
/// # Return value
/// Basic usage:
///
/// `Err(ParseIntError)` if the string did not represent a valid number.
/// Otherwise, `Ok(n)` where `n` is the integer represented by `src`.
/// ```
/// assert_eq!(u32::from_str_radix("A", 16), Ok(10));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseIntError> {
from_str_radix(src, radix)
Expand Down Expand Up @@ -1745,7 +1743,7 @@ macro_rules! uint_impl {
/// Basic usage:
///
/// ```
/// assert_eq!(100i8.wrapping_rem(10), 0);
/// assert_eq!(100u8.wrapping_rem(10), 0);
/// ```
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[inline(always)]
Expand Down Expand Up @@ -1783,6 +1781,13 @@ macro_rules! uint_impl {
/// where `mask` removes any high-order bits of `rhs` that
/// would cause the shift to exceed the bitwidth of the type.
///
/// Note that this is *not* the same as a rotate-left; the
/// RHS of a wrapping shift-left is restricted to the range
/// of the type, rather than the bits shifted out of the LHS
/// being returned to the other end. The primitive integer
/// types all implement a `rotate_left` function, which may
/// be what you want instead.
///
/// # Examples
///
/// Basic usage:
Expand All @@ -1801,6 +1806,13 @@ macro_rules! uint_impl {
/// where `mask` removes any high-order bits of `rhs` that
/// would cause the shift to exceed the bitwidth of the type.
///
/// Note that this is *not* the same as a rotate-right; the
/// RHS of a wrapping shift-right is restricted to the range
/// of the type, rather than the bits shifted out of the LHS
/// being returned to the other end. The primitive integer
/// types all implement a `rotate_right` function, which may
/// be what you want instead.
///
/// # Examples
///
/// Basic usage:
Expand Down
Loading