Skip to content

Commit 0c1b084

Browse files
committed
---
yaml --- r: 153395 b: refs/heads/try2 c: b1a964a h: refs/heads/master i: 153393: b39fe39 153391: 42163e2 v: v3
1 parent 2feb606 commit 0c1b084

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+544
-675
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: ffd9966c79ad034fe16e66e6c6795473473a6f50
8+
refs/heads/try2: b1a964a9bf23c92a6b6cb5762b54e0f0f4a337d5
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/liballoc/lib.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
//!
2222
//! Currently, there are four major definitions in this library.
2323
//!
24-
//! ## Boxed values
24+
//! ## Owned pointers
2525
//!
26-
//! The [`Box`](boxed/index.html) type is the core owned pointer type in rust.
26+
//! The [`Box`](owned/index.html) type is the core owned pointer type in rust.
2727
//! There can only be one owner of a `Box`, and the owner can decide to mutate
28-
//! the contents, which live on the heap.
28+
//! the contents.
2929
//!
3030
//! This type can be sent among tasks efficiently as the size of a `Box` value
3131
//! is just a pointer. Tree-like data structures are often built on owned
@@ -82,12 +82,6 @@ extern crate libc;
8282
#[cfg(test)] #[phase(plugin, link)] extern crate std;
8383
#[cfg(test)] #[phase(plugin, link)] extern crate log;
8484

85-
// The deprecated name of the boxed module
86-
87-
#[deprecated = "use boxed instead"]
88-
#[cfg(not(test))]
89-
pub use owned = boxed;
90-
9185
// Heaps provided for low-level allocation strategies
9286

9387
pub mod heap;
@@ -97,7 +91,7 @@ pub mod util;
9791
// Primitive types using the heaps above
9892

9993
#[cfg(not(test))]
100-
pub mod boxed;
94+
pub mod owned;
10195
pub mod arc;
10296
pub mod rc;
10397

branches/try2/src/liballoc/boxed.rs renamed to branches/try2/src/liballoc/owned.rs

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering};
1616
use core::default::Default;
1717
use core::fmt;
1818
use core::intrinsics;
19+
use core::kinds::Send;
1920
use core::mem;
2021
use core::option::Option;
2122
use core::raw::TraitObject;
@@ -26,19 +27,17 @@ use core::result::{Ok, Err, Result};
2627
///
2728
/// The following two examples are equivalent:
2829
///
29-
/// use std::boxed::HEAP;
30+
/// use std::owned::HEAP;
3031
///
3132
/// # struct Bar;
3233
/// # impl Bar { fn new(_a: int) { } }
3334
/// let foo = box(HEAP) Bar::new(2);
3435
/// let foo = box Bar::new(2);
35-
#[lang = "exchange_heap"]
36-
#[experimental = "may be renamed; uncertain about custom allocator design"]
36+
#[lang="exchange_heap"]
3737
pub static HEAP: () = ();
3838

3939
/// A type that represents a uniquely-owned value.
40-
#[lang = "owned_box"]
41-
#[unstable = "custom allocators will add an additional type parameter (with default)"]
40+
#[lang="owned_box"]
4241
pub struct Box<T>(*mut T);
4342

4443
impl<T: Default> Default for Box<T> {
@@ -58,6 +57,7 @@ impl<T: Clone> Clone for Box<T> {
5857
}
5958
}
6059

60+
// box pointers
6161
impl<T:PartialEq> PartialEq for Box<T> {
6262
#[inline]
6363
fn eq(&self, other: &Box<T>) -> bool { *(*self) == *(*other) }
@@ -85,27 +85,48 @@ impl<T: Ord> Ord for Box<T> {
8585
impl<T: Eq> Eq for Box<T> {}
8686

8787
/// Extension methods for an owning `Any` trait object
88-
#[unstable = "post-DST, the signature of `downcast` will change to take `Box<Self>`"]
89-
pub trait BoxAny {
88+
pub trait AnyOwnExt {
9089
/// Returns the boxed value if it is of type `T`, or
9190
/// `Err(Self)` if it isn't.
92-
fn downcast<T: 'static>(self) -> Result<Box<T>, Self>;
91+
fn move<T: 'static>(self) -> Result<Box<T>, Self>;
92+
}
93+
94+
impl AnyOwnExt for Box<Any> {
95+
#[inline]
96+
fn move<T: 'static>(self) -> Result<Box<T>, Box<Any>> {
97+
if self.is::<T>() {
98+
unsafe {
99+
// Get the raw representation of the trait object
100+
let to: TraitObject =
101+
*mem::transmute::<&Box<Any>, &TraitObject>(&self);
102+
103+
// Prevent destructor on self being run
104+
intrinsics::forget(self);
93105

94-
/// Deprecated; this method has been renamed to `downcast`.
95-
#[deprecated = "use downcast instead"]
96-
fn move<T: 'static>(self) -> Result<Box<T>, Self> {
97-
self.downcast::<T>()
106+
// Extract the data pointer
107+
Ok(mem::transmute(to.data))
108+
}
109+
} else {
110+
Err(self)
111+
}
98112
}
99113
}
100114

101-
impl BoxAny for Box<Any> {
115+
/// Extension methods for an owning `Any+Send` trait object
116+
pub trait AnySendOwnExt {
117+
/// Returns the boxed value if it is of type `T`, or
118+
/// `Err(Self)` if it isn't.
119+
fn move_send<T: 'static>(self) -> Result<Box<T>, Self>;
120+
}
121+
122+
impl AnySendOwnExt for Box<Any+Send> {
102123
#[inline]
103-
fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any>> {
124+
fn move_send<T: 'static>(self) -> Result<Box<T>, Box<Any+Send>> {
104125
if self.is::<T>() {
105126
unsafe {
106127
// Get the raw representation of the trait object
107128
let to: TraitObject =
108-
*mem::transmute::<&Box<Any>, &TraitObject>(&self);
129+
*mem::transmute::<&Box<Any+Send>, &TraitObject>(&self);
109130

110131
// Prevent destructor on self being run
111132
intrinsics::forget(self);
@@ -145,20 +166,20 @@ mod test {
145166
let a = box 8u as Box<Any>;
146167
let b = box Test as Box<Any>;
147168

148-
match a.downcast::<uint>() {
169+
match a.move::<uint>() {
149170
Ok(a) => { assert!(a == box 8u); }
150171
Err(..) => fail!()
151172
}
152-
match b.downcast::<Test>() {
173+
match b.move::<Test>() {
153174
Ok(a) => { assert!(a == box Test); }
154175
Err(..) => fail!()
155176
}
156177

157178
let a = box 8u as Box<Any>;
158179
let b = box Test as Box<Any>;
159180

160-
assert!(a.downcast::<Box<Test>>().is_err());
161-
assert!(b.downcast::<Box<uint>>().is_err());
181+
assert!(a.move::<Box<Test>>().is_err());
182+
assert!(b.move::<Box<uint>>().is_err());
162183
}
163184

164185
#[test]

branches/try2/src/libcollections/btree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
2121
use core::prelude::*;
2222

23-
use alloc::boxed::Box;
23+
use alloc::owned::Box;
2424
use core::fmt;
2525
use core::fmt::Show;
2626

branches/try2/src/libcollections/dlist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
use core::prelude::*;
2525

26-
use alloc::boxed::Box;
26+
use alloc::owned::Box;
2727
use core::default::Default;
2828
use core::fmt;
2929
use core::iter;

branches/try2/src/libcollections/hash/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565

6666
use core::prelude::*;
6767

68-
use alloc::boxed::Box;
68+
use alloc::owned::Box;
6969
use alloc::rc::Rc;
7070
use core::intrinsics::TypeId;
7171
use core::mem;

branches/try2/src/libcollections/treemap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
use core::prelude::*;
1616

17-
use alloc::boxed::Box;
17+
use alloc::owned::Box;
1818
use core::default::Default;
1919
use core::fmt;
2020
use core::fmt::Show;

branches/try2/src/libcollections/trie.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
use core::prelude::*;
1414

15-
use alloc::boxed::Box;
15+
use alloc::owned::Box;
1616
use core::default::Default;
1717
use core::mem::zeroed;
1818
use core::mem;

branches/try2/src/libcore/cell.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,11 @@ use option::{None, Option, Some};
163163
use ty::Unsafe;
164164

165165
/// A mutable memory location that admits only `Copy` data.
166-
#[unstable = "likely to be renamed; otherwise stable"]
167166
pub struct Cell<T> {
168167
value: Unsafe<T>,
169168
noshare: marker::NoShare,
170169
}
171170

172-
#[stable]
173171
impl<T:Copy> Cell<T> {
174172
/// Creates a new `Cell` containing the given value.
175173
pub fn new(value: T) -> Cell<T> {
@@ -194,22 +192,20 @@ impl<T:Copy> Cell<T> {
194192
}
195193
}
196194

197-
#[unstable = "waiting for `Clone` trait to become stable"]
195+
#[unstable]
198196
impl<T:Copy> Clone for Cell<T> {
199197
fn clone(&self) -> Cell<T> {
200198
Cell::new(self.get())
201199
}
202200
}
203201

204-
#[unstable = "waiting for `PartialEq` trait to become stable"]
205202
impl<T:PartialEq + Copy> PartialEq for Cell<T> {
206203
fn eq(&self, other: &Cell<T>) -> bool {
207204
self.get() == other.get()
208205
}
209206
}
210207

211208
/// A mutable memory location with dynamically checked borrow rules
212-
#[unstable = "likely to be renamed; otherwise stable"]
213209
pub struct RefCell<T> {
214210
value: Unsafe<T>,
215211
borrow: Cell<BorrowFlag>,
@@ -225,7 +221,6 @@ static WRITING: BorrowFlag = -1;
225221

226222
impl<T> RefCell<T> {
227223
/// Create a new `RefCell` containing `value`
228-
#[stable]
229224
pub fn new(value: T) -> RefCell<T> {
230225
RefCell {
231226
value: Unsafe::new(value),
@@ -236,7 +231,6 @@ impl<T> RefCell<T> {
236231
}
237232

238233
/// Consumes the `RefCell`, returning the wrapped value.
239-
#[unstable = "may be renamed, depending on global conventions"]
240234
pub fn unwrap(self) -> T {
241235
debug_assert!(self.borrow.get() == UNUSED);
242236
unsafe{self.value.unwrap()}
@@ -248,7 +242,6 @@ impl<T> RefCell<T> {
248242
/// immutable borrows can be taken out at the same time.
249243
///
250244
/// Returns `None` if the value is currently mutably borrowed.
251-
#[unstable = "may be renamed, depending on global conventions"]
252245
pub fn try_borrow<'a>(&'a self) -> Option<Ref<'a, T>> {
253246
match self.borrow.get() {
254247
WRITING => None,
@@ -267,7 +260,6 @@ impl<T> RefCell<T> {
267260
/// # Failure
268261
///
269262
/// Fails if the value is currently mutably borrowed.
270-
#[unstable]
271263
pub fn borrow<'a>(&'a self) -> Ref<'a, T> {
272264
match self.try_borrow() {
273265
Some(ptr) => ptr,
@@ -281,7 +273,6 @@ impl<T> RefCell<T> {
281273
/// cannot be borrowed while this borrow is active.
282274
///
283275
/// Returns `None` if the value is currently borrowed.
284-
#[unstable = "may be renamed, depending on global conventions"]
285276
pub fn try_borrow_mut<'a>(&'a self) -> Option<RefMut<'a, T>> {
286277
match self.borrow.get() {
287278
UNUSED => {
@@ -300,7 +291,6 @@ impl<T> RefCell<T> {
300291
/// # Failure
301292
///
302293
/// Fails if the value is currently borrowed.
303-
#[unstable]
304294
pub fn borrow_mut<'a>(&'a self) -> RefMut<'a, T> {
305295
match self.try_borrow_mut() {
306296
Some(ptr) => ptr,
@@ -309,30 +299,27 @@ impl<T> RefCell<T> {
309299
}
310300
}
311301

312-
#[unstable = "waiting for `Clone` to become stable"]
302+
#[unstable]
313303
impl<T: Clone> Clone for RefCell<T> {
314304
fn clone(&self) -> RefCell<T> {
315305
RefCell::new(self.borrow().clone())
316306
}
317307
}
318308

319-
#[unstable = "waiting for `PartialEq` to become stable"]
320309
impl<T: PartialEq> PartialEq for RefCell<T> {
321310
fn eq(&self, other: &RefCell<T>) -> bool {
322311
*self.borrow() == *other.borrow()
323312
}
324313
}
325314

326315
/// Wraps a borrowed reference to a value in a `RefCell` box.
327-
#[unstable]
328316
pub struct Ref<'b, T> {
329317
// FIXME #12808: strange name to try to avoid interfering with
330318
// field accesses of the contained type via Deref
331319
_parent: &'b RefCell<T>
332320
}
333321

334322
#[unsafe_destructor]
335-
#[unstable]
336323
impl<'b, T> Drop for Ref<'b, T> {
337324
fn drop(&mut self) {
338325
let borrow = self._parent.borrow.get();
@@ -341,7 +328,6 @@ impl<'b, T> Drop for Ref<'b, T> {
341328
}
342329
}
343330

344-
#[unstable = "waiting for `Deref` to become stable"]
345331
impl<'b, T> Deref<T> for Ref<'b, T> {
346332
#[inline]
347333
fn deref<'a>(&'a self) -> &'a T {
@@ -355,7 +341,7 @@ impl<'b, T> Deref<T> for Ref<'b, T> {
355341
///
356342
/// A `Clone` implementation would interfere with the widespread
357343
/// use of `r.borrow().clone()` to clone the contents of a `RefCell`.
358-
#[experimental = "likely to be moved to a method, pending language changes"]
344+
#[experimental]
359345
pub fn clone_ref<'b, T>(orig: &Ref<'b, T>) -> Ref<'b, T> {
360346
// Since this Ref exists, we know the borrow flag
361347
// is not set to WRITING.
@@ -369,15 +355,13 @@ pub fn clone_ref<'b, T>(orig: &Ref<'b, T>) -> Ref<'b, T> {
369355
}
370356

371357
/// Wraps a mutable borrowed reference to a value in a `RefCell` box.
372-
#[unstable]
373358
pub struct RefMut<'b, T> {
374359
// FIXME #12808: strange name to try to avoid interfering with
375360
// field accesses of the contained type via Deref
376361
_parent: &'b RefCell<T>
377362
}
378363

379364
#[unsafe_destructor]
380-
#[unstable]
381365
impl<'b, T> Drop for RefMut<'b, T> {
382366
fn drop(&mut self) {
383367
let borrow = self._parent.borrow.get();
@@ -386,15 +370,13 @@ impl<'b, T> Drop for RefMut<'b, T> {
386370
}
387371
}
388372

389-
#[unstable = "waiting for `Deref` to become stable"]
390373
impl<'b, T> Deref<T> for RefMut<'b, T> {
391374
#[inline]
392375
fn deref<'a>(&'a self) -> &'a T {
393376
unsafe { &*self._parent.value.get() }
394377
}
395378
}
396379

397-
#[unstable = "waiting for `DerefMut` to become stable"]
398380
impl<'b, T> DerefMut<T> for RefMut<'b, T> {
399381
#[inline]
400382
fn deref_mut<'a>(&'a mut self) -> &'a mut T {

0 commit comments

Comments
 (0)