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()`.
This commit is contained in:
commit
c599463cd1
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user