Skip to content

Commit c99f4c4

Browse files
author
Stjepan Glavina
committed
Stabilize LocalKey::try_with
1 parent 29f5c69 commit c99f4c4

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

src/libstd/io/stdio.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ use io::{self, Initializer, BufReader, LineWriter};
1717
use sync::{Arc, Mutex, MutexGuard};
1818
use sys::stdio;
1919
use sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard};
20-
use thread::{LocalKey, LocalKeyState};
20+
use thread::LocalKey;
21+
#[allow(deprecated)]
22+
use thread::LocalKeyState;
2123

2224
/// Stdout used by print! and println! macros
2325
thread_local! {
@@ -668,6 +670,7 @@ pub fn set_print(sink: Option<Box<Write + Send>>) -> Option<Box<Write + Send>> {
668670
/// thread, it will just fall back to the global stream.
669671
///
670672
/// However, if the actual I/O causes an error, this function does panic.
673+
#[allow(deprecated)]
671674
fn print_to<T>(args: fmt::Arguments,
672675
local_s: &'static LocalKey<RefCell<Option<Box<Write+Send>>>>,
673676
global_s: fn() -> T,

src/libstd/thread/local.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ macro_rules! __thread_local_inner {
199199
#[unstable(feature = "thread_local_state",
200200
reason = "state querying was recently added",
201201
issue = "27716")]
202+
#[rustc_deprecated(since = "1.26.0", reason = "use `LocalKey::try_with` instead")]
202203
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
203204
pub enum LocalKeyState {
204205
/// All keys are in this state whenever a thread starts. Keys will
@@ -234,25 +235,19 @@ pub enum LocalKeyState {
234235
}
235236

236237
/// An error returned by [`LocalKey::try_with`](struct.LocalKey.html#method.try_with).
237-
#[unstable(feature = "thread_local_state",
238-
reason = "state querying was recently added",
239-
issue = "27716")]
238+
#[stable(feature = "thread_local_try_with", since = "1.26.0")]
240239
pub struct AccessError {
241240
_private: (),
242241
}
243242

244-
#[unstable(feature = "thread_local_state",
245-
reason = "state querying was recently added",
246-
issue = "27716")]
243+
#[stable(feature = "thread_local_try_with", since = "1.26.0")]
247244
impl fmt::Debug for AccessError {
248245
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
249246
f.debug_struct("AccessError").finish()
250247
}
251248
}
252249

253-
#[unstable(feature = "thread_local_state",
254-
reason = "state querying was recently added",
255-
issue = "27716")]
250+
#[stable(feature = "thread_local_try_with", since = "1.26.0")]
256251
impl fmt::Display for AccessError {
257252
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
258253
fmt::Display::fmt("already destroyed", f)
@@ -341,6 +336,8 @@ impl<T: 'static> LocalKey<T> {
341336
#[unstable(feature = "thread_local_state",
342337
reason = "state querying was recently added",
343338
issue = "27716")]
339+
#[rustc_deprecated(since = "1.26.0", reason = "use `LocalKey::try_with` instead")]
340+
#[allow(deprecated)]
344341
pub fn state(&'static self) -> LocalKeyState {
345342
unsafe {
346343
match (self.inner)() {
@@ -365,11 +362,11 @@ impl<T: 'static> LocalKey<T> {
365362
///
366363
/// This function will still `panic!()` if the key is uninitialized and the
367364
/// key's initializer panics.
368-
#[unstable(feature = "thread_local_state",
369-
reason = "state querying was recently added",
370-
issue = "27716")]
365+
#[stable(feature = "thread_local_try_with", since = "1.26.0")]
371366
pub fn try_with<F, R>(&'static self, f: F) -> Result<R, AccessError>
372-
where F: FnOnce(&T) -> R {
367+
where
368+
F: FnOnce(&T) -> R,
369+
{
373370
unsafe {
374371
let slot = (self.inner)().ok_or(AccessError {
375372
_private: (),
@@ -530,6 +527,7 @@ pub mod os {
530527
mod tests {
531528
use sync::mpsc::{channel, Sender};
532529
use cell::{Cell, UnsafeCell};
530+
#[allow(deprecated)]
533531
use super::LocalKeyState;
534532
use thread;
535533

@@ -565,6 +563,7 @@ mod tests {
565563
}
566564

567565
#[test]
566+
#[allow(deprecated)]
568567
fn states() {
569568
struct Foo;
570569
impl Drop for Foo {
@@ -602,6 +601,7 @@ mod tests {
602601
}
603602

604603
#[test]
604+
#[allow(deprecated)]
605605
fn circular() {
606606
struct S1;
607607
struct S2;
@@ -642,6 +642,7 @@ mod tests {
642642
}
643643

644644
#[test]
645+
#[allow(deprecated)]
645646
fn self_referential() {
646647
struct S1;
647648
thread_local!(static K1: UnsafeCell<Option<S1>> = UnsafeCell::new(None));
@@ -663,6 +664,7 @@ mod tests {
663664
// test on macOS.
664665
#[test]
665666
#[cfg_attr(target_os = "macos", ignore)]
667+
#[allow(deprecated)]
666668
fn dtors_in_dtors_in_dtors() {
667669
struct S1(Sender<()>);
668670
thread_local!(static K1: UnsafeCell<Option<S1>> = UnsafeCell::new(None));

src/libstd/thread/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,10 @@ use time::Duration;
191191
#[macro_use] mod local;
192192

193193
#[stable(feature = "rust1", since = "1.0.0")]
194-
pub use self::local::{LocalKey, LocalKeyState, AccessError};
194+
pub use self::local::{LocalKey, AccessError};
195+
#[stable(feature = "rust1", since = "1.0.0")]
196+
#[allow(deprecated)]
197+
pub use self::local::LocalKeyState;
195198

196199
// The types used by the thread_local! macro to access TLS keys. Note that there
197200
// are two types, the "OS" type and the "fast" type. The OS thread local key

src/test/run-pass/tls-init-on-init.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// ignore-emscripten no threads support
1212

1313
#![feature(thread_local_state)]
14+
#![allow(deprecated)]
1415

1516
use std::thread::{self, LocalKeyState};
1617
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};

0 commit comments

Comments
 (0)