Skip to content

Commit

Permalink
Auto merge of #103881 - ChayimFriedman2:patch-2, r=compiler-errors
Browse files Browse the repository at this point in the history
Clarify docs of `RefCell`

Comparison operators only panic if the `RefCell` is mutably borrowed, and `RefCell::swap()` can also panic if swapping a `RefCell` with itself.
  • Loading branch information
bors committed Dec 28, 2022
2 parents 6a4624d + d2eb2bb commit 9b889e5
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions library/core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,8 @@ impl<T> RefCell<T> {
///
/// # Panics
///
/// Panics if the value in either `RefCell` is currently borrowed.
/// Panics if the value in either `RefCell` is currently borrowed, or
/// if `self` and `other` point to the same `RefCell`.
///
/// # Examples
///
Expand Down Expand Up @@ -1193,7 +1194,7 @@ impl<T: Default> Default for RefCell<T> {
impl<T: ?Sized + PartialEq> PartialEq for RefCell<T> {
/// # Panics
///
/// Panics if the value in either `RefCell` is currently borrowed.
/// Panics if the value in either `RefCell` is currently mutably borrowed.
#[inline]
fn eq(&self, other: &RefCell<T>) -> bool {
*self.borrow() == *other.borrow()
Expand All @@ -1207,39 +1208,39 @@ impl<T: ?Sized + Eq> Eq for RefCell<T> {}
impl<T: ?Sized + PartialOrd> PartialOrd for RefCell<T> {
/// # Panics
///
/// Panics if the value in either `RefCell` is currently borrowed.
/// Panics if the value in either `RefCell` is currently mutably 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.
/// Panics if the value in either `RefCell` is currently mutably borrowed.
#[inline]
fn lt(&self, other: &RefCell<T>) -> bool {
*self.borrow() < *other.borrow()
}

/// # Panics
///
/// Panics if the value in either `RefCell` is currently borrowed.
/// Panics if the value in either `RefCell` is currently mutably borrowed.
#[inline]
fn le(&self, other: &RefCell<T>) -> bool {
*self.borrow() <= *other.borrow()
}

/// # Panics
///
/// Panics if the value in either `RefCell` is currently borrowed.
/// Panics if the value in either `RefCell` is currently mutably borrowed.
#[inline]
fn gt(&self, other: &RefCell<T>) -> bool {
*self.borrow() > *other.borrow()
}

/// # Panics
///
/// Panics if the value in either `RefCell` is currently borrowed.
/// Panics if the value in either `RefCell` is currently mutably borrowed.
#[inline]
fn ge(&self, other: &RefCell<T>) -> bool {
*self.borrow() >= *other.borrow()
Expand All @@ -1250,7 +1251,7 @@ impl<T: ?Sized + PartialOrd> PartialOrd for RefCell<T> {
impl<T: ?Sized + Ord> Ord for RefCell<T> {
/// # Panics
///
/// Panics if the value in either `RefCell` is currently borrowed.
/// Panics if the value in either `RefCell` is currently mutably borrowed.
#[inline]
fn cmp(&self, other: &RefCell<T>) -> Ordering {
self.borrow().cmp(&*other.borrow())
Expand Down

0 comments on commit 9b889e5

Please sign in to comment.