Skip to content

Commit c98d7f0

Browse files
committed
---
yaml --- r: 93820 b: refs/heads/try c: 7c9daa8 h: refs/heads/master v: v3
1 parent d57704a commit c98d7f0

File tree

4 files changed

+15
-248
lines changed

4 files changed

+15
-248
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 0da105a8b7b6b1e0568e8ff20f6ff4b13cc7ecc2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d3e57dca68fde4effdda3e4ae2887aa535fcd6
5-
refs/heads/try: 0fade3a714f7a7f9bff5c11f9f37528d0ab168a1
5+
refs/heads/try: 7c9daa8ff71cb5896af9bb9a6ec8e15391e76b4e
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libstd/rc.rs

Lines changed: 0 additions & 237 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ The `Rc` type provides shared ownership of an immutable value. Destruction is de
1414
will occur as soon as the last owner is gone. It is marked as non-sendable because it avoids the
1515
overhead of atomic reference counting.
1616
17-
The `RcMut` type provides shared ownership of a mutable value. Since multiple owners prevent
18-
inherited mutability, a dynamic freezing check is used to maintain the invariant that an `&mut`
19-
reference is a unique handle and the type is marked as non-`Freeze`.
20-
2117
*/
2218

2319
use ptr::RawPtr;
@@ -151,236 +147,3 @@ mod test_rc {
151147
assert_eq!(**x.borrow(), 5);
152148
}
153149
}
154-
155-
#[deriving(Eq)]
156-
enum Borrow {
157-
Mutable,
158-
Immutable,
159-
Nothing
160-
}
161-
162-
struct RcMutBox<T> {
163-
value: T,
164-
count: uint,
165-
borrow: Borrow
166-
}
167-
168-
/// Mutable reference counted pointer type
169-
#[no_send]
170-
#[no_freeze]
171-
#[unsafe_no_drop_flag]
172-
pub struct RcMut<T> {
173-
priv ptr: *mut RcMutBox<T>,
174-
}
175-
176-
impl<T: Freeze> RcMut<T> {
177-
/// Construct a new mutable reference-counted box from a `Freeze` value
178-
#[inline]
179-
pub fn new(value: T) -> RcMut<T> {
180-
unsafe { RcMut::new_unchecked(value) }
181-
}
182-
}
183-
184-
impl<T: Send> RcMut<T> {
185-
/// Construct a new mutable reference-counted box from a `Send` value
186-
#[inline]
187-
pub fn from_send(value: T) -> RcMut<T> {
188-
unsafe { RcMut::new_unchecked(value) }
189-
}
190-
}
191-
192-
impl<T> RcMut<T> {
193-
/// Unsafety construct a new mutable reference-counted box from any value.
194-
///
195-
/// It is possible to create cycles, which will leak, and may interact
196-
/// poorly with managed pointers.
197-
#[inline]
198-
pub unsafe fn new_unchecked(value: T) -> RcMut<T> {
199-
RcMut{ptr: transmute(~RcMutBox{value: value, count: 1, borrow: Nothing})}
200-
}
201-
}
202-
203-
impl<T> RcMut<T> {
204-
/// Fails if there is already a mutable borrow of the box
205-
#[inline]
206-
pub fn with_borrow<U>(&self, f: |&T| -> U) -> U {
207-
unsafe {
208-
assert!((*self.ptr).borrow != Mutable);
209-
let previous = (*self.ptr).borrow;
210-
(*self.ptr).borrow = Immutable;
211-
let res = f(&(*self.ptr).value);
212-
(*self.ptr).borrow = previous;
213-
res
214-
}
215-
}
216-
217-
/// Fails if there is already a mutable or immutable borrow of the box
218-
#[inline]
219-
pub fn with_mut_borrow<U>(&self, f: |&mut T| -> U) -> U {
220-
unsafe {
221-
assert_eq!((*self.ptr).borrow, Nothing);
222-
(*self.ptr).borrow = Mutable;
223-
let res = f(&mut (*self.ptr).value);
224-
(*self.ptr).borrow = Nothing;
225-
res
226-
}
227-
}
228-
}
229-
230-
#[unsafe_destructor]
231-
impl<T> Drop for RcMut<T> {
232-
fn drop(&mut self) {
233-
unsafe {
234-
if self.ptr.is_not_null() {
235-
(*self.ptr).count -= 1;
236-
if (*self.ptr).count == 0 {
237-
let _: ~RcMutBox<T> = transmute(self.ptr);
238-
}
239-
}
240-
}
241-
}
242-
}
243-
244-
impl<T> Clone for RcMut<T> {
245-
/// Return a shallow copy of the reference counted pointer.
246-
#[inline]
247-
fn clone(&self) -> RcMut<T> {
248-
unsafe {
249-
(*self.ptr).count += 1;
250-
RcMut{ptr: self.ptr}
251-
}
252-
}
253-
}
254-
255-
impl<T: DeepClone> DeepClone for RcMut<T> {
256-
/// Return a deep copy of the reference counted pointer.
257-
#[inline]
258-
fn deep_clone(&self) -> RcMut<T> {
259-
do self.with_borrow |x| {
260-
// FIXME: #6497: should avoid freeze (slow)
261-
unsafe { RcMut::new_unchecked(x.deep_clone()) }
262-
}
263-
}
264-
}
265-
266-
#[cfg(test)]
267-
mod test_rc_mut {
268-
use super::*;
269-
270-
#[test]
271-
fn test_clone() {
272-
let x = RcMut::from_send(5);
273-
let y = x.clone();
274-
do x.with_mut_borrow |value| {
275-
*value = 20;
276-
}
277-
do y.with_borrow |value| {
278-
assert_eq!(*value, 20);
279-
}
280-
}
281-
282-
#[test]
283-
fn test_deep_clone() {
284-
let x = RcMut::new(5);
285-
let y = x.deep_clone();
286-
do x.with_mut_borrow |value| {
287-
*value = 20;
288-
}
289-
do y.with_borrow |value| {
290-
assert_eq!(*value, 5);
291-
}
292-
}
293-
294-
#[test]
295-
fn borrow_many() {
296-
let x = RcMut::from_send(5);
297-
let y = x.clone();
298-
299-
do x.with_borrow |a| {
300-
assert_eq!(*a, 5);
301-
do y.with_borrow |b| {
302-
assert_eq!(*b, 5);
303-
do x.with_borrow |c| {
304-
assert_eq!(*c, 5);
305-
}
306-
}
307-
}
308-
}
309-
310-
#[test]
311-
fn modify() {
312-
let x = RcMut::new(5);
313-
let y = x.clone();
314-
315-
do y.with_mut_borrow |a| {
316-
assert_eq!(*a, 5);
317-
*a = 6;
318-
}
319-
320-
do x.with_borrow |a| {
321-
assert_eq!(*a, 6);
322-
}
323-
}
324-
325-
#[test]
326-
fn release_immutable() {
327-
let x = RcMut::from_send(5);
328-
do x.with_borrow |_| {}
329-
do x.with_mut_borrow |_| {}
330-
}
331-
332-
#[test]
333-
fn release_mutable() {
334-
let x = RcMut::new(5);
335-
do x.with_mut_borrow |_| {}
336-
do x.with_borrow |_| {}
337-
}
338-
339-
#[test]
340-
#[should_fail]
341-
fn frozen() {
342-
let x = RcMut::from_send(5);
343-
let y = x.clone();
344-
345-
do x.with_borrow |_| {
346-
do y.with_mut_borrow |_| {
347-
}
348-
}
349-
}
350-
351-
#[test]
352-
#[should_fail]
353-
fn mutable_dupe() {
354-
let x = RcMut::new(5);
355-
let y = x.clone();
356-
357-
do x.with_mut_borrow |_| {
358-
do y.with_mut_borrow |_| {
359-
}
360-
}
361-
}
362-
363-
#[test]
364-
#[should_fail]
365-
fn mutable_freeze() {
366-
let x = RcMut::from_send(5);
367-
let y = x.clone();
368-
369-
do x.with_mut_borrow |_| {
370-
do y.with_borrow |_| {
371-
}
372-
}
373-
}
374-
375-
#[test]
376-
#[should_fail]
377-
fn restore_freeze() {
378-
let x = RcMut::new(5);
379-
let y = x.clone();
380-
381-
do x.with_borrow |_| {
382-
do x.with_borrow |_| {}
383-
do y.with_mut_borrow |_| {}
384-
}
385-
}
386-
}

branches/try/src/test/compile-fail/issue-7013.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,22 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::rc::RcMut;
11+
use std::rc::Rc;
12+
use std::mutable::Mut;
1213

1314
trait Foo
1415
{
15-
fn set(&mut self, v: RcMut<A>);
16+
fn set(&mut self, v: Rc<Mut<A>>);
1617
}
1718

1819
struct B
1920
{
20-
v: Option<RcMut<A>>
21+
v: Option<Rc<Mut<A>>>
2122
}
2223

2324
impl Foo for B
2425
{
25-
fn set(&mut self, v: RcMut<A>)
26+
fn set(&mut self, v: Rc<Mut<A>>)
2627
{
2728
self.v = Some(v);
2829
}
@@ -36,7 +37,9 @@ struct A
3637
fn main()
3738
{
3839
let a = A {v: ~B{v: None} as ~Foo}; //~ ERROR cannot pack type `~B`, which does not fulfill `Send`
39-
let v = RcMut::new(a); //~ ERROR instantiating a type parameter with an incompatible type
40+
let v = Rc::from_send(Mut::new(a));
4041
let w = v.clone();
41-
v.with_mut_borrow(|p| {p.v.set(w.clone());})
42+
let b = v.borrow();
43+
let mut b = b.borrow_mut();
44+
b.get().v.set(w.clone());
4245
}

branches/try/src/test/compile-fail/rcmut-not-const-and-not-owned.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::rc::RcMut;
11+
use std::mutable::Mut;
12+
use std::rc::Rc;
1213

1314
fn o<T: Send>(_: &T) {}
1415
fn c<T: Freeze>(_: &T) {}
1516

1617
fn main() {
17-
let x = RcMut::from_send(0);
18-
o(&x); //~ ERROR instantiating a type parameter with an incompatible type `std::rc::RcMut<int>`, which does not fulfill `Send`
19-
c(&x); //~ ERROR instantiating a type parameter with an incompatible type `std::rc::RcMut<int>`, which does not fulfill `Freeze`
18+
let x = Rc::from_send(Mut::new(0));
19+
o(&x); //~ ERROR instantiating a type parameter with an incompatible type `std::rc::Rc<std::mutable::Mut<int>>`, which does not fulfill `Send`
20+
c(&x); //~ ERROR instantiating a type parameter with an incompatible type `std::rc::Rc<std::mutable::Mut<int>>`, which does not fulfill `Freeze`
2021
}

0 commit comments

Comments
 (0)