about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaniel Micay <danielmicay@gmail.com>2013-12-11 18:03:25 -0500
committerDaniel Micay <danielmicay@gmail.com>2014-01-09 15:53:44 -0500
commitb36a948831f7375b725f26ebec1df88687fdfeab (patch)
tree5a6d78b2e4c6324dbe0aec869d46caabb05da453
parent63ba93f91d6988506fd25a91c7d80820818159ab (diff)
downloadrust-b36a948831f7375b725f26ebec1df88687fdfeab.tar.gz
rust-b36a948831f7375b725f26ebec1df88687fdfeab.zip
stop treating `Rc` cycles as unsafe
-rw-r--r--src/libextra/serialize.rs4
-rw-r--r--src/libstd/rc.rs54
-rw-r--r--src/test/compile-fail/issue-7013.rs2
-rw-r--r--src/test/compile-fail/no_freeze-rc.rs2
-rw-r--r--src/test/compile-fail/rcmut-not-const-and-not-owned.rs21
5 files changed, 13 insertions, 70 deletions
diff --git a/src/libextra/serialize.rs b/src/libextra/serialize.rs
index 59f7f2a2ffc..cdca670bc66 100644
--- a/src/libextra/serialize.rs
+++ b/src/libextra/serialize.rs
@@ -406,14 +406,14 @@ impl<S:Encoder,T:Encodable<S>> Encodable<S> for @T {
     }
 }
 
-impl<S:Encoder,T:Encodable<S> + Freeze> Encodable<S> for Rc<T> {
+impl<S:Encoder,T:Encodable<S>> Encodable<S> for Rc<T> {
     #[inline]
     fn encode(&self, s: &mut S) {
         self.borrow().encode(s)
     }
 }
 
-impl<D:Decoder,T:Decodable<D> + Freeze> Decodable<D> for Rc<T> {
+impl<D:Decoder,T:Decodable<D> + NonManaged> Decodable<D> for Rc<T> {
     #[inline]
     fn decode(d: &mut D) -> Rc<T> {
         Rc::new(Decodable::decode(d))
diff --git a/src/libstd/rc.rs b/src/libstd/rc.rs
index ad2305c2410..9e622dce4c0 100644
--- a/src/libstd/rc.rs
+++ b/src/libstd/rc.rs
@@ -19,9 +19,8 @@ overhead of atomic reference counting.
 use ptr::RawPtr;
 use unstable::intrinsics::transmute;
 use ops::Drop;
-use kinds::{Freeze, Send};
+use kinds::NonManaged;
 use clone::{Clone, DeepClone};
-use cell::RefCell;
 use cmp::{Eq, TotalEq, Ord, TotalOrd, Ordering};
 
 struct RcBox<T> {
@@ -36,46 +35,17 @@ pub struct Rc<T> {
     priv ptr: *mut RcBox<T>
 }
 
-impl<T: Freeze> Rc<T> {
-    /// Construct a new reference-counted box from a `Freeze` value
+impl<T: NonManaged> Rc<T> {
+    /// Construct a new reference-counted box
     #[inline]
     pub fn new(value: T) -> Rc<T> {
         unsafe {
-            Rc::new_unchecked(value)
-        }
-    }
-}
-
-impl<T: Send> Rc<T> {
-    /// Construct a new reference-counted box from a `Send` value
-    #[inline]
-    pub fn from_send(value: T) -> Rc<T> {
-        unsafe {
-            Rc::new_unchecked(value)
-        }
-    }
-}
-
-impl<T: Freeze> Rc<RefCell<T>> {
-    /// Construct a new reference-counted box from a `RefCell`-wrapped `Freeze` value
-    #[inline]
-    pub fn from_mut(value: RefCell<T>) -> Rc<RefCell<T>> {
-        unsafe {
-            Rc::new_unchecked(value)
+            Rc { ptr: transmute(~RcBox { value: value, count: 1 }) }
         }
     }
 }
 
 impl<T> Rc<T> {
-    /// Unsafety construct a new reference-counted box from any value.
-    ///
-    /// It is possible to create cycles, which will leak, and may interact
-    /// poorly with managed pointers.
-    #[inline]
-    pub unsafe fn new_unchecked(value: T) -> Rc<T> {
-        Rc{ptr: transmute(~RcBox{value: value, count: 1})}
-    }
-
     /// Borrow the value contained in the reference-counted box
     #[inline]
     pub fn borrow<'r>(&'r self) -> &'r T {
@@ -147,10 +117,10 @@ impl<T> Clone for Rc<T> {
     }
 }
 
-impl<T: DeepClone> DeepClone for Rc<T> {
+impl<T: NonManaged + DeepClone> DeepClone for Rc<T> {
     #[inline]
     fn deep_clone(&self) -> Rc<T> {
-        unsafe { Rc::new_unchecked(self.borrow().deep_clone()) }
+        Rc::new(self.borrow().deep_clone())
     }
 }
 
@@ -176,7 +146,7 @@ mod test_rc {
 
     #[test]
     fn test_clone() {
-        let x = Rc::from_send(RefCell::new(5));
+        let x = Rc::new(RefCell::new(5));
         let y = x.clone();
         x.borrow().with_mut(|inner| {
             *inner = 20;
@@ -186,7 +156,7 @@ mod test_rc {
 
     #[test]
     fn test_deep_clone() {
-        let x = Rc::from_send(RefCell::new(5));
+        let x = Rc::new(RefCell::new(5));
         let y = x.deep_clone();
         x.borrow().with_mut(|inner| {
             *inner = 20;
@@ -210,13 +180,7 @@ mod test_rc {
 
     #[test]
     fn test_destructor() {
-        let x = Rc::from_send(~5);
+        let x = Rc::new(~5);
         assert_eq!(**x.borrow(), 5);
     }
-
-    #[test]
-    fn test_from_mut() {
-        let a = 10;
-        let _x = Rc::from_mut(RefCell::new(&a));
-    }
 }
diff --git a/src/test/compile-fail/issue-7013.rs b/src/test/compile-fail/issue-7013.rs
index 9276a2f0d41..cf7cb1a5a53 100644
--- a/src/test/compile-fail/issue-7013.rs
+++ b/src/test/compile-fail/issue-7013.rs
@@ -37,7 +37,7 @@ struct A
 fn main()
 {
     let a = A {v: ~B{v: None} as ~Foo}; //~ ERROR cannot pack type `~B`, which does not fulfill `Send`
-    let v = Rc::from_send(RefCell::new(a));
+    let v = Rc::new(RefCell::new(a));
     let w = v.clone();
     let b = v.borrow();
     let mut b = b.borrow_mut();
diff --git a/src/test/compile-fail/no_freeze-rc.rs b/src/test/compile-fail/no_freeze-rc.rs
index dbf5d0fb3f9..a963446b84c 100644
--- a/src/test/compile-fail/no_freeze-rc.rs
+++ b/src/test/compile-fail/no_freeze-rc.rs
@@ -14,6 +14,6 @@ use std::cell::RefCell;
 fn bar<T: Freeze>(_: T) {}
 
 fn main() {
-    let x = Rc::from_send(RefCell::new(5));
+    let x = Rc::new(RefCell::new(5));
     bar(x); //~ ERROR instantiating a type parameter with an incompatible type `std::rc::Rc<std::cell::RefCell<int>>`, which does not fulfill `Freeze`
 }
diff --git a/src/test/compile-fail/rcmut-not-const-and-not-owned.rs b/src/test/compile-fail/rcmut-not-const-and-not-owned.rs
deleted file mode 100644
index 7e0c8319356..00000000000
--- a/src/test/compile-fail/rcmut-not-const-and-not-owned.rs
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use std::cell::RefCell;
-use std::rc::Rc;
-
-fn o<T: Send>(_: &T) {}
-fn c<T: Freeze>(_: &T) {}
-
-fn main() {
-    let x = Rc::from_send(RefCell::new(0));
-    o(&x); //~ ERROR instantiating a type parameter with an incompatible type `std::rc::Rc<std::cell::RefCell<int>>`, which does not fulfill `Send`
-    c(&x); //~ ERROR instantiating a type parameter with an incompatible type `std::rc::Rc<std::cell::RefCell<int>>`, which does not fulfill `Freeze`
-}