Skip to content

Commit a5e15f9

Browse files
committed
std: Clean up some annotations in thread::local
Don't need so much manual #[doc(hidden)] and #[unstable] as much of it is inherited!
1 parent a691f1e commit a5e15f9

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

src/libstd/thread/local.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use cell::UnsafeCell;
1818

1919
// Sure wish we had macro hygiene, no?
2020
#[doc(hidden)]
21-
#[unstable(feature = "thread_local_internals")]
2221
pub mod __impl {
2322
pub use super::imp::Key as KeyInner;
2423
pub use super::imp::destroy_value;
@@ -78,12 +77,10 @@ pub struct LocalKey<T> {
7877
// This is trivially devirtualizable by LLVM because we never store anything
7978
// to this field and rustc can declare the `static` as constant as well.
8079
#[doc(hidden)]
81-
#[unstable(feature = "thread_local_internals")]
8280
pub inner: fn() -> &'static __impl::KeyInner<UnsafeCell<Option<T>>>,
8381

8482
// initialization routine to invoke to create a value
8583
#[doc(hidden)]
86-
#[unstable(feature = "thread_local_internals")]
8784
pub init: fn() -> T,
8885
}
8986

@@ -297,36 +294,31 @@ impl<T: 'static> LocalKey<T> {
297294
}
298295

299296
#[cfg(all(any(target_os = "macos", target_os = "linux"), not(target_arch = "aarch64")))]
297+
#[doc(hidden)]
300298
mod imp {
301299
use prelude::v1::*;
302300

303301
use cell::UnsafeCell;
304302
use intrinsics;
305303
use ptr;
306304

307-
#[doc(hidden)]
308-
#[unstable(feature = "thread_local_internals")]
309305
pub struct Key<T> {
310306
// Place the inner bits in an `UnsafeCell` to currently get around the
311307
// "only Sync statics" restriction. This allows any type to be placed in
312308
// the cell.
313309
//
314310
// Note that all access requires `T: 'static` so it can't be a type with
315311
// any borrowed pointers still.
316-
#[unstable(feature = "thread_local_internals")]
317312
pub inner: UnsafeCell<T>,
318313

319314
// Metadata to keep track of the state of the destructor. Remember that
320315
// these variables are thread-local, not global.
321-
#[unstable(feature = "thread_local_internals")]
322316
pub dtor_registered: UnsafeCell<bool>, // should be Cell
323-
#[unstable(feature = "thread_local_internals")]
324317
pub dtor_running: UnsafeCell<bool>, // should be Cell
325318
}
326319

327320
unsafe impl<T> ::marker::Sync for Key<T> { }
328321

329-
#[doc(hidden)]
330322
impl<T> Key<T> {
331323
pub unsafe fn get(&'static self) -> Option<&'static T> {
332324
if intrinsics::needs_drop::<T>() && *self.dtor_running.get() {
@@ -422,8 +414,6 @@ mod imp {
422414
_tlv_atexit(dtor, t);
423415
}
424416

425-
#[doc(hidden)]
426-
#[unstable(feature = "thread_local_internals")]
427417
pub unsafe extern fn destroy_value<T>(ptr: *mut u8) {
428418
let ptr = ptr as *mut Key<T>;
429419
// Right before we run the user destructor be sure to flag the
@@ -435,6 +425,7 @@ mod imp {
435425
}
436426

437427
#[cfg(any(not(any(target_os = "macos", target_os = "linux")), target_arch = "aarch64"))]
428+
#[doc(hidden)]
438429
mod imp {
439430
use prelude::v1::*;
440431

@@ -444,16 +435,12 @@ mod imp {
444435
use ptr;
445436
use sys_common::thread_local::StaticKey as OsStaticKey;
446437

447-
#[doc(hidden)]
448-
#[unstable(feature = "thread_local_internals")]
449438
pub struct Key<T> {
450439
// Statically allocated initialization expression, using an `UnsafeCell`
451440
// for the same reasons as above.
452-
#[unstable(feature = "thread_local_internals")]
453441
pub inner: UnsafeCell<T>,
454442

455443
// OS-TLS key that we'll use to key off.
456-
#[unstable(feature = "thread_local_internals")]
457444
pub os: OsStaticKey,
458445
}
459446

@@ -464,7 +451,6 @@ mod imp {
464451
value: T,
465452
}
466453

467-
#[doc(hidden)]
468454
impl<T> Key<T> {
469455
pub unsafe fn get(&'static self) -> Option<&'static T> {
470456
self.ptr().map(|p| &*p)
@@ -489,14 +475,12 @@ mod imp {
489475
key: self,
490476
value: mem::transmute_copy(&self.inner),
491477
};
492-
let ptr: *mut Value<T> = boxed::into_raw(ptr);
478+
let ptr = boxed::into_raw(ptr);
493479
self.os.set(ptr as *mut u8);
494480
Some(&mut (*ptr).value as *mut T)
495481
}
496482
}
497483

498-
#[doc(hidden)]
499-
#[unstable(feature = "thread_local_internals")]
500484
pub unsafe extern fn destroy_value<T: 'static>(ptr: *mut u8) {
501485
// The OS TLS ensures that this key contains a NULL value when this
502486
// destructor starts to run. We set it back to a sentinel value of 1 to
@@ -505,7 +489,7 @@ mod imp {
505489
//
506490
// Note that to prevent an infinite loop we reset it back to null right
507491
// before we return from the destructor ourselves.
508-
let ptr: Box<Value<T>> = Box::from_raw(ptr as *mut Value<T>);
492+
let ptr = Box::from_raw(ptr as *mut Value<T>);
509493
let key = ptr.key;
510494
key.os.set(1 as *mut u8);
511495
drop(ptr);

0 commit comments

Comments
 (0)