@@ -199,6 +199,7 @@ macro_rules! __thread_local_inner {
199
199
#[ unstable( feature = "thread_local_state" ,
200
200
reason = "state querying was recently added" ,
201
201
issue = "27716" ) ]
202
+ #[ rustc_deprecated( since = "1.26.0" , reason = "use `LocalKey::try_with` instead" ) ]
202
203
#[ derive( Debug , Eq , PartialEq , Copy , Clone ) ]
203
204
pub enum LocalKeyState {
204
205
/// All keys are in this state whenever a thread starts. Keys will
@@ -234,25 +235,19 @@ pub enum LocalKeyState {
234
235
}
235
236
236
237
/// 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" ) ]
240
239
pub struct AccessError {
241
240
_private : ( ) ,
242
241
}
243
242
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" ) ]
247
244
impl fmt:: Debug for AccessError {
248
245
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
249
246
f. debug_struct ( "AccessError" ) . finish ( )
250
247
}
251
248
}
252
249
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" ) ]
256
251
impl fmt:: Display for AccessError {
257
252
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
258
253
fmt:: Display :: fmt ( "already destroyed" , f)
@@ -341,6 +336,8 @@ impl<T: 'static> LocalKey<T> {
341
336
#[ unstable( feature = "thread_local_state" ,
342
337
reason = "state querying was recently added" ,
343
338
issue = "27716" ) ]
339
+ #[ rustc_deprecated( since = "1.26.0" , reason = "use `LocalKey::try_with` instead" ) ]
340
+ #[ allow( deprecated) ]
344
341
pub fn state ( & ' static self ) -> LocalKeyState {
345
342
unsafe {
346
343
match ( self . inner ) ( ) {
@@ -365,11 +362,11 @@ impl<T: 'static> LocalKey<T> {
365
362
///
366
363
/// This function will still `panic!()` if the key is uninitialized and the
367
364
/// 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" ) ]
371
366
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
+ {
373
370
unsafe {
374
371
let slot = ( self . inner ) ( ) . ok_or ( AccessError {
375
372
_private : ( ) ,
@@ -530,6 +527,7 @@ pub mod os {
530
527
mod tests {
531
528
use sync:: mpsc:: { channel, Sender } ;
532
529
use cell:: { Cell , UnsafeCell } ;
530
+ #[ allow( deprecated) ]
533
531
use super :: LocalKeyState ;
534
532
use thread;
535
533
@@ -565,6 +563,7 @@ mod tests {
565
563
}
566
564
567
565
#[ test]
566
+ #[ allow( deprecated) ]
568
567
fn states ( ) {
569
568
struct Foo ;
570
569
impl Drop for Foo {
@@ -602,6 +601,7 @@ mod tests {
602
601
}
603
602
604
603
#[ test]
604
+ #[ allow( deprecated) ]
605
605
fn circular ( ) {
606
606
struct S1 ;
607
607
struct S2 ;
@@ -642,6 +642,7 @@ mod tests {
642
642
}
643
643
644
644
#[ test]
645
+ #[ allow( deprecated) ]
645
646
fn self_referential ( ) {
646
647
struct S1 ;
647
648
thread_local ! ( static K1 : UnsafeCell <Option <S1 >> = UnsafeCell :: new( None ) ) ;
@@ -663,6 +664,7 @@ mod tests {
663
664
// test on macOS.
664
665
#[ test]
665
666
#[ cfg_attr( target_os = "macos" , ignore) ]
667
+ #[ allow( deprecated) ]
666
668
fn dtors_in_dtors_in_dtors ( ) {
667
669
struct S1 ( Sender < ( ) > ) ;
668
670
thread_local ! ( static K1 : UnsafeCell <Option <S1 >> = UnsafeCell :: new( None ) ) ;
0 commit comments