diff options
| author | bors <bors@rust-lang.org> | 2017-11-29 12:17:45 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-11-29 12:17:45 +0000 |
| commit | 0a2e9ade83ff253bb489c63a95b1f499c5e0916f (patch) | |
| tree | 6fe2c8003b84d6e710ad6d57b77427b66b9c4ad4 /src/libstd | |
| parent | dc0e227745765c198958f0298785d18bcf61d4ae (diff) | |
| parent | 51bd916af49dff0e88cf3cd01d507aa5fabc6cf8 (diff) | |
| download | rust-0a2e9ade83ff253bb489c63a95b1f499c5e0916f.tar.gz rust-0a2e9ade83ff253bb489c63a95b1f499c5e0916f.zip | |
Auto merge of #46362 - kennytm:rollup, r=kennytm
Rollup of 10 pull requests - Successful merges: #45969, #46077, #46219, #46287, #46293, #46322, #46323, #46330, #46354, #46356 - Failed merges:
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/ascii.rs | 209 | ||||
| -rw-r--r-- | src/libstd/lib.rs | 11 | ||||
| -rw-r--r-- | src/libstd/sync/mpsc/mod.rs | 71 | ||||
| -rw-r--r-- | src/libstd/sync/once.rs | 1 |
4 files changed, 232 insertions, 60 deletions
diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 96d719c528c..312da203574 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -490,77 +490,199 @@ impl AsciiExt for [u8] { } } -macro_rules! impl_by_delegating { - ($ty:ty, $owned:ty) => { - #[stable(feature = "rust1", since = "1.0.0")] - impl AsciiExt for $ty { - type Owned = $owned; +macro_rules! delegating_ascii_methods { + () => { + #[inline] + fn is_ascii(&self) -> bool { self.is_ascii() } - #[inline] - fn is_ascii(&self) -> bool { self.is_ascii() } + #[inline] + fn to_ascii_uppercase(&self) -> Self::Owned { self.to_ascii_uppercase() } - #[inline] - fn to_ascii_uppercase(&self) -> Self::Owned { self.to_ascii_uppercase() } + #[inline] + fn to_ascii_lowercase(&self) -> Self::Owned { self.to_ascii_lowercase() } - #[inline] - fn to_ascii_lowercase(&self) -> Self::Owned { self.to_ascii_lowercase() } + #[inline] + fn eq_ignore_ascii_case(&self, o: &Self) -> bool { self.eq_ignore_ascii_case(o) } - #[inline] - fn eq_ignore_ascii_case(&self, o: &Self) -> bool { self.eq_ignore_ascii_case(o) } + #[inline] + fn make_ascii_uppercase(&mut self) { self.make_ascii_uppercase(); } - #[inline] - fn make_ascii_uppercase(&mut self) { self.make_ascii_uppercase(); } - - #[inline] - fn make_ascii_lowercase(&mut self) { self.make_ascii_lowercase(); } + #[inline] + fn make_ascii_lowercase(&mut self) { self.make_ascii_lowercase(); } + } +} - #[inline] - fn is_ascii_alphabetic(&self) -> bool { self.is_ascii_alphabetic() } +macro_rules! delegating_ascii_ctype_methods { + () => { + #[inline] + fn is_ascii_alphabetic(&self) -> bool { self.is_ascii_alphabetic() } - #[inline] - fn is_ascii_uppercase(&self) -> bool { self.is_ascii_uppercase() } + #[inline] + fn is_ascii_uppercase(&self) -> bool { self.is_ascii_uppercase() } - #[inline] - fn is_ascii_lowercase(&self) -> bool { self.is_ascii_lowercase() } + #[inline] + fn is_ascii_lowercase(&self) -> bool { self.is_ascii_lowercase() } - #[inline] - fn is_ascii_alphanumeric(&self) -> bool { self.is_ascii_alphanumeric() } + #[inline] + fn is_ascii_alphanumeric(&self) -> bool { self.is_ascii_alphanumeric() } - #[inline] - fn is_ascii_digit(&self) -> bool { self.is_ascii_digit() } + #[inline] + fn is_ascii_digit(&self) -> bool { self.is_ascii_digit() } - #[inline] - fn is_ascii_hexdigit(&self) -> bool { self.is_ascii_hexdigit() } + #[inline] + fn is_ascii_hexdigit(&self) -> bool { self.is_ascii_hexdigit() } - #[inline] - fn is_ascii_punctuation(&self) -> bool { self.is_ascii_punctuation() } + #[inline] + fn is_ascii_punctuation(&self) -> bool { self.is_ascii_punctuation() } - #[inline] - fn is_ascii_graphic(&self) -> bool { self.is_ascii_graphic() } + #[inline] + fn is_ascii_graphic(&self) -> bool { self.is_ascii_graphic() } - #[inline] - fn is_ascii_whitespace(&self) -> bool { self.is_ascii_whitespace() } + #[inline] + fn is_ascii_whitespace(&self) -> bool { self.is_ascii_whitespace() } - #[inline] - fn is_ascii_control(&self) -> bool { self.is_ascii_control() } - } + #[inline] + fn is_ascii_control(&self) -> bool { self.is_ascii_control() } } } -impl_by_delegating!(u8, u8); -impl_by_delegating!(char, char); +#[stable(feature = "rust1", since = "1.0.0")] +impl AsciiExt for u8 { + type Owned = u8; + + delegating_ascii_methods!(); + delegating_ascii_ctype_methods!(); +} + +#[stable(feature = "rust1", since = "1.0.0")] +impl AsciiExt for char { + type Owned = char; + + delegating_ascii_methods!(); + delegating_ascii_ctype_methods!(); +} // FIXME(LukasKalbertodt): the macro invocation should replace the impl block // for `[u8]` above. But this is not possible until the stage0 compiler is new // enough to contain the inherent ascii methods for `[u8]`. #[cfg(not(stage0))] -impl_by_delegating!([u8], Vec<u8>); +#[stable(feature = "rust1", since = "1.0.0")] +impl AsciiExt for [u8] { + type Owned = Vec<u8>; + + delegating_ascii_methods!(); + + #[inline] + fn is_ascii_alphabetic(&self) -> bool { + self.iter().all(|b| b.is_ascii_alphabetic()) + } + + #[inline] + fn is_ascii_uppercase(&self) -> bool { + self.iter().all(|b| b.is_ascii_uppercase()) + } + + #[inline] + fn is_ascii_lowercase(&self) -> bool { + self.iter().all(|b| b.is_ascii_lowercase()) + } + + #[inline] + fn is_ascii_alphanumeric(&self) -> bool { + self.iter().all(|b| b.is_ascii_alphanumeric()) + } + + #[inline] + fn is_ascii_digit(&self) -> bool { + self.iter().all(|b| b.is_ascii_digit()) + } + + #[inline] + fn is_ascii_hexdigit(&self) -> bool { + self.iter().all(|b| b.is_ascii_hexdigit()) + } + + #[inline] + fn is_ascii_punctuation(&self) -> bool { + self.iter().all(|b| b.is_ascii_punctuation()) + } + + #[inline] + fn is_ascii_graphic(&self) -> bool { + self.iter().all(|b| b.is_ascii_graphic()) + } + + #[inline] + fn is_ascii_whitespace(&self) -> bool { + self.iter().all(|b| b.is_ascii_whitespace()) + } + + #[inline] + fn is_ascii_control(&self) -> bool { + self.iter().all(|b| b.is_ascii_control()) + } +} // FIXME(LukasKalbertodt): the macro invocation should replace the impl block // for `str` above. But this is not possible until the stage0 compiler is new // enough to contain the inherent ascii methods for `str`. #[cfg(not(stage0))] -impl_by_delegating!(str, String); +#[stable(feature = "rust1", since = "1.0.0")] +impl AsciiExt for str { + type Owned = String; + + delegating_ascii_methods!(); + + #[inline] + fn is_ascii_alphabetic(&self) -> bool { + self.bytes().all(|b| b.is_ascii_alphabetic()) + } + + #[inline] + fn is_ascii_uppercase(&self) -> bool { + self.bytes().all(|b| b.is_ascii_uppercase()) + } + + #[inline] + fn is_ascii_lowercase(&self) -> bool { + self.bytes().all(|b| b.is_ascii_lowercase()) + } + + #[inline] + fn is_ascii_alphanumeric(&self) -> bool { + self.bytes().all(|b| b.is_ascii_alphanumeric()) + } + + #[inline] + fn is_ascii_digit(&self) -> bool { + self.bytes().all(|b| b.is_ascii_digit()) + } + + #[inline] + fn is_ascii_hexdigit(&self) -> bool { + self.bytes().all(|b| b.is_ascii_hexdigit()) + } + + #[inline] + fn is_ascii_punctuation(&self) -> bool { + self.bytes().all(|b| b.is_ascii_punctuation()) + } + + #[inline] + fn is_ascii_graphic(&self) -> bool { + self.bytes().all(|b| b.is_ascii_graphic()) + } + + #[inline] + fn is_ascii_whitespace(&self) -> bool { + self.bytes().all(|b| b.is_ascii_whitespace()) + } + + #[inline] + fn is_ascii_control(&self) -> bool { + self.bytes().all(|b| b.is_ascii_control()) + } +} /// An iterator over the escaped version of a byte. /// @@ -684,6 +806,7 @@ mod tests { //! Note that most of these tests are not testing `AsciiExt` methods, but //! test inherent ascii methods of char, u8, str and [u8]. `AsciiExt` is //! just using those methods, though. + use super::AsciiExt; use char::from_u32; #[test] diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 9587bb424bd..bf177ac7f2c 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -256,15 +256,6 @@ #![feature(collections_range)] #![feature(compiler_builtins_lib)] #![feature(const_fn)] -#![feature(const_max_value)] -#![feature(const_atomic_bool_new)] -#![feature(const_atomic_isize_new)] -#![feature(const_atomic_usize_new)] -#![feature(const_unsafe_cell_new)] -#![feature(const_cell_new)] -#![feature(const_once_new)] -#![feature(const_ptr_null)] -#![feature(const_ptr_null_mut)] #![feature(core_float)] #![feature(core_intrinsics)] #![feature(dropck_eyepatch)] @@ -306,7 +297,6 @@ #![feature(repr_align)] #![feature(repr_simd)] #![feature(rustc_attrs)] -#![feature(rustc_const_unstable)] #![feature(shared)] #![feature(sip_hash_13)] #![feature(slice_bytes)] @@ -331,7 +321,6 @@ #![feature(doc_masked)] #![feature(doc_spotlight)] #![cfg_attr(test, feature(update_panic_count))] -#![cfg_attr(windows, feature(const_atomic_ptr_new))] #![cfg_attr(windows, feature(used))] #![default_lib_allocator] diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 8d7f60f9d2c..2dd3aebe610 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -1297,11 +1297,72 @@ impl<T> Receiver<T> { Err(TryRecvError::Disconnected) => Err(RecvTimeoutError::Disconnected), Err(TryRecvError::Empty) - => self.recv_max_until(Instant::now() + timeout) + => self.recv_deadline(Instant::now() + timeout) } } - fn recv_max_until(&self, deadline: Instant) -> Result<T, RecvTimeoutError> { + /// Attempts to wait for a value on this receiver, returning an error if the + /// corresponding channel has hung up, or if `deadline` is reached. + /// + /// This function will always block the current thread if there is no data + /// available and it's possible for more data to be sent. Once a message is + /// sent to the corresponding [`Sender`][] (or [`SyncSender`]), then this + /// receiver will wake up and return that message. + /// + /// If the corresponding [`Sender`] has disconnected, or it disconnects while + /// this call is blocking, this call will wake up and return [`Err`] to + /// indicate that no more messages can ever be received on this channel. + /// However, since channels are buffered, messages sent before the disconnect + /// will still be properly received. + /// + /// [`Sender`]: struct.Sender.html + /// [`SyncSender`]: struct.SyncSender.html + /// [`Err`]: ../../../std/result/enum.Result.html#variant.Err + /// + /// # Examples + /// + /// Successfully receiving value before reaching deadline: + /// + /// ```no_run + /// #![feature(deadline_api)] + /// use std::thread; + /// use std::time::{Duration, Instant}; + /// use std::sync::mpsc; + /// + /// let (send, recv) = mpsc::channel(); + /// + /// thread::spawn(move || { + /// send.send('a').unwrap(); + /// }); + /// + /// assert_eq!( + /// recv.recv_deadline(Instant::now() + Duration::from_millis(400)), + /// Ok('a') + /// ); + /// ``` + /// + /// Receiving an error upon reaching deadline: + /// + /// ```no_run + /// #![feature(deadline_api)] + /// use std::thread; + /// use std::time::{Duration, Instant}; + /// use std::sync::mpsc; + /// + /// let (send, recv) = mpsc::channel(); + /// + /// thread::spawn(move || { + /// thread::sleep(Duration::from_millis(800)); + /// send.send('a').unwrap(); + /// }); + /// + /// assert_eq!( + /// recv.recv_deadline(Instant::now() + Duration::from_millis(400)), + /// Err(mpsc::RecvTimeoutError::Timeout) + /// ); + /// ``` + #[unstable(feature = "deadline_api", issue = "46316")] + pub fn recv_deadline(&self, deadline: Instant) -> Result<T, RecvTimeoutError> { use self::RecvTimeoutError::*; loop { @@ -1625,7 +1686,7 @@ impl<T: Send> error::Error for TrySendError<T> { } } -#[stable(feature = "mpsc_error_conversions", since = "1.23.0")] +#[stable(feature = "mpsc_error_conversions", since = "1.24.0")] impl<T> From<SendError<T>> for TrySendError<T> { fn from(err: SendError<T>) -> TrySendError<T> { match err { @@ -1686,7 +1747,7 @@ impl error::Error for TryRecvError { } } -#[stable(feature = "mpsc_error_conversions", since = "1.23.0")] +#[stable(feature = "mpsc_error_conversions", since = "1.24.0")] impl From<RecvError> for TryRecvError { fn from(err: RecvError) -> TryRecvError { match err { @@ -1727,7 +1788,7 @@ impl error::Error for RecvTimeoutError { } } -#[stable(feature = "mpsc_error_conversions", since = "1.23.0")] +#[stable(feature = "mpsc_error_conversions", since = "1.24.0")] impl From<RecvError> for RecvTimeoutError { fn from(err: RecvError) -> RecvTimeoutError { match err { diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index 2ef99525af5..6fd8b6a5bba 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -156,7 +156,6 @@ struct Finish { impl Once { /// Creates a new `Once` value. #[stable(feature = "once_new", since = "1.2.0")] - #[rustc_const_unstable(feature = "const_once_new")] pub const fn new() -> Once { Once { state: AtomicUsize::new(INCOMPLETE), |
