Skip to content

Commit

Permalink
Rollup merge of rust-lang#35895 - F001:patch-1, r=steveklabnik
Browse files Browse the repository at this point in the history
Fix documentation in cell mod

The implementation of Rc type in this doc is outdated.
  • Loading branch information
GuillaumeGomez authored Aug 30, 2016
2 parents f4b7d78 + f4c55dd commit 290095d
Showing 1 changed file with 39 additions and 10 deletions.
49 changes: 39 additions & 10 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
//! }
//! }
//! }
//! ```
//!
Expand Down

0 comments on commit 290095d

Please sign in to comment.