about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorchangchun.fan <changchun.fan@gmail.com>2016-08-22 15:37:08 +0800
committerfcc <changchun.fan@qq.com>2016-08-26 09:13:59 +0800
commitf4c55dd08f8e02145d28f2ccdc07cf3e9d9ffc1b (patch)
tree96277b65cf99268faa70f7719f3e72e75ec6ff16 /src/libcore
parent71bdeea561355ba5adbc9a1f44f4f866a75a15c4 (diff)
downloadrust-f4c55dd08f8e02145d28f2ccdc07cf3e9d9ffc1b.tar.gz
rust-f4c55dd08f8e02145d28f2ccdc07cf3e9d9ffc1b.zip
Fix documentation in cell mod
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/cell.rs49
1 files changed, 39 insertions, 10 deletions
diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs
index 2af48ef2fab..9b8c1be231a 100644
--- a/src/libcore/cell.rs
+++ b/src/libcore/cell.rs
@@ -119,26 +119,55 @@
 //! `Cell<T>`.
 //!
 //! ```
+//! #![feature(core_intrinsics)]
+//! #![feature(shared)]
 //! use std::cell::Cell;
+//! use std::ptr::Shared;
+//! use std::intrinsics::abort;
+//! use std::intrinsics::assume;
 //!
-//! struct Rc<T> {
-//!     ptr: *mut RcBox<T>
+//! struct Rc<T: ?Sized> {
+//!     ptr: Shared<RcBox<T>>
 //! }
 //!
-//! struct RcBox<T> {
-//! # #[allow(dead_code)]
+//! struct RcBox<T: ?Sized> {
+//!     strong: Cell<usize>,
+//!     refcount: Cell<usize>,
 //!     value: T,
-//!     refcount: Cell<usize>
 //! }
 //!
-//! impl<T> Clone for Rc<T> {
+//! impl<T: ?Sized> Clone for Rc<T> {
 //!     fn clone(&self) -> Rc<T> {
-//!         unsafe {
-//!             (*self.ptr).refcount.set((*self.ptr).refcount.get() + 1);
-//!             Rc { ptr: self.ptr }
-//!         }
+//!         self.inc_strong();
+//!         Rc { ptr: self.ptr }
+//!     }
+//! }
+//!
+//! trait RcBoxPtr<T: ?Sized> {
+//!
+//!     fn inner(&self) -> &RcBox<T>;
+//!
+//!     fn strong(&self) -> usize {
+//!         self.inner().strong.get()
+//!     }
+//!
+//!     fn inc_strong(&self) {
+//!         self.inner()
+//!             .strong
+//!             .set(self.strong()
+//!                      .checked_add(1)
+//!                      .unwrap_or_else(|| unsafe { abort() }));
 //!     }
 //! }
+//!
+//! impl<T: ?Sized> RcBoxPtr<T> for Rc<T> {
+//!    fn inner(&self) -> &RcBox<T> {
+//!        unsafe {
+//!            assume(!(*(&self.ptr as *const _ as *const *const ())).is_null());
+//!            &(**self.ptr)
+//!        }
+//!    }
+//! }
 //! ```
 //!