From c99f4c4c5b9f968b82037cf643b6662b140d9b1f Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Tue, 27 Feb 2018 17:00:01 +0100 Subject: Stabilize LocalKey::try_with --- src/libstd/thread/local.rs | 28 +++++++++++++++------------- src/libstd/thread/mod.rs | 5 ++++- 2 files changed, 19 insertions(+), 14 deletions(-) (limited to 'src/libstd/thread') diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index fcbca38a98f..b6dbcf8914c 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -199,6 +199,7 @@ macro_rules! __thread_local_inner { #[unstable(feature = "thread_local_state", reason = "state querying was recently added", issue = "27716")] +#[rustc_deprecated(since = "1.26.0", reason = "use `LocalKey::try_with` instead")] #[derive(Debug, Eq, PartialEq, Copy, Clone)] pub enum LocalKeyState { /// All keys are in this state whenever a thread starts. Keys will @@ -234,25 +235,19 @@ pub enum LocalKeyState { } /// An error returned by [`LocalKey::try_with`](struct.LocalKey.html#method.try_with). -#[unstable(feature = "thread_local_state", - reason = "state querying was recently added", - issue = "27716")] +#[stable(feature = "thread_local_try_with", since = "1.26.0")] pub struct AccessError { _private: (), } -#[unstable(feature = "thread_local_state", - reason = "state querying was recently added", - issue = "27716")] +#[stable(feature = "thread_local_try_with", since = "1.26.0")] impl fmt::Debug for AccessError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("AccessError").finish() } } -#[unstable(feature = "thread_local_state", - reason = "state querying was recently added", - issue = "27716")] +#[stable(feature = "thread_local_try_with", since = "1.26.0")] impl fmt::Display for AccessError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt("already destroyed", f) @@ -341,6 +336,8 @@ impl LocalKey { #[unstable(feature = "thread_local_state", reason = "state querying was recently added", issue = "27716")] + #[rustc_deprecated(since = "1.26.0", reason = "use `LocalKey::try_with` instead")] + #[allow(deprecated)] pub fn state(&'static self) -> LocalKeyState { unsafe { match (self.inner)() { @@ -365,11 +362,11 @@ impl LocalKey { /// /// This function will still `panic!()` if the key is uninitialized and the /// key's initializer panics. - #[unstable(feature = "thread_local_state", - reason = "state querying was recently added", - issue = "27716")] + #[stable(feature = "thread_local_try_with", since = "1.26.0")] pub fn try_with(&'static self, f: F) -> Result - where F: FnOnce(&T) -> R { + where + F: FnOnce(&T) -> R, + { unsafe { let slot = (self.inner)().ok_or(AccessError { _private: (), @@ -530,6 +527,7 @@ pub mod os { mod tests { use sync::mpsc::{channel, Sender}; use cell::{Cell, UnsafeCell}; + #[allow(deprecated)] use super::LocalKeyState; use thread; @@ -565,6 +563,7 @@ mod tests { } #[test] + #[allow(deprecated)] fn states() { struct Foo; impl Drop for Foo { @@ -602,6 +601,7 @@ mod tests { } #[test] + #[allow(deprecated)] fn circular() { struct S1; struct S2; @@ -642,6 +642,7 @@ mod tests { } #[test] + #[allow(deprecated)] fn self_referential() { struct S1; thread_local!(static K1: UnsafeCell> = UnsafeCell::new(None)); @@ -663,6 +664,7 @@ mod tests { // test on macOS. #[test] #[cfg_attr(target_os = "macos", ignore)] + #[allow(deprecated)] fn dtors_in_dtors_in_dtors() { struct S1(Sender<()>); thread_local!(static K1: UnsafeCell> = UnsafeCell::new(None)); diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index ff121e2d7ee..01898679bdc 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -191,7 +191,10 @@ use time::Duration; #[macro_use] mod local; #[stable(feature = "rust1", since = "1.0.0")] -pub use self::local::{LocalKey, LocalKeyState, AccessError}; +pub use self::local::{LocalKey, AccessError}; +#[stable(feature = "rust1", since = "1.0.0")] +#[allow(deprecated)] +pub use self::local::LocalKeyState; // The types used by the thread_local! macro to access TLS keys. Note that there // are two types, the "OS" type and the "fast" type. The OS thread local key -- cgit 1.4.1-3-g733a5