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:
This commit is contained in:
commit
c0221c8897
@ -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
|
||||
@ -174,7 +174,7 @@ fn main() {
|
||||
|
||||
for i in 0..3 {
|
||||
thread::spawn(move || {
|
||||
data[i] += 1;
|
||||
data[0] += i;
|
||||
});
|
||||
}
|
||||
|
||||
@ -186,7 +186,7 @@ This gives us an error:
|
||||
|
||||
```text
|
||||
8:17 error: capture of moved value: `data`
|
||||
data[i] += 1;
|
||||
data[0] += i;
|
||||
^~~~
|
||||
```
|
||||
|
||||
@ -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
|
||||
@ -223,7 +218,7 @@ fn main() {
|
||||
|
||||
// use it in a thread
|
||||
thread::spawn(move || {
|
||||
data_ref[i] += 1;
|
||||
data_ref[0] += i;
|
||||
});
|
||||
}
|
||||
|
||||
@ -266,7 +261,7 @@ fn main() {
|
||||
for i in 0..3 {
|
||||
let data = data.clone();
|
||||
thread::spawn(move || {
|
||||
data[i] += 1;
|
||||
data[0] += i;
|
||||
});
|
||||
}
|
||||
|
||||
@ -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;
|
||||
^~~~
|
||||
```
|
||||
|
||||
@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
@ -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));
|
||||
|
@ -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> {
|
||||
@ -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]
|
||||
@ -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]
|
||||
@ -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]
|
||||
@ -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]
|
||||
@ -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]
|
||||
@ -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]
|
||||
@ -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);
|
||||
/// ```
|
||||
@ -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")]
|
||||
@ -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")]
|
||||
@ -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)
|
||||
@ -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)
|
||||
@ -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]
|
||||
@ -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]
|
||||
@ -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)]
|
||||
@ -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)]
|
||||
@ -1193,15 +1193,13 @@ macro_rules! uint_impl {
|
||||
///
|
||||
/// Leading and trailing whitespace represent an error.
|
||||
///
|
||||
/// # Arguments
|
||||
/// # Examples
|
||||
///
|
||||
/// * src - A string slice
|
||||
/// * radix - The base to use. Must lie in the range [2 .. 36]
|
||||
/// Basic usage:
|
||||
///
|
||||
/// # Return value
|
||||
///
|
||||
/// `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)
|
||||
@ -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)]
|
||||
@ -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:
|
||||
@ -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:
|
||||
|
@ -19,7 +19,7 @@
|
||||
//! # #[allow(dead_code)]
|
||||
//! enum Result<T, E> {
|
||||
//! Ok(T),
|
||||
//! Err(E)
|
||||
//! Err(E),
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
@ -39,7 +39,7 @@
|
||||
//! None => Err("invalid header length"),
|
||||
//! Some(&1) => Ok(Version::Version1),
|
||||
//! Some(&2) => Ok(Version::Version2),
|
||||
//! Some(_) => Err("invalid version")
|
||||
//! Some(_) => Err("invalid version"),
|
||||
//! }
|
||||
//! }
|
||||
//!
|
||||
@ -254,7 +254,7 @@ pub enum Result<T, E> {
|
||||
|
||||
/// Contains the error value
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
Err(#[stable(feature = "rust1", since = "1.0.0")] E)
|
||||
Err(#[stable(feature = "rust1", since = "1.0.0")] E),
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@ -270,6 +270,8 @@ impl<T, E> Result<T, E> {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// let x: Result<i32, &str> = Ok(-3);
|
||||
/// assert_eq!(x.is_ok(), true);
|
||||
@ -290,6 +292,8 @@ impl<T, E> Result<T, E> {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// let x: Result<i32, &str> = Ok(-3);
|
||||
/// assert_eq!(x.is_err(), false);
|
||||
@ -314,6 +318,8 @@ impl<T, E> Result<T, E> {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// let x: Result<u32, &str> = Ok(2);
|
||||
/// assert_eq!(x.ok(), Some(2));
|
||||
@ -337,6 +343,8 @@ impl<T, E> Result<T, E> {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// let x: Result<u32, &str> = Ok(2);
|
||||
/// assert_eq!(x.err(), None);
|
||||
@ -362,6 +370,10 @@ impl<T, E> Result<T, E> {
|
||||
/// Produces a new `Result`, containing a reference
|
||||
/// into the original, leaving the original in place.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// let x: Result<u32, &str> = Ok(2);
|
||||
/// assert_eq!(x.as_ref(), Ok(&2));
|
||||
@ -380,6 +392,10 @@ impl<T, E> Result<T, E> {
|
||||
|
||||
/// Converts from `Result<T, E>` to `Result<&mut T, &mut E>`
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// fn mutate(r: &mut Result<i32, i32>) {
|
||||
/// match r.as_mut() {
|
||||
@ -445,6 +461,8 @@ impl<T, E> Result<T, E> {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// fn stringify(x: u32) -> String { format!("error code: {}", x) }
|
||||
///
|
||||
@ -471,6 +489,8 @@ impl<T, E> Result<T, E> {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// let x: Result<u32, &str> = Ok(7);
|
||||
/// assert_eq!(x.iter().next(), Some(&7));
|
||||
@ -488,6 +508,8 @@ impl<T, E> Result<T, E> {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// let mut x: Result<u32, &str> = Ok(7);
|
||||
/// match x.iter_mut().next() {
|
||||
@ -513,6 +535,8 @@ impl<T, E> Result<T, E> {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// let x: Result<u32, &str> = Ok(2);
|
||||
/// let y: Result<&str, &str> = Err("late error");
|
||||
@ -545,6 +569,8 @@ impl<T, E> Result<T, E> {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// fn sq(x: u32) -> Result<u32, u32> { Ok(x * x) }
|
||||
/// fn err(x: u32) -> Result<u32, u32> { Err(x) }
|
||||
@ -567,6 +593,8 @@ impl<T, E> Result<T, E> {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// let x: Result<u32, &str> = Ok(2);
|
||||
/// let y: Result<u32, &str> = Err("late error");
|
||||
@ -599,6 +627,8 @@ impl<T, E> Result<T, E> {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// fn sq(x: u32) -> Result<u32, u32> { Ok(x * x) }
|
||||
/// fn err(x: u32) -> Result<u32, u32> { Err(x) }
|
||||
@ -622,6 +652,8 @@ impl<T, E> Result<T, E> {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// let optb = 2;
|
||||
/// let x: Result<u32, &str> = Ok(9);
|
||||
@ -644,6 +676,8 @@ impl<T, E> Result<T, E> {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// fn count(x: &str) -> usize { x.len() }
|
||||
///
|
||||
@ -670,6 +704,8 @@ impl<T, E: fmt::Debug> Result<T, E> {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// let x: Result<u32, &str> = Ok(2);
|
||||
/// assert_eq!(x.unwrap(), 2);
|
||||
@ -696,6 +732,9 @@ impl<T, E: fmt::Debug> Result<T, E> {
|
||||
/// passed message, and the content of the `Err`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```{.should_panic}
|
||||
/// let x: Result<u32, &str> = Err("emergency failure");
|
||||
/// x.expect("Testing expect"); // panics with `Testing expect: emergency failure`
|
||||
@ -759,6 +798,8 @@ impl<T, E> IntoIterator for Result<T, E> {
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// let x: Result<u32, &str> = Ok(5);
|
||||
/// let v: Vec<u32> = x.into_iter().collect();
|
||||
|
@ -871,6 +871,20 @@ macro_rules! make_mut_slice {
|
||||
}
|
||||
|
||||
/// Immutable slice iterator
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// // First, we declare a type which has `iter` method to get the `Iter` struct (&[usize here]):
|
||||
/// let slice = &[1, 2, 3];
|
||||
///
|
||||
/// // Then, we iterate over it:
|
||||
/// for element in slice.iter() {
|
||||
/// println!("{}", element);
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct Iter<'a, T: 'a> {
|
||||
ptr: *const T,
|
||||
@ -897,6 +911,26 @@ impl<'a, T> Iter<'a, T> {
|
||||
///
|
||||
/// This has the same lifetime as the original slice, and so the
|
||||
/// iterator can continue to be used while this exists.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// // First, we declare a type which has the `iter` method to get the `Iter`
|
||||
/// // struct (&[usize here]):
|
||||
/// let slice = &[1, 2, 3];
|
||||
///
|
||||
/// // Then, we get the iterator:
|
||||
/// let mut iter = slice.iter();
|
||||
/// // So if we print what `as_slice` method returns here, we have "[1, 2, 3]":
|
||||
/// println!("{:?}", iter.as_slice());
|
||||
///
|
||||
/// // Next, we move to the second element of the slice:
|
||||
/// iter.next();
|
||||
/// // Now `as_slice` returns "[2, 3]":
|
||||
/// println!("{:?}", iter.as_slice());
|
||||
/// ```
|
||||
#[stable(feature = "iter_to_slice", since = "1.4.0")]
|
||||
pub fn as_slice(&self) -> &'a [T] {
|
||||
make_slice!(self.ptr, self.end)
|
||||
@ -928,6 +962,24 @@ impl<'a, T> Clone for Iter<'a, T> {
|
||||
}
|
||||
|
||||
/// Mutable slice iterator.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// // First, we declare a type which has `iter_mut` method to get the `IterMut`
|
||||
/// // struct (&[usize here]):
|
||||
/// let mut slice = &mut [1, 2, 3];
|
||||
///
|
||||
/// // Then, we iterate over it and increment each element value:
|
||||
/// for element in slice.iter_mut() {
|
||||
/// *element += 1;
|
||||
/// }
|
||||
///
|
||||
/// // We now have "[2, 3, 4]":
|
||||
/// println!("{:?}", slice);
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct IterMut<'a, T: 'a> {
|
||||
ptr: *mut T,
|
||||
@ -956,6 +1008,35 @@ impl<'a, T> IterMut<'a, T> {
|
||||
/// to consume the iterator. Consider using the `Slice` and
|
||||
/// `SliceMut` implementations for obtaining slices with more
|
||||
/// restricted lifetimes that do not consume the iterator.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// // First, we declare a type which has `iter_mut` method to get the `IterMut`
|
||||
/// // struct (&[usize here]):
|
||||
/// let mut slice = &mut [1, 2, 3];
|
||||
///
|
||||
/// {
|
||||
/// // Then, we get the iterator:
|
||||
/// let mut iter = slice.iter_mut();
|
||||
/// // We move to next element:
|
||||
/// iter.next();
|
||||
/// // So if we print what `into_slice` method returns here, we have "[2, 3]":
|
||||
/// println!("{:?}", iter.into_slice());
|
||||
/// }
|
||||
///
|
||||
/// // Now let's modify a value of the slice:
|
||||
/// {
|
||||
/// // First we get back the iterator:
|
||||
/// let mut iter = slice.iter_mut();
|
||||
/// // We change the value of the first element of the slice returned by the `next` method:
|
||||
/// *iter.next().unwrap() += 1;
|
||||
/// }
|
||||
/// // Now slice is "[2, 2, 3]":
|
||||
/// println!("{:?}", slice);
|
||||
/// ```
|
||||
#[stable(feature = "iter_to_slice", since = "1.4.0")]
|
||||
pub fn into_slice(self) -> &'a mut [T] {
|
||||
make_mut_slice!(self.ptr, self.end)
|
||||
|
@ -1940,7 +1940,8 @@ impl StrExt for str {
|
||||
if index == 0 || index == self.len() { return true; }
|
||||
match self.as_bytes().get(index) {
|
||||
None => false,
|
||||
Some(&b) => b < 128 || b >= 192,
|
||||
// This is bit magic equivalent to: b < 128 || b >= 192
|
||||
Some(&b) => (b as i8) >= -0x40,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -436,6 +436,7 @@ impl Target {
|
||||
key!(target_family, optional);
|
||||
key!(is_like_osx, bool);
|
||||
key!(is_like_windows, bool);
|
||||
key!(is_like_msvc, bool);
|
||||
key!(linker_is_gnu, bool);
|
||||
key!(has_rpath, bool);
|
||||
key!(no_compiler_rt, bool);
|
||||
|
@ -539,6 +539,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
(&Failed(_), &Failed(_)) => {
|
||||
let resolutions = target_module.resolutions.borrow();
|
||||
let names = resolutions.iter().filter_map(|(&(ref name, _), resolution)| {
|
||||
if *name == source { return None; } // Never suggest the same name
|
||||
match *resolution.borrow() {
|
||||
NameResolution { binding: Some(_), .. } => Some(name),
|
||||
NameResolution { single_imports: SingleImports::None, .. } => None,
|
||||
@ -549,9 +550,12 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
||||
Some(name) => format!(". Did you mean to use `{}`?", name),
|
||||
None => "".to_owned(),
|
||||
};
|
||||
let msg = format!("There is no `{}` in `{}`{}",
|
||||
source,
|
||||
module_to_string(target_module), lev_suggestion);
|
||||
let module_str = module_to_string(target_module);
|
||||
let msg = if &module_str == "???" {
|
||||
format!("There is no `{}` in the crate root{}", source, lev_suggestion)
|
||||
} else {
|
||||
format!("There is no `{}` in `{}`{}", source, module_str, lev_suggestion)
|
||||
};
|
||||
return Failed(Some((directive.span, msg)));
|
||||
}
|
||||
_ => (),
|
||||
|
@ -466,7 +466,7 @@ enum State {
|
||||
Done = 3,
|
||||
}
|
||||
|
||||
/// A Windows path prefix, e.g. `C:` or `\server\share`.
|
||||
/// A Windows path prefix, e.g. `C:` or `\\server\share`.
|
||||
///
|
||||
/// Does not occur on Unix.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -528,7 +528,7 @@ impl<'a> Hash for PrefixComponent<'a> {
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub enum Component<'a> {
|
||||
/// A Windows path prefix, e.g. `C:` or `\server\share`.
|
||||
/// A Windows path prefix, e.g. `C:` or `\\server\share`.
|
||||
///
|
||||
/// Does not occur on Unix.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
16
src/test/compile-fail/issue-32833.rs
Normal file
16
src/test/compile-fail/issue-32833.rs
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use bar::Foo; //~ ERROR There is no `Foo` in `bar` [E0432]
|
||||
mod bar {
|
||||
use Foo; //~ ERROR There is no `Foo` in the crate root [E0432]
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -10,10 +10,10 @@
|
||||
|
||||
mod foo {
|
||||
use self::{self};
|
||||
//~^ ERROR unresolved import `self`. There is no `self` in `???`
|
||||
//~^ ERROR unresolved import `self`. There is no `self` in the crate root
|
||||
|
||||
use super::{self};
|
||||
//~^ ERROR unresolved import `super`. There is no `super` in `???`
|
||||
//~^ ERROR unresolved import `super`. There is no `super` in the crate root
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
17
src/test/parse-fail/issue-32505.rs
Normal file
17
src/test/parse-fail/issue-32505.rs
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags: -Z parse-only -Z continue-parse-after-error
|
||||
|
||||
pub fn test() {
|
||||
foo(|_|) //~ ERROR unexpected token: `)`
|
||||
}
|
||||
|
||||
fn main() { }
|
Loading…
x
Reference in New Issue
Block a user