Skip to content

Commit e6e544f

Browse files
committed
auto merge of #15936 : alexcrichton/rust/stability, r=brson
This commit applies stability attributes to the contents of these modules, summarized here: * The `unit` and `bool` modules have become #[unstable] as they are purely meant for documentation purposes and are candidates for removal. * The `ty` module has been deprecated, and the inner `Unsafe` type has been renamed to `UnsafeCell` and moved to the `cell` module. The `marker1` field has been removed as the compiler now always infers `UnsafeCell` to be invariant. The `new` method i stable, but the `value` field, `get` and `unwrap` methods are all unstable. * The `tuple` module has its name as stable, the naming of the `TupleN` traits as stable while the methods are all #[unstable]. The other impls in the module have appropriate stability for the corresponding trait. * The `arc` module has received the exact same treatment as the `rc` module previously did. * The `any` module has its name as stable. The `Any` trait is also stable, with a new private supertrait which now contains the `get_type_id` method. This is to make the method a private implementation detail rather than a public-facing detail. The two extension traits in the module are marked #[unstable] as they will not be necessary with DST. The `is` method is #[stable], the as_{mut,ref} methods have been renamed to downcast_{mut,ref} and are #[unstable]. The extension trait `BoxAny` has been clarified as to why it is unstable as it will not be necessary with DST. This is a breaking change because the `marker1` field was removed from the `UnsafeCell` type. To deal with this change, you can simply delete the field and only specify the value of the `data` field in static initializers. [breaking-change]
2 parents ecce58c + e5da6a7 commit e6e544f

31 files changed

+310
-325
lines changed

src/liballoc/arc.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
/*!
12-
* Concurrency-enabled mechanisms for sharing mutable and/or immutable state
13-
* between tasks.
14-
*/
11+
#![stable]
12+
13+
//! Concurrency-enabled mechanisms for sharing mutable and/or immutable state
14+
//! between tasks.
1515
1616
use core::atomics;
1717
use core::clone::Clone;
@@ -51,6 +51,7 @@ use heap::deallocate;
5151
/// }
5252
/// ```
5353
#[unsafe_no_drop_flag]
54+
#[stable]
5455
pub struct Arc<T> {
5556
// FIXME #12808: strange name to try to avoid interfering with
5657
// field accesses of the contained type via Deref
@@ -62,6 +63,7 @@ pub struct Arc<T> {
6263
/// Weak pointers will not keep the data inside of the `Arc` alive, and can be
6364
/// used to break cycles between `Arc` pointers.
6465
#[unsafe_no_drop_flag]
66+
#[experimental = "Weak pointers may not belong in this module."]
6567
pub struct Weak<T> {
6668
// FIXME #12808: strange name to try to avoid interfering with
6769
// field accesses of the contained type via Deref
@@ -77,6 +79,7 @@ struct ArcInner<T> {
7779
impl<T: Share + Send> Arc<T> {
7880
/// Create an atomically reference counted wrapper.
7981
#[inline]
82+
#[stable]
8083
pub fn new(data: T) -> Arc<T> {
8184
// Start the weak pointer count as 1 which is the weak pointer that's
8285
// held by all the strong pointers (kinda), see std/rc.rs for more info
@@ -103,14 +106,15 @@ impl<T: Share + Send> Arc<T> {
103106
/// Weak pointers will not keep the data alive. Once all strong references
104107
/// to the underlying data have been dropped, the data itself will be
105108
/// destroyed.
109+
#[experimental = "Weak pointers may not belong in this module."]
106110
pub fn downgrade(&self) -> Weak<T> {
107111
// See the clone() impl for why this is relaxed
108112
self.inner().weak.fetch_add(1, atomics::Relaxed);
109113
Weak { _ptr: self._ptr }
110114
}
111115
}
112116

113-
#[unstable]
117+
#[unstable = "waiting on stability of Clone"]
114118
impl<T: Share + Send> Clone for Arc<T> {
115119
/// Duplicate an atomically reference counted wrapper.
116120
///
@@ -135,6 +139,7 @@ impl<T: Share + Send> Clone for Arc<T> {
135139
}
136140
}
137141

142+
#[experimental = "Deref is experimental."]
138143
impl<T: Send + Share> Deref<T> for Arc<T> {
139144
#[inline]
140145
fn deref<'a>(&'a self) -> &'a T {
@@ -169,6 +174,7 @@ impl<T: Send + Share + Clone> Arc<T> {
169174
}
170175

171176
#[unsafe_destructor]
177+
#[experimental = "waiting on stability of Drop"]
172178
impl<T: Share + Send> Drop for Arc<T> {
173179
fn drop(&mut self) {
174180
// This structure has #[unsafe_no_drop_flag], so this drop glue may run
@@ -212,6 +218,7 @@ impl<T: Share + Send> Drop for Arc<T> {
212218
}
213219
}
214220

221+
#[experimental = "Weak pointers may not belong in this module."]
215222
impl<T: Share + Send> Weak<T> {
216223
/// Attempts to upgrade this weak reference to a strong reference.
217224
///
@@ -237,7 +244,7 @@ impl<T: Share + Send> Weak<T> {
237244
}
238245
}
239246

240-
#[unstable]
247+
#[experimental = "Weak pointers may not belong in this module."]
241248
impl<T: Share + Send> Clone for Weak<T> {
242249
#[inline]
243250
fn clone(&self) -> Weak<T> {
@@ -248,6 +255,7 @@ impl<T: Share + Send> Clone for Weak<T> {
248255
}
249256

250257
#[unsafe_destructor]
258+
#[experimental = "Weak pointers may not belong in this module."]
251259
impl<T: Share + Send> Drop for Weak<T> {
252260
fn drop(&mut self) {
253261
// see comments above for why this check is here

src/liballoc/boxed.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,12 @@ impl<T: Ord> Ord for Box<T> {
8787
impl<T: Eq> Eq for Box<T> {}
8888

8989
/// Extension methods for an owning `Any` trait object
90-
#[unstable = "post-DST, the signature of `downcast` will change to take `Box<Self>`"]
90+
#[unstable = "post-DST and coherence changes, this will not be a trait but \
91+
rather a direct `impl` on `Box<Any>`"]
9192
pub trait BoxAny {
9293
/// Returns the boxed value if it is of type `T`, or
9394
/// `Err(Self)` if it isn't.
95+
#[unstable = "naming conventions around accessing innards may change"]
9496
fn downcast<T: 'static>(self) -> Result<Box<T>, Self>;
9597

9698
/// Deprecated; this method has been renamed to `downcast`.
@@ -100,6 +102,7 @@ pub trait BoxAny {
100102
}
101103
}
102104

105+
#[stable]
103106
impl BoxAny for Box<Any> {
104107
#[inline]
105108
fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any>> {

src/liballoc/rc.rs

-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ impl<T> Drop for Weak<T> {
379379
}
380380
}
381381

382-
#[unstable]
383382
#[experimental = "Weak pointers may not belong in this module."]
384383
impl<T> Clone for Weak<T> {
385384
#[inline]

src/libcore/any.rs

+48-14
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
//! // try to convert our value to a String. If successful, we want to
4545
//! // output the String's length as well as its value. If not, it's a
4646
//! // different type: just print it out unadorned.
47-
//! match value_any.as_ref::<String>() {
47+
//! match value_any.downcast_ref::<String>() {
4848
//! Some(as_string) => {
4949
//! println!("String ({}): {}", as_string.len(), as_string);
5050
//! }
@@ -69,51 +69,72 @@
6969
//! }
7070
//! ```
7171
72+
#![stable]
73+
7274
use mem::{transmute, transmute_copy};
7375
use option::{Option, Some, None};
7476
use raw::TraitObject;
7577
use intrinsics::TypeId;
7678

7779
/// A type with no inhabitants
80+
#[deprecated = "this type is being removed, define a type locally if \
81+
necessary"]
7882
pub enum Void { }
7983

8084
///////////////////////////////////////////////////////////////////////////////
8185
// Any trait
8286
///////////////////////////////////////////////////////////////////////////////
8387

84-
/// The `Any` trait is implemented by all `'static` types, and can be used for dynamic typing
88+
/// The `Any` trait is implemented by all `'static` types, and can be used for
89+
/// dynamic typing
8590
///
86-
/// Every type with no non-`'static` references implements `Any`, so `Any` can be used as a trait
87-
/// object to emulate the effects dynamic typing.
88-
pub trait Any {
91+
/// Every type with no non-`'static` references implements `Any`, so `Any` can
92+
/// be used as a trait object to emulate the effects dynamic typing.
93+
#[stable]
94+
pub trait Any: AnyPrivate {}
95+
96+
/// An inner trait to ensure that only this module can call `get_type_id()`.
97+
trait AnyPrivate {
8998
/// Get the `TypeId` of `self`
9099
fn get_type_id(&self) -> TypeId;
91100
}
92101

93-
impl<T: 'static> Any for T {
94-
/// Get the `TypeId` of `self`
95-
fn get_type_id(&self) -> TypeId {
96-
TypeId::of::<T>()
97-
}
102+
impl<T: 'static> AnyPrivate for T {
103+
fn get_type_id(&self) -> TypeId { TypeId::of::<T>() }
98104
}
99105

106+
impl<T: 'static + AnyPrivate> Any for T {}
107+
100108
///////////////////////////////////////////////////////////////////////////////
101109
// Extension methods for Any trait objects.
102110
// Implemented as three extension traits so that the methods can be generic.
103111
///////////////////////////////////////////////////////////////////////////////
104112

105113
/// Extension methods for a referenced `Any` trait object
114+
#[unstable = "this trait will not be necessary once DST lands, it will be a \
115+
part of `impl Any`"]
106116
pub trait AnyRefExt<'a> {
107117
/// Returns true if the boxed type is the same as `T`
118+
#[stable]
108119
fn is<T: 'static>(self) -> bool;
109120

110121
/// Returns some reference to the boxed value if it is of type `T`, or
111122
/// `None` if it isn't.
112-
fn as_ref<T: 'static>(self) -> Option<&'a T>;
123+
#[unstable = "naming conventions around acquiring references may change"]
124+
fn downcast_ref<T: 'static>(self) -> Option<&'a T>;
125+
126+
/// Returns some reference to the boxed value if it is of type `T`, or
127+
/// `None` if it isn't.
128+
#[deprecated = "this function has been renamed to `downcast_ref`"]
129+
fn as_ref<T: 'static>(self) -> Option<&'a T> {
130+
self.downcast_ref::<T>()
131+
}
113132
}
114133

134+
#[stable]
115135
impl<'a> AnyRefExt<'a> for &'a Any {
116136
#[inline]
137+
#[stable]
117138
fn is<T: 'static>(self) -> bool {
118139
// Get TypeId of the type this function is instantiated with
119140
let t = TypeId::of::<T>();
@@ -126,7 +147,8 @@ impl<'a> AnyRefExt<'a> for &'a Any {
126147
}
127148

128149
#[inline]
129-
fn as_ref<T: 'static>(self) -> Option<&'a T> {
150+
#[unstable = "naming conventions around acquiring references may change"]
151+
fn downcast_ref<T: 'static>(self) -> Option<&'a T> {
130152
if self.is::<T>() {
131153
unsafe {
132154
// Get the raw representation of the trait object
@@ -142,15 +164,27 @@ impl<'a> AnyRefExt<'a> for &'a Any {
142164
}
143165

144166
/// Extension methods for a mutable referenced `Any` trait object
167+
#[unstable = "this trait will not be necessary once DST lands, it will be a \
168+
part of `impl Any`"]
145169
pub trait AnyMutRefExt<'a> {
146170
/// Returns some mutable reference to the boxed value if it is of type `T`, or
147171
/// `None` if it isn't.
148-
fn as_mut<T: 'static>(self) -> Option<&'a mut T>;
172+
#[unstable = "naming conventions around acquiring references may change"]
173+
fn downcast_mut<T: 'static>(self) -> Option<&'a mut T>;
174+
175+
/// Returns some mutable reference to the boxed value if it is of type `T`, or
176+
/// `None` if it isn't.
177+
#[deprecated = "this function has been renamed to `downcast_mut`"]
178+
fn as_mut<T: 'static>(self) -> Option<&'a mut T> {
179+
self.downcast_mut::<T>()
180+
}
149181
}
150182

183+
#[stable]
151184
impl<'a> AnyMutRefExt<'a> for &'a mut Any {
152185
#[inline]
153-
fn as_mut<T: 'static>(self) -> Option<&'a mut T> {
186+
#[unstable = "naming conventions around acquiring references may change"]
187+
fn downcast_mut<T: 'static>(self) -> Option<&'a mut T> {
154188
if self.is::<T>() {
155189
unsafe {
156190
// Get the raw representation of the trait object

src/libcore/atomics.rs

+15-18
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,29 @@
1212
1313
use intrinsics;
1414
use std::kinds::marker;
15-
use ty::Unsafe;
15+
use cell::UnsafeCell;
1616

1717
/// An atomic boolean type.
1818
pub struct AtomicBool {
19-
v: Unsafe<uint>,
19+
v: UnsafeCell<uint>,
2020
nocopy: marker::NoCopy
2121
}
2222

2323
/// A signed atomic integer type, supporting basic atomic arithmetic operations
2424
pub struct AtomicInt {
25-
v: Unsafe<int>,
25+
v: UnsafeCell<int>,
2626
nocopy: marker::NoCopy
2727
}
2828

2929
/// An unsigned atomic integer type, supporting basic atomic arithmetic operations
3030
pub struct AtomicUint {
31-
v: Unsafe<uint>,
31+
v: UnsafeCell<uint>,
3232
nocopy: marker::NoCopy
3333
}
3434

3535
/// An unsafe atomic pointer. Only supports basic atomic operations
3636
pub struct AtomicPtr<T> {
37-
p: Unsafe<uint>,
37+
p: UnsafeCell<uint>,
3838
nocopy: marker::NoCopy
3939
}
4040

@@ -69,17 +69,14 @@ pub enum Ordering {
6969
}
7070

7171
/// An `AtomicBool` initialized to `false`
72-
pub static INIT_ATOMIC_BOOL : AtomicBool = AtomicBool { v: Unsafe{value: 0,
73-
marker1: marker::InvariantType},
74-
nocopy: marker::NoCopy };
72+
pub static INIT_ATOMIC_BOOL: AtomicBool =
73+
AtomicBool { v: UnsafeCell { value: 0 }, nocopy: marker::NoCopy };
7574
/// An `AtomicInt` initialized to `0`
76-
pub static INIT_ATOMIC_INT : AtomicInt = AtomicInt { v: Unsafe{value: 0,
77-
marker1: marker::InvariantType},
78-
nocopy: marker::NoCopy };
75+
pub static INIT_ATOMIC_INT: AtomicInt =
76+
AtomicInt { v: UnsafeCell { value: 0 }, nocopy: marker::NoCopy };
7977
/// An `AtomicUint` initialized to `0`
80-
pub static INIT_ATOMIC_UINT : AtomicUint = AtomicUint { v: Unsafe{value: 0,
81-
marker1: marker::InvariantType},
82-
nocopy: marker::NoCopy };
78+
pub static INIT_ATOMIC_UINT: AtomicUint =
79+
AtomicUint { v: UnsafeCell { value: 0, }, nocopy: marker::NoCopy };
8380

8481
// NB: Needs to be -1 (0b11111111...) to make fetch_nand work correctly
8582
static UINT_TRUE: uint = -1;
@@ -88,7 +85,7 @@ impl AtomicBool {
8885
/// Create a new `AtomicBool`
8986
pub fn new(v: bool) -> AtomicBool {
9087
let val = if v { UINT_TRUE } else { 0 };
91-
AtomicBool { v: Unsafe::new(val), nocopy: marker::NoCopy }
88+
AtomicBool { v: UnsafeCell::new(val), nocopy: marker::NoCopy }
9289
}
9390

9491
/// Load the value
@@ -289,7 +286,7 @@ impl AtomicBool {
289286
impl AtomicInt {
290287
/// Create a new `AtomicInt`
291288
pub fn new(v: int) -> AtomicInt {
292-
AtomicInt {v: Unsafe::new(v), nocopy: marker::NoCopy}
289+
AtomicInt {v: UnsafeCell::new(v), nocopy: marker::NoCopy}
293290
}
294291

295292
/// Load the value
@@ -401,7 +398,7 @@ impl AtomicInt {
401398
impl AtomicUint {
402399
/// Create a new `AtomicUint`
403400
pub fn new(v: uint) -> AtomicUint {
404-
AtomicUint { v: Unsafe::new(v), nocopy: marker::NoCopy }
401+
AtomicUint { v: UnsafeCell::new(v), nocopy: marker::NoCopy }
405402
}
406403

407404
/// Load the value
@@ -513,7 +510,7 @@ impl AtomicUint {
513510
impl<T> AtomicPtr<T> {
514511
/// Create a new `AtomicPtr`
515512
pub fn new(p: *mut T) -> AtomicPtr<T> {
516-
AtomicPtr { p: Unsafe::new(p as uint), nocopy: marker::NoCopy }
513+
AtomicPtr { p: UnsafeCell::new(p as uint), nocopy: marker::NoCopy }
517514
}
518515

519516
/// Load the value

src/libcore/bool.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@
1111
//! The boolean type
1212
1313
#![doc(primitive = "bool")]
14+
#![unstable = "this module is purely for documentation and it will likely be \
15+
removed from the public api"]
1416

0 commit comments

Comments
 (0)