Skip to content

Commit 3161176

Browse files
committed
---
yaml --- r: 106109 b: refs/heads/auto c: 3848021 h: refs/heads/master i: 106107: d30ac2a v: v3
1 parent 2780684 commit 3161176

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 710f13f0ad8f41c4c3d5de96b0d96ee4dea4c8b2
16+
refs/heads/auto: 3848021faedff3b99ad03fca320a1388e71e5039
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/libstd/cell.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ use fmt;
1717
use kinds::{marker, Pod};
1818
use ops::{Deref, DerefMut, Drop};
1919
use option::{None, Option, Some};
20+
use ty::Unsafe;
2021

2122
/// A mutable memory location that admits only `Pod` data.
2223
pub struct Cell<T> {
23-
priv value: T,
24+
priv value: Unsafe<T>,
2425
priv marker1: marker::InvariantType<T>,
2526
priv marker2: marker::NoFreeze,
2627
priv marker3: marker::NoShare,
@@ -30,7 +31,7 @@ impl<T:Pod> Cell<T> {
3031
/// Creates a new `Cell` containing the given value.
3132
pub fn new(value: T) -> Cell<T> {
3233
Cell {
33-
value: value,
34+
value: Unsafe{value: value, marker1: marker::InvariantType::<T>},
3435
marker1: marker::InvariantType::<T>,
3536
marker2: marker::NoFreeze,
3637
marker3: marker::NoShare,
@@ -40,14 +41,14 @@ impl<T:Pod> Cell<T> {
4041
/// Returns a copy of the contained value.
4142
#[inline]
4243
pub fn get(&self) -> T {
43-
self.value
44+
unsafe{ *self.value.get() }
4445
}
4546

4647
/// Sets the contained value.
4748
#[inline]
4849
pub fn set(&self, value: T) {
4950
unsafe {
50-
*cast::transmute_mut(&self.value) = value
51+
*self.value.get() = value;
5152
}
5253
}
5354
}
@@ -66,13 +67,13 @@ impl<T:Eq + Pod> Eq for Cell<T> {
6667

6768
impl<T: fmt::Show> fmt::Show for Cell<T> {
6869
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
69-
write!(f.buf, r"Cell \{ value: {} \}", self.value)
70+
write!(f.buf, r"Cell \{ value: {} \}", unsafe{*&self.value.get()})
7071
}
7172
}
7273

7374
/// A mutable memory location with dynamically checked borrow rules
7475
pub struct RefCell<T> {
75-
priv value: T,
76+
priv value: Unsafe<T>,
7677
priv borrow: BorrowFlag,
7778
priv marker1: marker::InvariantType<T>,
7879
priv marker2: marker::NoFreeze,
@@ -94,15 +95,15 @@ impl<T> RefCell<T> {
9495
marker2: marker::NoFreeze,
9596
marker3: marker::NoPod,
9697
marker4: marker::NoShare,
97-
value: value,
98+
value: Unsafe{value: value, marker1: marker::InvariantType::<T>},
9899
borrow: UNUSED,
99100
}
100101
}
101102

102103
/// Consumes the `RefCell`, returning the wrapped value.
103104
pub fn unwrap(self) -> T {
104105
assert!(self.borrow == UNUSED);
105-
self.value
106+
unsafe{self.value.unwrap()}
106107
}
107108

108109
unsafe fn as_mut<'a>(&'a self) -> &'a mut RefCell<T> {
@@ -202,7 +203,7 @@ impl<T> RefCell<T> {
202203
#[inline]
203204
pub fn set(&self, value: T) {
204205
let mut reference = self.borrow_mut();
205-
*reference.get() = value
206+
*reference.get() = value;
206207
}
207208
}
208209

@@ -251,14 +252,14 @@ impl<'b, T> Ref<'b, T> {
251252
/// Retrieve an immutable reference to the stored value.
252253
#[inline]
253254
pub fn get<'a>(&'a self) -> &'a T {
254-
&self.parent.value
255+
unsafe{ &*self.parent.value.get() }
255256
}
256257
}
257258

258259
impl<'b, T> Deref<T> for Ref<'b, T> {
259260
#[inline]
260261
fn deref<'a>(&'a self) -> &'a T {
261-
&self.parent.value
262+
unsafe{ &*self.parent.value.get() }
262263
}
263264
}
264265

@@ -279,21 +280,21 @@ impl<'b, T> RefMut<'b, T> {
279280
/// Retrieve a mutable reference to the stored value.
280281
#[inline]
281282
pub fn get<'a>(&'a mut self) -> &'a mut T {
282-
&mut self.parent.value
283+
unsafe{ &mut *self.parent.value.get() }
283284
}
284285
}
285286

286287
impl<'b, T> Deref<T> for RefMut<'b, T> {
287288
#[inline]
288289
fn deref<'a>(&'a self) -> &'a T {
289-
&self.parent.value
290+
unsafe{ &*self.parent.value.get() }
290291
}
291292
}
292293

293294
impl<'b, T> DerefMut<T> for RefMut<'b, T> {
294295
#[inline]
295296
fn deref_mut<'a>(&'a mut self) -> &'a mut T {
296-
&mut self.parent.value
297+
unsafe{ &mut *self.parent.value.get() }
297298
}
298299
}
299300

branches/auto/src/libstd/ty.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,8 @@ impl<T> Unsafe<T> {
7676
/// Gets a mutable pointer to the wrapped value
7777
#[inline]
7878
pub unsafe fn get(&self) -> *mut T { cast::transmute(&self.value) }
79+
80+
/// Unwraps the value
81+
#[inline]
82+
pub unsafe fn unwrap(self) -> T { self.value }
7983
}

0 commit comments

Comments
 (0)