diff options
| author | kennytm <kennytm@gmail.com> | 2018-02-28 19:15:29 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-28 19:15:29 +0800 |
| commit | c599463cd165d7ec01ba37c6979d1e7109cf9d3a (patch) | |
| tree | 664e18a2c2c35f68026b85407bef1482d2a080e7 /src/libcore | |
| parent | 85d7d0bf561c278123e288bffbe4b3baf843742b (diff) | |
| parent | f8ebb3f09fa98cf5583f6bd8d5677a1f4dd0941d (diff) | |
Rollup merge of #48365 - Centril:docs/document-refcell-panics, r=frewsxcv
RefCell: document panics in Clone, PartialEq, PartialOrd, Ord.
This fixes #47400 by adding:
```rust
/// # Panics
///
/// Panics if the value is currently mutably borrowed.
```
to said impls. They may panic since they call `.borrow()`.
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/cell.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index ec0d1b704dc..419ae96b94b 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -863,6 +863,9 @@ impl<T: ?Sized> !Sync for RefCell<T> {} #[stable(feature = "rust1", since = "1.0.0")] impl<T: Clone> Clone for RefCell<T> { + /// # Panics + /// + /// Panics if the value is currently mutably borrowed. #[inline] fn clone(&self) -> RefCell<T> { RefCell::new(self.borrow().clone()) @@ -880,6 +883,9 @@ impl<T:Default> Default for RefCell<T> { #[stable(feature = "rust1", since = "1.0.0")] impl<T: ?Sized + PartialEq> PartialEq for RefCell<T> { + /// # Panics + /// + /// Panics if the value in either `RefCell` is currently borrowed. #[inline] fn eq(&self, other: &RefCell<T>) -> bool { *self.borrow() == *other.borrow() @@ -891,26 +897,41 @@ impl<T: ?Sized + Eq> Eq for RefCell<T> {} #[stable(feature = "cell_ord", since = "1.10.0")] impl<T: ?Sized + PartialOrd> PartialOrd for RefCell<T> { + /// # Panics + /// + /// Panics if the value in either `RefCell` is currently borrowed. #[inline] fn partial_cmp(&self, other: &RefCell<T>) -> Option<Ordering> { self.borrow().partial_cmp(&*other.borrow()) } + /// # Panics + /// + /// Panics if the value in either `RefCell` is currently borrowed. #[inline] fn lt(&self, other: &RefCell<T>) -> bool { *self.borrow() < *other.borrow() } + /// # Panics + /// + /// Panics if the value in either `RefCell` is currently borrowed. #[inline] fn le(&self, other: &RefCell<T>) -> bool { *self.borrow() <= *other.borrow() } + /// # Panics + /// + /// Panics if the value in either `RefCell` is currently borrowed. #[inline] fn gt(&self, other: &RefCell<T>) -> bool { *self.borrow() > *other.borrow() } + /// # Panics + /// + /// Panics if the value in either `RefCell` is currently borrowed. #[inline] fn ge(&self, other: &RefCell<T>) -> bool { *self.borrow() >= *other.borrow() @@ -919,6 +940,9 @@ impl<T: ?Sized + PartialOrd> PartialOrd for RefCell<T> { #[stable(feature = "cell_ord", since = "1.10.0")] impl<T: ?Sized + Ord> Ord for RefCell<T> { + /// # Panics + /// + /// Panics if the value in either `RefCell` is currently borrowed. #[inline] fn cmp(&self, other: &RefCell<T>) -> Ordering { self.borrow().cmp(&*other.borrow()) |
