@@ -195,45 +195,6 @@ macro_rules! __thread_local_inner {
195
195
}
196
196
}
197
197
198
- /// Indicator of the state of a thread local storage key.
199
- #[ unstable( feature = "thread_local_state" ,
200
- reason = "state querying was recently added" ,
201
- issue = "27716" ) ]
202
- #[ rustc_deprecated( since = "1.26.0" , reason = "use `LocalKey::try_with` instead" ) ]
203
- #[ derive( Debug , Eq , PartialEq , Copy , Clone ) ]
204
- pub enum LocalKeyState {
205
- /// All keys are in this state whenever a thread starts. Keys will
206
- /// transition to the `Valid` state once the first call to [`with`] happens
207
- /// and the initialization expression succeeds.
208
- ///
209
- /// Keys in the `Uninitialized` state will yield a reference to the closure
210
- /// passed to [`with`] so long as the initialization routine does not panic.
211
- ///
212
- /// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
213
- Uninitialized ,
214
-
215
- /// Once a key has been accessed successfully, it will enter the `Valid`
216
- /// state. Keys in the `Valid` state will remain so until the thread exits,
217
- /// at which point the destructor will be run and the key will enter the
218
- /// `Destroyed` state.
219
- ///
220
- /// Keys in the `Valid` state will be guaranteed to yield a reference to the
221
- /// closure passed to [`with`].
222
- ///
223
- /// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
224
- Valid ,
225
-
226
- /// When a thread exits, the destructors for keys will be run (if
227
- /// necessary). While a destructor is running, and possibly after a
228
- /// destructor has run, a key is in the `Destroyed` state.
229
- ///
230
- /// Keys in the `Destroyed` states will trigger a panic when accessed via
231
- /// [`with`].
232
- ///
233
- /// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
234
- Destroyed ,
235
- }
236
-
237
198
/// An error returned by [`LocalKey::try_with`](struct.LocalKey.html#method.try_with).
238
199
#[ stable( feature = "thread_local_try_with" , since = "1.26.0" ) ]
239
200
pub struct AccessError {
@@ -307,51 +268,6 @@ impl<T: 'static> LocalKey<T> {
307
268
( * ptr) . as_ref ( ) . unwrap ( )
308
269
}
309
270
310
- /// Query the current state of this key.
311
- ///
312
- /// A key is initially in the `Uninitialized` state whenever a thread
313
- /// starts. It will remain in this state up until the first call to [`with`]
314
- /// within a thread has run the initialization expression successfully.
315
- ///
316
- /// Once the initialization expression succeeds, the key transitions to the
317
- /// `Valid` state which will guarantee that future calls to [`with`] will
318
- /// succeed within the thread. Some keys might skip the `Uninitialized`
319
- /// state altogether and start in the `Valid` state as an optimization
320
- /// (e.g. keys initialized with a constant expression), but no guarantees
321
- /// are made.
322
- ///
323
- /// When a thread exits, each key will be destroyed in turn, and as keys are
324
- /// destroyed they will enter the `Destroyed` state just before the
325
- /// destructor starts to run. Keys may remain in the `Destroyed` state after
326
- /// destruction has completed. Keys without destructors (e.g. with types
327
- /// that are [`Copy`]), may never enter the `Destroyed` state.
328
- ///
329
- /// Keys in the `Uninitialized` state can be accessed so long as the
330
- /// initialization does not panic. Keys in the `Valid` state are guaranteed
331
- /// to be able to be accessed. Keys in the `Destroyed` state will panic on
332
- /// any call to [`with`].
333
- ///
334
- /// [`with`]: ../../std/thread/struct.LocalKey.html#method.with
335
- /// [`Copy`]: ../../std/marker/trait.Copy.html
336
- #[ unstable( feature = "thread_local_state" ,
337
- reason = "state querying was recently added" ,
338
- issue = "27716" ) ]
339
- #[ rustc_deprecated( since = "1.26.0" , reason = "use `LocalKey::try_with` instead" ) ]
340
- #[ allow( deprecated) ]
341
- pub fn state ( & ' static self ) -> LocalKeyState {
342
- unsafe {
343
- match ( self . inner ) ( ) {
344
- Some ( cell) => {
345
- match * cell. get ( ) {
346
- Some ( ..) => LocalKeyState :: Valid ,
347
- None => LocalKeyState :: Uninitialized ,
348
- }
349
- }
350
- None => LocalKeyState :: Destroyed ,
351
- }
352
- }
353
- }
354
-
355
271
/// Acquires a reference to the value in this TLS key.
356
272
///
357
273
/// This will lazily initialize the value if this thread has not referenced
@@ -527,8 +443,6 @@ pub mod os {
527
443
mod tests {
528
444
use sync:: mpsc:: { channel, Sender } ;
529
445
use cell:: { Cell , UnsafeCell } ;
530
- #[ allow( deprecated) ]
531
- use super :: LocalKeyState ;
532
446
use thread;
533
447
534
448
struct Foo ( Sender < ( ) > ) ;
@@ -563,26 +477,21 @@ mod tests {
563
477
}
564
478
565
479
#[ test]
566
- #[ allow( deprecated) ]
567
480
fn states ( ) {
568
481
struct Foo ;
569
482
impl Drop for Foo {
570
483
fn drop ( & mut self ) {
571
- assert ! ( FOO . state ( ) == LocalKeyState :: Destroyed ) ;
484
+ assert ! ( FOO . try_with ( |_| ( ) ) . is_err ( ) ) ;
572
485
}
573
486
}
574
487
fn foo ( ) -> Foo {
575
- assert ! ( FOO . state ( ) == LocalKeyState :: Uninitialized ) ;
488
+ assert ! ( FOO . try_with ( |_| ( ) ) . is_err ( ) ) ;
576
489
Foo
577
490
}
578
491
thread_local ! ( static FOO : Foo = foo( ) ) ;
579
492
580
493
thread:: spawn ( || {
581
- assert ! ( FOO . state( ) == LocalKeyState :: Uninitialized ) ;
582
- FOO . with ( |_| {
583
- assert ! ( FOO . state( ) == LocalKeyState :: Valid ) ;
584
- } ) ;
585
- assert ! ( FOO . state( ) == LocalKeyState :: Valid ) ;
494
+ assert ! ( FOO . try_with( |_| ( ) ) . is_ok( ) ) ;
586
495
} ) . join ( ) . ok ( ) . unwrap ( ) ;
587
496
}
588
497
@@ -601,7 +510,6 @@ mod tests {
601
510
}
602
511
603
512
#[ test]
604
- #[ allow( deprecated) ]
605
513
fn circular ( ) {
606
514
struct S1 ;
607
515
struct S2 ;
@@ -612,8 +520,7 @@ mod tests {
612
520
impl Drop for S1 {
613
521
fn drop ( & mut self ) {
614
522
unsafe {
615
- HITS += 1 ;
616
- if K2 . state ( ) == LocalKeyState :: Destroyed {
523
+ if K2 . try_with ( |_| ( ) ) . is_err ( ) {
617
524
assert_eq ! ( HITS , 3 ) ;
618
525
} else {
619
526
if HITS == 1 {
@@ -629,7 +536,7 @@ mod tests {
629
536
fn drop ( & mut self ) {
630
537
unsafe {
631
538
HITS += 1 ;
632
- assert ! ( K1 . state ( ) != LocalKeyState :: Destroyed ) ;
539
+ assert ! ( K1 . try_with ( |_| ( ) ) . is_ok ( ) ) ;
633
540
assert_eq ! ( HITS , 2 ) ;
634
541
K1 . with ( |s| * s. get ( ) = Some ( S1 ) ) ;
635
542
}
@@ -642,14 +549,13 @@ mod tests {
642
549
}
643
550
644
551
#[ test]
645
- #[ allow( deprecated) ]
646
552
fn self_referential ( ) {
647
553
struct S1 ;
648
554
thread_local ! ( static K1 : UnsafeCell <Option <S1 >> = UnsafeCell :: new( None ) ) ;
649
555
650
556
impl Drop for S1 {
651
557
fn drop ( & mut self ) {
652
- assert ! ( K1 . state ( ) == LocalKeyState :: Destroyed ) ;
558
+ assert ! ( K1 . try_with ( |_| ( ) ) . is_err ( ) ) ;
653
559
}
654
560
}
655
561
@@ -664,7 +570,6 @@ mod tests {
664
570
// test on macOS.
665
571
#[ test]
666
572
#[ cfg_attr( target_os = "macos" , ignore) ]
667
- #[ allow( deprecated) ]
668
573
fn dtors_in_dtors_in_dtors ( ) {
669
574
struct S1 ( Sender < ( ) > ) ;
670
575
thread_local ! ( static K1 : UnsafeCell <Option <S1 >> = UnsafeCell :: new( None ) ) ;
@@ -674,9 +579,7 @@ mod tests {
674
579
fn drop ( & mut self ) {
675
580
let S1 ( ref tx) = * self ;
676
581
unsafe {
677
- if K2 . state ( ) != LocalKeyState :: Destroyed {
678
- K2 . with ( |s| * s. get ( ) = Some ( Foo ( tx. clone ( ) ) ) ) ;
679
- }
582
+ let _ = K2 . try_with ( |s| * s. get ( ) = Some ( Foo ( tx. clone ( ) ) ) ) ;
680
583
}
681
584
}
682
585
}
0 commit comments