diff --git a/src/libextra/serialize.rs b/src/libextra/serialize.rs index 59f7f2a2ffcb1d8d3564b8dd8a2c1d0628722719..cdca670bc66a9da55e47ca5565671dd96ed25250 100644 --- a/src/libextra/serialize.rs +++ b/src/libextra/serialize.rs @@ -406,14 +406,14 @@ fn encode(&self, s: &mut S) { } } -impl + Freeze> Encodable for Rc { +impl> Encodable for Rc { #[inline] fn encode(&self, s: &mut S) { self.borrow().encode(s) } } -impl + Freeze> Decodable for Rc { +impl + NonManaged> Decodable for Rc { #[inline] fn decode(d: &mut D) -> Rc { Rc::new(Decodable::decode(d)) diff --git a/src/libstd/rc.rs b/src/libstd/rc.rs index ad2305c241017c21d2ea82f5fb1444c2f74a6c4b..9e622dce4c0f8dbf9c67cbd41885245777046a32 100644 --- a/src/libstd/rc.rs +++ b/src/libstd/rc.rs @@ -19,9 +19,8 @@ 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 { @@ -36,46 +35,17 @@ pub struct Rc { priv ptr: *mut RcBox } -impl Rc { - /// Construct a new reference-counted box from a `Freeze` value +impl Rc { + /// Construct a new reference-counted box #[inline] pub fn new(value: T) -> Rc { unsafe { - Rc::new_unchecked(value) - } - } -} - -impl Rc { - /// Construct a new reference-counted box from a `Send` value - #[inline] - pub fn from_send(value: T) -> Rc { - unsafe { - Rc::new_unchecked(value) - } - } -} - -impl Rc> { - /// Construct a new reference-counted box from a `RefCell`-wrapped `Freeze` value - #[inline] - pub fn from_mut(value: RefCell) -> Rc> { - unsafe { - Rc::new_unchecked(value) + Rc { ptr: transmute(~RcBox { value: value, count: 1 }) } } } } impl Rc { - /// 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 { - 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 @@ fn clone(&self) -> Rc { } } -impl DeepClone for Rc { +impl DeepClone for Rc { #[inline] fn deep_clone(&self) -> Rc { - 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 @@ fn test_clone() { #[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 @@ fn test_simple_clone() { #[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 9276a2f0d41941e5f0ac0cb5ca95c3228c67420a..cf7cb1a5a535f48f593063c82772bb73349012c0 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 dbf5d0fb3f98b1c1475aea70b7035cb99ae8fe3d..a963446b84c734d2bdfe88c7aeffc99d3d16c8f4 100644 --- a/src/test/compile-fail/no_freeze-rc.rs +++ b/src/test/compile-fail/no_freeze-rc.rs @@ -14,6 +14,6 @@ fn bar(_: 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>`, 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 7e0c8319356e47f8ca7110978bfac4ea91d1258d..0000000000000000000000000000000000000000 --- 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 or the MIT license -// , 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) {} -fn c(_: &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>`, which does not fulfill `Send` - c(&x); //~ ERROR instantiating a type parameter with an incompatible type `std::rc::Rc>`, which does not fulfill `Freeze` -}