diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 831688bb73d..f01ca18851d 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -17,7 +17,9 @@ use io::{self, Initializer, BufReader, LineWriter}; use sync::{Arc, Mutex, MutexGuard}; use sys::stdio; use sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard}; -use thread::{LocalKey, LocalKeyState}; +use thread::LocalKey; +#[allow(deprecated)] +use thread::LocalKeyState; /// Stdout used by print! and println! macros thread_local! { @@ -668,6 +670,7 @@ pub fn set_print(sink: Option>) -> Option> { /// thread, it will just fall back to the global stream. /// /// However, if the actual I/O causes an error, this function does panic. +#[allow(deprecated)] fn print_to(args: fmt::Arguments, local_s: &'static LocalKey>>>, global_s: fn() -> T, 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 diff --git a/src/test/run-pass/tls-init-on-init.rs b/src/test/run-pass/tls-init-on-init.rs index b44c535d3a4..b5b9fb561ae 100644 --- a/src/test/run-pass/tls-init-on-init.rs +++ b/src/test/run-pass/tls-init-on-init.rs @@ -11,6 +11,7 @@ // ignore-emscripten no threads support #![feature(thread_local_state)] +#![allow(deprecated)] use std::thread::{self, LocalKeyState}; use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};