about summary refs log tree commit diff
path: root/src/liballoc/rc.rs
diff options
context:
space:
mode:
authorEduard Burtescu <edy.burt@gmail.com>2015-05-25 20:21:29 +0300
committerEduard Burtescu <edy.burt@gmail.com>2015-05-27 11:19:02 +0300
commit6e8e4f847c2ea02fec021ea15dfb2de6beac797a (patch)
tree7831f2de833ae0151217710dc87b2ba03a3bc128 /src/liballoc/rc.rs
parent07503dfb8bd60e2047a0a5083dd5377f9f14b77d (diff)
downloadrust-6e8e4f847c2ea02fec021ea15dfb2de6beac797a.tar.gz
rust-6e8e4f847c2ea02fec021ea15dfb2de6beac797a.zip
Remove #[cfg(stage0)] items.
Diffstat (limited to 'src/liballoc/rc.rs')
-rw-r--r--src/liballoc/rc.rs419
1 files changed, 4 insertions, 415 deletions
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs
index 1f660449593..44f4a6a6290 100644
--- a/src/liballoc/rc.rs
+++ b/src/liballoc/rc.rs
@@ -159,36 +159,19 @@ use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering};
 use core::default::Default;
 use core::fmt;
 use core::hash::{Hasher, Hash};
-use core::marker::{self, Sized};
-use core::mem::{self, min_align_of, size_of, forget};
+use core::intrinsics::{assume, drop_in_place};
+use core::marker::{self, Sized, Unsize};
+use core::mem::{self, min_align_of, size_of, min_align_of_val, size_of_val, forget};
 use core::nonzero::NonZero;
-use core::ops::{Deref, Drop};
+use core::ops::{CoerceUnsized, Deref, Drop};
 use core::option::Option;
 use core::option::Option::{Some, None};
 use core::ptr;
 use core::result::Result;
 use core::result::Result::{Ok, Err};
-use core::intrinsics::assume;
-
-#[cfg(not(stage0))]
-use core::intrinsics::drop_in_place;
-#[cfg(not(stage0))]
-use core::marker::Unsize;
-#[cfg(not(stage0))]
-use core::mem::{min_align_of_val, size_of_val};
-#[cfg(not(stage0))]
-use core::ops::CoerceUnsized;
 
 use heap::deallocate;
 
-#[cfg(stage0)]
-struct RcBox<T> {
-    strong: Cell<usize>,
-    weak: Cell<usize>,
-    value: T,
-}
-
-#[cfg(not(stage0))]
 struct RcBox<T: ?Sized> {
     strong: Cell<usize>,
     weak: Cell<usize>,
@@ -199,15 +182,6 @@ struct RcBox<T: ?Sized> {
 /// A reference-counted pointer type over an immutable value.
 ///
 /// See the [module level documentation](./index.html) for more details.
-#[cfg(stage0)]
-#[unsafe_no_drop_flag]
-#[stable(feature = "rust1", since = "1.0.0")]
-pub struct Rc<T> {
-    // FIXME #12808: strange names to try to avoid interfering with field
-    // accesses of the contained type via Deref
-    _ptr: NonZero<*mut RcBox<T>>,
-}
-#[cfg(not(stage0))]
 #[unsafe_no_drop_flag]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct Rc<T: ?Sized> {
@@ -216,19 +190,9 @@ pub struct Rc<T: ?Sized> {
     _ptr: NonZero<*mut RcBox<T>>,
 }
 
-#[cfg(stage0)]
-impl<T> !marker::Send for Rc<T> {}
-
-#[cfg(not(stage0))]
 impl<T: ?Sized> !marker::Send for Rc<T> {}
-
-#[cfg(stage0)]
-impl<T> !marker::Sync for Rc<T> {}
-
-#[cfg(not(stage0))]
 impl<T: ?Sized> !marker::Sync for Rc<T> {}
 
-#[cfg(not(stage0))]
 impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<Rc<U>> for Rc<T> {}
 
 impl<T> Rc<T> {
@@ -259,7 +223,6 @@ impl<T> Rc<T> {
     }
 }
 
-#[cfg(not(stage0))]
 impl<T: ?Sized> Rc<T> {
     /// Downgrades the `Rc<T>` to a `Weak<T>` reference.
     ///
@@ -281,44 +244,12 @@ impl<T: ?Sized> Rc<T> {
     }
 }
 
-#[cfg(stage0)]
-impl<T> Rc<T> {
-    /// Downgrades the `Rc<T>` to a `Weak<T>` reference.
-    ///
-    /// # Examples
-    ///
-    /// ```
-    /// # #![feature(alloc)]
-    /// use std::rc::Rc;
-    ///
-    /// let five = Rc::new(5);
-    ///
-    /// let weak_five = five.downgrade();
-    /// ```
-    #[unstable(feature = "alloc",
-               reason = "Weak pointers may not belong in this module")]
-    pub fn downgrade(&self) -> Weak<T> {
-        self.inc_weak();
-        Weak { _ptr: self._ptr }
-    }
-}
-
 /// Get the number of weak references to this value.
-#[cfg(stage0)]
-#[inline]
-#[unstable(feature = "alloc")]
-pub fn weak_count<T>(this: &Rc<T>) -> usize { this.weak() - 1 }
-#[cfg(not(stage0))]
 #[inline]
 #[unstable(feature = "alloc")]
 pub fn weak_count<T: ?Sized>(this: &Rc<T>) -> usize { this.weak() - 1 }
 
 /// Get the number of strong references to this value.
-#[cfg(stage0)]
-#[inline]
-#[unstable(feature = "alloc")]
-pub fn strong_count<T>(this: &Rc<T>) -> usize { this.strong() }
-#[cfg(not(stage0))]
 #[inline]
 #[unstable(feature = "alloc")]
 pub fn strong_count<T: ?Sized>(this: &Rc<T>) -> usize { this.strong() }
@@ -438,17 +369,6 @@ impl<T: Clone> Rc<T> {
     }
 }
 
-#[cfg(stage0)]
-#[stable(feature = "rust1", since = "1.0.0")]
-impl<T> Deref for Rc<T> {
-    type Target = T;
-
-    #[inline(always)]
-    fn deref(&self) -> &T {
-        &self.inner().value
-    }
-}
-#[cfg(not(stage0))]
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: ?Sized> Deref for Rc<T> {
     type Target = T;
@@ -459,58 +379,6 @@ impl<T: ?Sized> Deref for Rc<T> {
     }
 }
 
-#[cfg(stage0)]
-#[stable(feature = "rust1", since = "1.0.0")]
-impl<T> Drop for Rc<T> {
-    /// Drops the `Rc<T>`.
-    ///
-    /// This will decrement the strong reference count. If the strong reference
-    /// count becomes zero and the only other references are `Weak<T>` ones,
-    /// `drop`s the inner value.
-    ///
-    /// # Examples
-    ///
-    /// ```
-    /// # #![feature(alloc)]
-    /// use std::rc::Rc;
-    ///
-    /// {
-    ///     let five = Rc::new(5);
-    ///
-    ///     // stuff
-    ///
-    ///     drop(five); // explicit drop
-    /// }
-    /// {
-    ///     let five = Rc::new(5);
-    ///
-    ///     // stuff
-    ///
-    /// } // implicit drop
-    /// ```
-    fn drop(&mut self) {
-        unsafe {
-            let ptr = *self._ptr;
-            if !ptr.is_null() && ptr as usize != mem::POST_DROP_USIZE {
-                self.dec_strong();
-                if self.strong() == 0 {
-                    ptr::read(&**self); // destroy the contained object
-
-                    // remove the implicit "strong weak" pointer now that we've
-                    // destroyed the contents.
-                    self.dec_weak();
-
-                    if self.weak() == 0 {
-                        deallocate(ptr as *mut u8, size_of::<RcBox<T>>(),
-                                   min_align_of::<RcBox<T>>())
-                    }
-                }
-            }
-        }
-    }
-}
-
-#[cfg(not(stage0))]
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: ?Sized> Drop for Rc<T> {
     /// Drops the `Rc<T>`.
@@ -564,32 +432,6 @@ impl<T: ?Sized> Drop for Rc<T> {
     }
 }
 
-#[cfg(stage0)]
-#[stable(feature = "rust1", since = "1.0.0")]
-impl<T> Clone for Rc<T> {
-
-    /// Makes a clone of the `Rc<T>`.
-    ///
-    /// When you clone an `Rc<T>`, it will create another pointer to the data and
-    /// increase the strong reference counter.
-    ///
-    /// # Examples
-    ///
-    /// ```
-    /// # #![feature(alloc)]
-    /// use std::rc::Rc;
-    ///
-    /// let five = Rc::new(5);
-    ///
-    /// five.clone();
-    /// ```
-    #[inline]
-    fn clone(&self) -> Rc<T> {
-        self.inc_strong();
-        Rc { _ptr: self._ptr }
-    }
-}
-#[cfg(not(stage0))]
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: ?Sized> Clone for Rc<T> {
 
@@ -634,17 +476,6 @@ impl<T: Default> Default for Rc<T> {
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
-#[cfg(stage0)]
-impl<T: PartialEq> PartialEq for Rc<T> {
-    #[inline(always)]
-    fn eq(&self, other: &Rc<T>) -> bool { **self == **other }
-
-    #[inline(always)]
-    fn ne(&self, other: &Rc<T>) -> bool { **self != **other }
-}
-
-#[stable(feature = "rust1", since = "1.0.0")]
-#[cfg(not(stage0))]
 impl<T: ?Sized + PartialEq> PartialEq for Rc<T> {
     /// Equality for two `Rc<T>`s.
     ///
@@ -680,34 +511,9 @@ impl<T: ?Sized + PartialEq> PartialEq for Rc<T> {
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
-#[cfg(stage0)]
-impl<T: Eq> Eq for Rc<T> {}
-#[stable(feature = "rust1", since = "1.0.0")]
-#[cfg(not(stage0))]
 impl<T: ?Sized + Eq> Eq for Rc<T> {}
 
 #[stable(feature = "rust1", since = "1.0.0")]
-#[cfg(stage0)]
-impl<T: PartialOrd> PartialOrd for Rc<T> {
-    #[inline(always)]
-    fn partial_cmp(&self, other: &Rc<T>) -> Option<Ordering> {
-        (**self).partial_cmp(&**other)
-    }
-
-    #[inline(always)]
-    fn lt(&self, other: &Rc<T>) -> bool { **self < **other }
-
-    #[inline(always)]
-    fn le(&self, other: &Rc<T>) -> bool { **self <= **other }
-
-    #[inline(always)]
-    fn gt(&self, other: &Rc<T>) -> bool { **self > **other }
-
-    #[inline(always)]
-    fn ge(&self, other: &Rc<T>) -> bool { **self >= **other }
-}
-#[stable(feature = "rust1", since = "1.0.0")]
-#[cfg(not(stage0))]
 impl<T: ?Sized + PartialOrd> PartialOrd for Rc<T> {
     /// Partial comparison for two `Rc<T>`s.
     ///
@@ -793,13 +599,6 @@ impl<T: ?Sized + PartialOrd> PartialOrd for Rc<T> {
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
-#[cfg(stage0)]
-impl<T: Ord> Ord for Rc<T> {
-    #[inline]
-    fn cmp(&self, other: &Rc<T>) -> Ordering { (**self).cmp(&**other) }
-}
-#[stable(feature = "rust1", since = "1.0.0")]
-#[cfg(not(stage0))]
 impl<T: ?Sized + Ord> Ord for Rc<T> {
     /// Comparison for two `Rc<T>`s.
     ///
@@ -818,14 +617,6 @@ impl<T: ?Sized + Ord> Ord for Rc<T> {
     fn cmp(&self, other: &Rc<T>) -> Ordering { (**self).cmp(&**other) }
 }
 
-#[cfg(stage0)]
-#[stable(feature = "rust1", since = "1.0.0")]
-impl<T: Hash> Hash for Rc<T> {
-    fn hash<H: Hasher>(&self, state: &mut H) {
-        (**self).hash(state);
-    }
-}
-#[cfg(not(stage0))]
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: ?Sized+Hash> Hash for Rc<T> {
     fn hash<H: Hasher>(&self, state: &mut H) {
@@ -833,14 +624,6 @@ impl<T: ?Sized+Hash> Hash for Rc<T> {
     }
 }
 
-#[cfg(stage0)]
-#[stable(feature = "rust1", since = "1.0.0")]
-impl<T: fmt::Display> fmt::Display for Rc<T> {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        fmt::Display::fmt(&**self, f)
-    }
-}
-#[cfg(not(stage0))]
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: ?Sized+fmt::Display> fmt::Display for Rc<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -848,14 +631,6 @@ impl<T: ?Sized+fmt::Display> fmt::Display for Rc<T> {
     }
 }
 
-#[cfg(stage0)]
-#[stable(feature = "rust1", since = "1.0.0")]
-impl<T: fmt::Debug> fmt::Debug for Rc<T> {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        fmt::Debug::fmt(&**self, f)
-    }
-}
-#[cfg(not(stage0))]
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: ?Sized+fmt::Debug> fmt::Debug for Rc<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -876,16 +651,6 @@ impl<T> fmt::Pointer for Rc<T> {
 /// dropped.
 ///
 /// See the [module level documentation](./index.html) for more.
-#[cfg(stage0)]
-#[unsafe_no_drop_flag]
-#[unstable(feature = "alloc",
-           reason = "Weak pointers may not belong in this module.")]
-pub struct Weak<T> {
-    // FIXME #12808: strange names to try to avoid interfering with
-    // field accesses of the contained type via Deref
-    _ptr: NonZero<*mut RcBox<T>>,
-}
-#[cfg(not(stage0))]
 #[unsafe_no_drop_flag]
 #[unstable(feature = "alloc",
            reason = "Weak pointers may not belong in this module.")]
@@ -895,51 +660,9 @@ pub struct Weak<T: ?Sized> {
     _ptr: NonZero<*mut RcBox<T>>,
 }
 
-#[cfg(stage0)]
-impl<T> !marker::Send for Weak<T> {}
-#[cfg(not(stage0))]
 impl<T: ?Sized> !marker::Send for Weak<T> {}
-
-#[cfg(stage0)]
-impl<T> !marker::Sync for Weak<T> {}
-#[cfg(not(stage0))]
 impl<T: ?Sized> !marker::Sync for Weak<T> {}
 
-
-#[cfg(stage0)]
-#[unstable(feature = "alloc",
-           reason = "Weak pointers may not belong in this module.")]
-impl<T> Weak<T> {
-
-    /// Upgrades a weak reference to a strong reference.
-    ///
-    /// Upgrades the `Weak<T>` reference to an `Rc<T>`, if possible.
-    ///
-    /// Returns `None` if there were no strong references and the data was
-    /// destroyed.
-    ///
-    /// # Examples
-    ///
-    /// ```
-    /// # #![feature(alloc)]
-    /// use std::rc::Rc;
-    ///
-    /// let five = Rc::new(5);
-    ///
-    /// let weak_five = five.downgrade();
-    ///
-    /// let strong_five: Option<Rc<_>> = weak_five.upgrade();
-    /// ```
-    pub fn upgrade(&self) -> Option<Rc<T>> {
-        if self.strong() == 0 {
-            None
-        } else {
-            self.inc_strong();
-            Some(Rc { _ptr: self._ptr })
-        }
-    }
-}
-#[cfg(not(stage0))]
 #[unstable(feature = "alloc",
            reason = "Weak pointers may not belong in this module.")]
 impl<T: ?Sized> Weak<T> {
@@ -973,52 +696,6 @@ impl<T: ?Sized> Weak<T> {
     }
 }
 
-#[cfg(stage0)]
-#[stable(feature = "rust1", since = "1.0.0")]
-impl<T> Drop for Weak<T> {
-    /// Drops the `Weak<T>`.
-    ///
-    /// This will decrement the weak reference count.
-    ///
-    /// # Examples
-    ///
-    /// ```
-    /// # #![feature(alloc)]
-    /// use std::rc::Rc;
-    ///
-    /// {
-    ///     let five = Rc::new(5);
-    ///     let weak_five = five.downgrade();
-    ///
-    ///     // stuff
-    ///
-    ///     drop(weak_five); // explicit drop
-    /// }
-    /// {
-    ///     let five = Rc::new(5);
-    ///     let weak_five = five.downgrade();
-    ///
-    ///     // stuff
-    ///
-    /// } // implicit drop
-    /// ```
-    fn drop(&mut self) {
-        unsafe {
-            let ptr = *self._ptr;
-            if !ptr.is_null() && ptr as usize != mem::POST_DROP_USIZE {
-                self.dec_weak();
-                // the weak count starts at 1, and will only go to zero if all
-                // the strong pointers have disappeared.
-                if self.weak() == 0 {
-                    deallocate(ptr as *mut u8, size_of::<RcBox<T>>(),
-                               min_align_of::<RcBox<T>>())
-                }
-            }
-        }
-    }
-}
-
-#[cfg(not(stage0))]
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: ?Sized> Drop for Weak<T> {
     /// Drops the `Weak<T>`.
@@ -1064,32 +741,6 @@ impl<T: ?Sized> Drop for Weak<T> {
     }
 }
 
-#[cfg(stage0)]
-#[unstable(feature = "alloc",
-           reason = "Weak pointers may not belong in this module.")]
-impl<T> Clone for Weak<T> {
-
-    /// Makes a clone of the `Weak<T>`.
-    ///
-    /// This increases the weak reference count.
-    ///
-    /// # Examples
-    ///
-    /// ```
-    /// # #![feature(alloc)]
-    /// use std::rc::Rc;
-    ///
-    /// let weak_five = Rc::new(5).downgrade();
-    ///
-    /// weak_five.clone();
-    /// ```
-    #[inline]
-    fn clone(&self) -> Weak<T> {
-        self.inc_weak();
-        Weak { _ptr: self._ptr }
-    }
-}
-#[cfg(not(stage0))]
 #[unstable(feature = "alloc",
            reason = "Weak pointers may not belong in this module.")]
 impl<T: ?Sized> Clone for Weak<T> {
@@ -1115,14 +766,6 @@ impl<T: ?Sized> Clone for Weak<T> {
     }
 }
 
-#[cfg(stage0)]
-#[stable(feature = "rust1", since = "1.0.0")]
-impl<T: fmt::Debug> fmt::Debug for Weak<T> {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        write!(f, "(Weak)")
-    }
-}
-#[cfg(not(stage0))]
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: ?Sized+fmt::Debug> fmt::Debug for Weak<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -1130,30 +773,6 @@ impl<T: ?Sized+fmt::Debug> fmt::Debug for Weak<T> {
     }
 }
 
-#[cfg(stage0)]
-#[doc(hidden)]
-trait RcBoxPtr<T> {
-    fn inner(&self) -> &RcBox<T>;
-
-    #[inline]
-    fn strong(&self) -> usize { self.inner().strong.get() }
-
-    #[inline]
-    fn inc_strong(&self) { self.inner().strong.set(self.strong() + 1); }
-
-    #[inline]
-    fn dec_strong(&self) { self.inner().strong.set(self.strong() - 1); }
-
-    #[inline]
-    fn weak(&self) -> usize { self.inner().weak.get() }
-
-    #[inline]
-    fn inc_weak(&self) { self.inner().weak.set(self.weak() + 1); }
-
-    #[inline]
-    fn dec_weak(&self) { self.inner().weak.set(self.weak() - 1); }
-}
-#[cfg(not(stage0))]
 #[doc(hidden)]
 trait RcBoxPtr<T: ?Sized> {
     fn inner(&self) -> &RcBox<T>;
@@ -1177,21 +796,6 @@ trait RcBoxPtr<T: ?Sized> {
     fn dec_weak(&self) { self.inner().weak.set(self.weak() - 1); }
 }
 
-#[cfg(stage0)]
-impl<T> RcBoxPtr<T> for Rc<T> {
-    #[inline(always)]
-    fn inner(&self) -> &RcBox<T> {
-        unsafe {
-            // Safe to assume this here, as if it weren't true, we'd be breaking
-            // the contract anyway.
-            // This allows the null check to be elided in the destructor if we
-            // manipulated the reference count in the same function.
-            assume(!(*(&self._ptr as *const _ as *const *const ())).is_null());
-            &(**self._ptr)
-        }
-    }
-}
-#[cfg(not(stage0))]
 impl<T: ?Sized> RcBoxPtr<T> for Rc<T> {
     #[inline(always)]
     fn inner(&self) -> &RcBox<T> {
@@ -1206,21 +810,6 @@ impl<T: ?Sized> RcBoxPtr<T> for Rc<T> {
     }
 }
 
-#[cfg(stage0)]
-impl<T> RcBoxPtr<T> for Weak<T> {
-    #[inline(always)]
-    fn inner(&self) -> &RcBox<T> {
-        unsafe {
-            // Safe to assume this here, as if it weren't true, we'd be breaking
-            // the contract anyway.
-            // This allows the null check to be elided in the destructor if we
-            // manipulated the reference count in the same function.
-            assume(!(*(&self._ptr as *const _ as *const *const ())).is_null());
-            &(**self._ptr)
-        }
-    }
-}
-#[cfg(not(stage0))]
 impl<T: ?Sized> RcBoxPtr<T> for Weak<T> {
     #[inline(always)]
     fn inner(&self) -> &RcBox<T> {