Skip to content

Commit ab7ef74

Browse files
committed
Use #[allow_internal_unstable] for thread_local!
This destabilises all the implementation details of `thread_local!`, since they do not *need* to be stable with the new attribute.
1 parent 84b060c commit ab7ef74

File tree

5 files changed

+39
-15
lines changed

5 files changed

+39
-15
lines changed

src/libstd/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
#![feature(hash)]
126126
#![feature(int_uint)]
127127
#![feature(unique)]
128+
#![feature(allow_internal_unstable)]
128129
#![cfg_attr(test, feature(test, rustc_private))]
129130

130131
// Don't link to std. We are std.

src/libstd/sys/common/thread_local.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
//! ```
5656
5757
#![allow(non_camel_case_types)]
58+
#![unstable(feature = "thread_local_internals")]
5859

5960
use prelude::v1::*;
6061

@@ -84,17 +85,14 @@ use sys::thread_local as imp;
8485
/// KEY.set(1 as *mut u8);
8586
/// }
8687
/// ```
87-
#[stable(feature = "rust1", since = "1.0.0")]
8888
pub struct StaticKey {
8989
/// Inner static TLS key (internals), created with by `INIT_INNER` in this
9090
/// module.
91-
#[stable(feature = "rust1", since = "1.0.0")]
9291
pub inner: StaticKeyInner,
9392
/// Destructor for the TLS value.
9493
///
9594
/// See `Key::new` for information about when the destructor runs and how
9695
/// it runs.
97-
#[stable(feature = "rust1", since = "1.0.0")]
9896
pub dtor: Option<unsafe extern fn(*mut u8)>,
9997
}
10098

@@ -131,7 +129,6 @@ pub struct Key {
131129
/// Constant initialization value for static TLS keys.
132130
///
133131
/// This value specifies no destructor by default.
134-
#[stable(feature = "rust1", since = "1.0.0")]
135132
pub const INIT: StaticKey = StaticKey {
136133
inner: INIT_INNER,
137134
dtor: None,
@@ -140,7 +137,6 @@ pub const INIT: StaticKey = StaticKey {
140137
/// Constant initialization value for the inner part of static TLS keys.
141138
///
142139
/// This value allows specific configuration of the destructor for a TLS key.
143-
#[stable(feature = "rust1", since = "1.0.0")]
144140
pub const INIT_INNER: StaticKeyInner = StaticKeyInner {
145141
key: atomic::ATOMIC_USIZE_INIT,
146142
};

src/libstd/thread_local/mod.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub mod scoped;
4545

4646
// Sure wish we had macro hygiene, no?
4747
#[doc(hidden)]
48-
#[stable(feature = "rust1", since = "1.0.0")]
48+
#[unstable(feature = "thread_local_internals")]
4949
pub mod __impl {
5050
pub use super::imp::Key as KeyInner;
5151
pub use super::imp::destroy_value;
@@ -117,6 +117,7 @@ pub struct Key<T> {
117117
/// Declare a new thread local storage key of type `std::thread_local::Key`.
118118
#[macro_export]
119119
#[stable(feature = "rust1", since = "1.0.0")]
120+
#[allow_internal_unstable]
120121
macro_rules! thread_local {
121122
(static $name:ident: $t:ty = $init:expr) => (
122123
static $name: ::std::thread_local::Key<$t> = {
@@ -176,6 +177,7 @@ macro_rules! thread_local {
176177

177178
#[macro_export]
178179
#[doc(hidden)]
180+
#[allow_internal_unstable]
179181
macro_rules! __thread_local_inner {
180182
(static $name:ident: $t:ty = $init:expr) => (
181183
#[cfg_attr(all(any(target_os = "macos", target_os = "linux"),
@@ -337,22 +339,22 @@ mod imp {
337339
use ptr;
338340

339341
#[doc(hidden)]
340-
#[stable(since = "1.0.0", feature = "rust1")]
342+
#[unstable(feature = "thread_local_internals")]
341343
pub struct Key<T> {
342344
// Place the inner bits in an `UnsafeCell` to currently get around the
343345
// "only Sync statics" restriction. This allows any type to be placed in
344346
// the cell.
345347
//
346348
// Note that all access requires `T: 'static` so it can't be a type with
347349
// any borrowed pointers still.
348-
#[stable(since = "1.0.0", feature = "rust1")]
350+
#[unstable(feature = "thread_local_internals")]
349351
pub inner: UnsafeCell<T>,
350352

351353
// Metadata to keep track of the state of the destructor. Remember that
352354
// these variables are thread-local, not global.
353-
#[stable(since = "1.0.0", feature = "rust1")]
355+
#[unstable(feature = "thread_local_internals")]
354356
pub dtor_registered: UnsafeCell<bool>, // should be Cell
355-
#[stable(since = "1.0.0", feature = "rust1")]
357+
#[unstable(feature = "thread_local_internals")]
356358
pub dtor_running: UnsafeCell<bool>, // should be Cell
357359
}
358360

@@ -455,7 +457,7 @@ mod imp {
455457
}
456458

457459
#[doc(hidden)]
458-
#[stable(feature = "rust1", since = "1.0.0")]
460+
#[unstable(feature = "thread_local_internals")]
459461
pub unsafe extern fn destroy_value<T>(ptr: *mut u8) {
460462
let ptr = ptr as *mut Key<T>;
461463
// Right before we run the user destructor be sure to flag the
@@ -477,15 +479,15 @@ mod imp {
477479
use sys_common::thread_local::StaticKey as OsStaticKey;
478480

479481
#[doc(hidden)]
480-
#[stable(since = "1.0.0", feature = "rust1")]
482+
#[unstable(feature = "thread_local_internals")]
481483
pub struct Key<T> {
482484
// Statically allocated initialization expression, using an `UnsafeCell`
483485
// for the same reasons as above.
484-
#[stable(since = "1.0.0", feature = "rust1")]
486+
#[unstable(feature = "thread_local_internals")]
485487
pub inner: UnsafeCell<T>,
486488

487489
// OS-TLS key that we'll use to key off.
488-
#[stable(since = "1.0.0", feature = "rust1")]
490+
#[unstable(feature = "thread_local_internals")]
489491
pub os: OsStaticKey,
490492
}
491493

@@ -528,7 +530,7 @@ mod imp {
528530
}
529531

530532
#[doc(hidden)]
531-
#[stable(feature = "rust1", since = "1.0.0")]
533+
#[unstable(feature = "thread_local_internals")]
532534
pub unsafe extern fn destroy_value<T: 'static>(ptr: *mut u8) {
533535
// The OS TLS ensures that this key contains a NULL value when this
534536
// destructor starts to run. We set it back to a sentinel value of 1 to

src/libstd/thread_local/scoped.rs

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pub struct Key<T> { #[doc(hidden)] pub inner: __impl::KeyInner<T> }
6565
/// This macro declares a `static` item on which methods are used to get and
6666
/// set the value stored within.
6767
#[macro_export]
68+
#[allow_internal_unstable]
6869
macro_rules! scoped_thread_local {
6970
(static $name:ident: $t:ty) => (
7071
__scoped_thread_local_inner!(static $name: $t);
@@ -76,6 +77,7 @@ macro_rules! scoped_thread_local {
7677

7778
#[macro_export]
7879
#[doc(hidden)]
80+
#[allow_internal_unstable]
7981
macro_rules! __scoped_thread_local_inner {
8082
(static $name:ident: $t:ty) => (
8183
#[cfg_attr(not(any(windows,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:internal_unstable.rs
12+
13+
#![feature(rustc_attrs)]
14+
#![allow(dead_code)]
15+
16+
extern crate internal_unstable;
17+
18+
19+
thread_local!(static FOO: () = ());
20+
thread_local!(static BAR: () = internal_unstable::unstable()); //~ WARN use of unstable
21+
22+
#[rustc_error]
23+
fn main() {} //~ ERROR

0 commit comments

Comments
 (0)