diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2016-02-25 15:52:29 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2016-02-29 09:05:33 -0800 |
| commit | b643782a10288a86a500168d754026bd0fce2ab5 (patch) | |
| tree | 3cdcf9693f45703b64f4d0d86c5fbbbef0c439c2 /src/libstd | |
| parent | 504ca6f4221b5745c5d72902c1c30415845afa26 (diff) | |
| download | rust-b643782a10288a86a500168d754026bd0fce2ab5.tar.gz rust-b643782a10288a86a500168d754026bd0fce2ab5.zip | |
std: Stabilize APIs for the 1.8 release
This commit is the result of the FCPs ending for the 1.8 release cycle for both
the libs and the lang suteams. The full list of changes are:
Stabilized
* `braced_empty_structs`
* `augmented_assignments`
* `str::encode_utf16` - renamed from `utf16_units`
* `str::EncodeUtf16` - renamed from `Utf16Units`
* `Ref::map`
* `RefMut::map`
* `ptr::drop_in_place`
* `time::Instant`
* `time::SystemTime`
* `{Instant,SystemTime}::now`
* `{Instant,SystemTime}::duration_since` - renamed from `duration_from_earlier`
* `{Instant,SystemTime}::elapsed`
* Various `Add`/`Sub` impls for `Time` and `SystemTime`
* `SystemTimeError`
* `SystemTimeError::duration`
* Various impls for `SystemTimeError`
* `UNIX_EPOCH`
* `ops::{Add,Sub,Mul,Div,Rem,BitAnd,BitOr,BitXor,Shl,Shr}Assign`
Deprecated
* Scoped TLS (the `scoped_thread_local!` macro)
* `Ref::filter_map`
* `RefMut::filter_map`
* `RwLockReadGuard::map`
* `RwLockWriteGuard::map`
* `Condvar::wait_timeout_with`
Closes #27714
Closes #27715
Closes #27746
Closes #27748
Closes #27908
Closes #29866
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/lib.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sync/condvar.rs | 3 | ||||
| -rw-r--r-- | src/libstd/sync/rwlock.rs | 8 | ||||
| -rw-r--r-- | src/libstd/sys/windows/compat.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/windows/stdio.rs | 2 | ||||
| -rw-r--r-- | src/libstd/thread/mod.rs | 1 | ||||
| -rw-r--r-- | src/libstd/thread/scoped_tls.rs | 9 | ||||
| -rw-r--r-- | src/libstd/time/mod.rs | 82 |
8 files changed, 78 insertions, 30 deletions
diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index f9e7c1fede2..e062f9040af 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -226,7 +226,6 @@ #![feature(core_float)] #![feature(core_intrinsics)] #![feature(decode_utf16)] -#![feature(drop_in_place)] #![feature(dropck_parametricity)] #![feature(float_extras)] #![feature(float_from_str_radix)] diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs index 9a786752365..0ff3a690702 100644 --- a/src/libstd/sync/condvar.rs +++ b/src/libstd/sync/condvar.rs @@ -209,6 +209,9 @@ impl Condvar { #[unstable(feature = "wait_timeout_with", reason = "unsure if this API is broadly needed or what form it should take", issue = "27748")] + #[rustc_deprecated(since = "1.8.0", + reason = "wonky signature and questionable \ + implementation didn't justify existence")] pub fn wait_timeout_with<'a, T, F>(&self, guard: MutexGuard<'a, T>, dur: Duration, diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index fd538d52fb2..0603dad4528 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -457,6 +457,10 @@ impl<'rwlock, T: ?Sized> RwLockReadGuard<'rwlock, T> { reason = "recently added, needs RFC for stabilization, questionable interaction with Condvar", issue = "27746")] + #[rustc_deprecated(since = "1.8.0", + reason = "unsound on Mutex because of Condvar and \ + RwLock may also with to be used with Condvar \ + one day")] pub fn map<U: ?Sized, F>(this: Self, cb: F) -> RwLockReadGuard<'rwlock, U> where F: FnOnce(&T) -> &U { @@ -508,6 +512,10 @@ impl<'rwlock, T: ?Sized> RwLockWriteGuard<'rwlock, T> { reason = "recently added, needs RFC for stabilization, questionable interaction with Condvar", issue = "27746")] + #[rustc_deprecated(since = "1.8.0", + reason = "unsound on Mutex because of Condvar and \ + RwLock may also with to be used with Condvar \ + one day")] pub fn map<U: ?Sized, F>(this: Self, cb: F) -> RwLockWriteGuard<'rwlock, U> where F: FnOnce(&mut T) -> &mut U { diff --git a/src/libstd/sys/windows/compat.rs b/src/libstd/sys/windows/compat.rs index 780a0d9427d..acbfacce8bd 100644 --- a/src/libstd/sys/windows/compat.rs +++ b/src/libstd/sys/windows/compat.rs @@ -28,7 +28,7 @@ use sync::atomic::{AtomicUsize, Ordering}; use sys::c; pub fn lookup(module: &str, symbol: &str) -> Option<usize> { - let mut module: Vec<u16> = module.utf16_units().collect(); + let mut module: Vec<u16> = module.encode_utf16().collect(); module.push(0); let symbol = CString::new(symbol).unwrap(); unsafe { diff --git a/src/libstd/sys/windows/stdio.rs b/src/libstd/sys/windows/stdio.rs index 8f37dc02e87..1cd05b61d25 100644 --- a/src/libstd/sys/windows/stdio.rs +++ b/src/libstd/sys/windows/stdio.rs @@ -56,7 +56,7 @@ fn write(out: &Output, data: &[u8]) -> io::Result<usize> { Output::Pipe(ref p) => return p.get().write(data), }; let utf16 = match str::from_utf8(data).ok() { - Some(utf8) => utf8.utf16_units().collect::<Vec<u16>>(), + Some(utf8) => utf8.encode_utf16().collect::<Vec<u16>>(), None => return Err(invalid_encoding()), }; let mut written = 0; diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 116cd5da2ce..981ba1e36e9 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -188,6 +188,7 @@ pub use self::local::{LocalKey, LocalKeyState}; reason = "scoped TLS has yet to have wide enough use to fully \ consider stabilizing its interface", issue = "27715")] +#[allow(deprecated)] pub use self::scoped_tls::ScopedKey; #[unstable(feature = "libstd_thread_internals", issue = "0")] diff --git a/src/libstd/thread/scoped_tls.rs b/src/libstd/thread/scoped_tls.rs index dc0bc6dfe02..dea58d016e4 100644 --- a/src/libstd/thread/scoped_tls.rs +++ b/src/libstd/thread/scoped_tls.rs @@ -41,6 +41,7 @@ //! ``` #![unstable(feature = "thread_local_internals", issue = "0")] +#![allow(deprecated)] #[doc(hidden)] pub use self::imp::KeyInner as __KeyInner; @@ -56,6 +57,8 @@ pub use self::imp::KeyInner as __KeyInner; reason = "scoped TLS has yet to have wide enough use to fully consider \ stabilizing its interface", issue = "27715")] +#[rustc_deprecated(since = "1.8.0", + reason = "hasn't proven itself over LocalKey")] pub struct ScopedKey<T:'static> { inner: fn() -> &'static imp::KeyInner<T> } /// Declare a new scoped thread local storage key. @@ -68,6 +71,8 @@ pub struct ScopedKey<T:'static> { inner: fn() -> &'static imp::KeyInner<T> } #[unstable(feature = "thread_local_internals", reason = "should not be necessary", issue = "0")] +#[rustc_deprecated(since = "1.8.0", + reason = "hasn't proven itself over LocalKey")] #[macro_export] #[allow_internal_unstable] macro_rules! scoped_thread_local { @@ -85,6 +90,8 @@ macro_rules! scoped_thread_local { #[unstable(feature = "thread_local_internals", reason = "should not be necessary", issue = "0")] +#[rustc_deprecated(since = "1.8.0", + reason = "hasn't proven itself over LocalKey")] #[macro_export] #[allow_internal_unstable] macro_rules! __scoped_thread_local_inner { @@ -101,6 +108,8 @@ macro_rules! __scoped_thread_local_inner { reason = "scoped TLS has yet to have wide enough use to fully consider \ stabilizing its interface", issue = "27715")] +#[rustc_deprecated(since = "1.8.0", + reason = "hasn't proven itself over LocalKey")] impl<T> ScopedKey<T> { #[doc(hidden)] pub const fn new(inner: fn() -> &'static imp::KeyInner<T>) -> ScopedKey<T> { diff --git a/src/libstd/time/mod.rs b/src/libstd/time/mod.rs index a0cf443c0c3..aa0a843dc9a 100644 --- a/src/libstd/time/mod.rs +++ b/src/libstd/time/mod.rs @@ -41,7 +41,7 @@ mod duration; /// allows measuring the duration between two instants (or comparing two /// instants). #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] -#[unstable(feature = "time2", reason = "recently added", issue = "29866")] +#[stable(feature = "time2", since = "1.8.0")] pub struct Instant(time::Instant); /// A measurement of the system clock, useful for talking to @@ -64,18 +64,18 @@ pub struct Instant(time::Instant); /// fixed point in time, a `SystemTime` can be converted to a human-readable time, /// or perhaps some other string representation. #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] -#[unstable(feature = "time2", reason = "recently added", issue = "29866")] +#[stable(feature = "time2", since = "1.8.0")] pub struct SystemTime(time::SystemTime); -/// An error returned from the `duration_from_earlier` method on `SystemTime`, +/// An error returned from the `duration_since` method on `SystemTime`, /// used to learn about why how far in the opposite direction a timestamp lies. #[derive(Clone, Debug)] -#[unstable(feature = "time2", reason = "recently added", issue = "29866")] +#[stable(feature = "time2", since = "1.8.0")] pub struct SystemTimeError(Duration); -#[unstable(feature = "time2", reason = "recently added", issue = "29866")] impl Instant { /// Returns an instant corresponding to "now". + #[stable(feature = "time2", since = "1.8.0")] pub fn now() -> Instant { Instant(time::Instant::now()) } @@ -88,6 +88,14 @@ impl Instant { /// only be possible if `earlier` was created after `self`. Because /// `Instant` is monotonic, the only time that this should happen should be /// a bug. + #[stable(feature = "time2", since = "1.8.0")] + pub fn duration_since(&self, earlier: Instant) -> Duration { + self.0.sub_instant(&earlier.0) + } + + /// Deprecated, renamed to `duration_since` + #[unstable(feature = "time2_old", issue = "29866")] + #[rustc_deprecated(since = "1.8.0", reason = "renamed to duration_since")] pub fn duration_from_earlier(&self, earlier: Instant) -> Duration { self.0.sub_instant(&earlier.0) } @@ -99,12 +107,13 @@ impl Instant { /// This function may panic if the current time is earlier than this /// instant, which is something that can happen if an `Instant` is /// produced synthetically. + #[stable(feature = "time2", since = "1.8.0")] pub fn elapsed(&self) -> Duration { - Instant::now().duration_from_earlier(*self) + Instant::now() - *self } } -#[unstable(feature = "time2", reason = "recently added", issue = "29866")] +#[stable(feature = "time2", since = "1.8.0")] impl Add<Duration> for Instant { type Output = Instant; @@ -113,7 +122,7 @@ impl Add<Duration> for Instant { } } -#[unstable(feature = "time2", reason = "recently added", issue = "29866")] +#[stable(feature = "time2", since = "1.8.0")] impl Sub<Duration> for Instant { type Output = Instant; @@ -122,16 +131,25 @@ impl Sub<Duration> for Instant { } } -#[unstable(feature = "time2", reason = "recently added", issue = "29866")] +#[stable(feature = "time2", since = "1.8.0")] +impl Sub<Instant> for Instant { + type Output = Duration; + + fn sub(self, other: Instant) -> Duration { + self.duration_since(other) + } +} + +#[stable(feature = "time2", since = "1.8.0")] impl fmt::Debug for Instant { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.0.fmt(f) } } -#[unstable(feature = "time2", reason = "recently added", issue = "29866")] impl SystemTime { /// Returns the system time corresponding to "now". + #[stable(feature = "time2", since = "1.8.0")] pub fn now() -> SystemTime { SystemTime(time::SystemTime::now()) } @@ -147,6 +165,15 @@ impl SystemTime { /// /// Returns an `Err` if `earlier` is later than `self`, and the error /// contains how far from `self` the time is. + #[stable(feature = "time2", since = "1.8.0")] + pub fn duration_since(&self, earlier: SystemTime) + -> Result<Duration, SystemTimeError> { + self.0.sub_time(&earlier.0).map_err(SystemTimeError) + } + + /// Deprecated, renamed to `duration_since` + #[unstable(feature = "time2_old", issue = "29866")] + #[rustc_deprecated(since = "1.8.0", reason = "renamed to duration_since")] pub fn duration_from_earlier(&self, earlier: SystemTime) -> Result<Duration, SystemTimeError> { self.0.sub_time(&earlier.0).map_err(SystemTimeError) @@ -162,12 +189,13 @@ impl SystemTime { /// /// Returns an `Err` if `self` is later than the current system time, and /// the error contains how far from the current system time `self` is. + #[stable(feature = "time2", since = "1.8.0")] pub fn elapsed(&self) -> Result<Duration, SystemTimeError> { - SystemTime::now().duration_from_earlier(*self) + SystemTime::now().duration_since(*self) } } -#[unstable(feature = "time2", reason = "recently added", issue = "29866")] +#[stable(feature = "time2", since = "1.8.0")] impl Add<Duration> for SystemTime { type Output = SystemTime; @@ -176,7 +204,7 @@ impl Add<Duration> for SystemTime { } } -#[unstable(feature = "time2", reason = "recently added", issue = "29866")] +#[stable(feature = "time2", since = "1.8.0")] impl Sub<Duration> for SystemTime { type Output = SystemTime; @@ -185,7 +213,7 @@ impl Sub<Duration> for SystemTime { } } -#[unstable(feature = "time2", reason = "recently added", issue = "29866")] +#[stable(feature = "time2", since = "1.8.0")] impl fmt::Debug for SystemTime { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.0.fmt(f) @@ -196,32 +224,32 @@ impl fmt::Debug for SystemTime { /// learn about where in time a `SystemTime` lies. /// /// This constant is defined to be "1970-01-01 00:00:00 UTC" on all systems with -/// respect to the system clock. Using `duration_from_earlier` on an existing +/// respect to the system clock. Using `duration_since` on an existing /// `SystemTime` instance can tell how far away from this point in time a /// measurement lies, and using `UNIX_EPOCH + duration` can be used to create a /// `SystemTime` instance to represent another fixed point in time. -#[unstable(feature = "time2", reason = "recently added", issue = "29866")] +#[stable(feature = "time2", since = "1.8.0")] pub const UNIX_EPOCH: SystemTime = SystemTime(time::UNIX_EPOCH); -#[unstable(feature = "time2", reason = "recently added", issue = "29866")] impl SystemTimeError { /// Returns the positive duration which represents how far forward the /// second system time was from the first. /// - /// A `SystemTimeError` is returned from the `duration_from_earlier` + /// A `SystemTimeError` is returned from the `duration_since` /// operation whenever the second system time represents a point later /// in time than the `self` of the method call. + #[stable(feature = "time2", since = "1.8.0")] pub fn duration(&self) -> Duration { self.0 } } -#[unstable(feature = "time2", reason = "recently added", issue = "29866")] +#[stable(feature = "time2", since = "1.8.0")] impl Error for SystemTimeError { fn description(&self) -> &str { "other time was not earlier than self" } } -#[unstable(feature = "time2", reason = "recently added", issue = "29866")] +#[stable(feature = "time2", since = "1.8.0")] impl fmt::Display for SystemTimeError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "second time provided was later than self") @@ -265,7 +293,7 @@ mod tests { fn instant_math() { let a = Instant::now(); let b = Instant::now(); - let dur = b.duration_from_earlier(a); + let dur = b.duration_since(a); assert_almost_eq!(b - dur, a); assert_almost_eq!(a + dur, b); @@ -277,14 +305,14 @@ mod tests { #[should_panic] fn instant_duration_panic() { let a = Instant::now(); - (a - Duration::new(1, 0)).duration_from_earlier(a); + (a - Duration::new(1, 0)).duration_since(a); } #[test] fn system_time_math() { let a = SystemTime::now(); let b = SystemTime::now(); - match b.duration_from_earlier(a) { + match b.duration_since(a) { Ok(dur) if dur == Duration::new(0, 0) => { assert_almost_eq!(a, b); } @@ -302,8 +330,8 @@ mod tests { } let second = Duration::new(1, 0); - assert_almost_eq!(a.duration_from_earlier(a - second).unwrap(), second); - assert_almost_eq!(a.duration_from_earlier(a + second).unwrap_err() + assert_almost_eq!(a.duration_since(a - second).unwrap(), second); + assert_almost_eq!(a.duration_since(a + second).unwrap_err() .duration(), second); assert_almost_eq!(a - second + second, a); @@ -327,8 +355,8 @@ mod tests { #[test] fn since_epoch() { let ts = SystemTime::now(); - let a = ts.duration_from_earlier(UNIX_EPOCH).unwrap(); - let b = ts.duration_from_earlier(UNIX_EPOCH - Duration::new(1, 0)).unwrap(); + let a = ts.duration_since(UNIX_EPOCH).unwrap(); + let b = ts.duration_since(UNIX_EPOCH - Duration::new(1, 0)).unwrap(); assert!(b > a); assert_eq!(b - a, Duration::new(1, 0)); |
