Skip to content

Commit 9b889e5

Browse files
committed
Auto merge of rust-lang#103881 - ChayimFriedman2:patch-2, r=compiler-errors
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.
2 parents 6a4624d + d2eb2bb commit 9b889e5

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

library/core/src/cell.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,8 @@ impl<T> RefCell<T> {
807807
///
808808
/// # Panics
809809
///
810-
/// Panics if the value in either `RefCell` is currently borrowed.
810+
/// Panics if the value in either `RefCell` is currently borrowed, or
811+
/// if `self` and `other` point to the same `RefCell`.
811812
///
812813
/// # Examples
813814
///
@@ -1193,7 +1194,7 @@ impl<T: Default> Default for RefCell<T> {
11931194
impl<T: ?Sized + PartialEq> PartialEq for RefCell<T> {
11941195
/// # Panics
11951196
///
1196-
/// Panics if the value in either `RefCell` is currently borrowed.
1197+
/// Panics if the value in either `RefCell` is currently mutably borrowed.
11971198
#[inline]
11981199
fn eq(&self, other: &RefCell<T>) -> bool {
11991200
*self.borrow() == *other.borrow()
@@ -1207,39 +1208,39 @@ impl<T: ?Sized + Eq> Eq for RefCell<T> {}
12071208
impl<T: ?Sized + PartialOrd> PartialOrd for RefCell<T> {
12081209
/// # Panics
12091210
///
1210-
/// Panics if the value in either `RefCell` is currently borrowed.
1211+
/// Panics if the value in either `RefCell` is currently mutably borrowed.
12111212
#[inline]
12121213
fn partial_cmp(&self, other: &RefCell<T>) -> Option<Ordering> {
12131214
self.borrow().partial_cmp(&*other.borrow())
12141215
}
12151216

12161217
/// # Panics
12171218
///
1218-
/// Panics if the value in either `RefCell` is currently borrowed.
1219+
/// Panics if the value in either `RefCell` is currently mutably borrowed.
12191220
#[inline]
12201221
fn lt(&self, other: &RefCell<T>) -> bool {
12211222
*self.borrow() < *other.borrow()
12221223
}
12231224

12241225
/// # Panics
12251226
///
1226-
/// Panics if the value in either `RefCell` is currently borrowed.
1227+
/// Panics if the value in either `RefCell` is currently mutably borrowed.
12271228
#[inline]
12281229
fn le(&self, other: &RefCell<T>) -> bool {
12291230
*self.borrow() <= *other.borrow()
12301231
}
12311232

12321233
/// # Panics
12331234
///
1234-
/// Panics if the value in either `RefCell` is currently borrowed.
1235+
/// Panics if the value in either `RefCell` is currently mutably borrowed.
12351236
#[inline]
12361237
fn gt(&self, other: &RefCell<T>) -> bool {
12371238
*self.borrow() > *other.borrow()
12381239
}
12391240

12401241
/// # Panics
12411242
///
1242-
/// Panics if the value in either `RefCell` is currently borrowed.
1243+
/// Panics if the value in either `RefCell` is currently mutably borrowed.
12431244
#[inline]
12441245
fn ge(&self, other: &RefCell<T>) -> bool {
12451246
*self.borrow() >= *other.borrow()
@@ -1250,7 +1251,7 @@ impl<T: ?Sized + PartialOrd> PartialOrd for RefCell<T> {
12501251
impl<T: ?Sized + Ord> Ord for RefCell<T> {
12511252
/// # Panics
12521253
///
1253-
/// Panics if the value in either `RefCell` is currently borrowed.
1254+
/// Panics if the value in either `RefCell` is currently mutably borrowed.
12541255
#[inline]
12551256
fn cmp(&self, other: &RefCell<T>) -> Ordering {
12561257
self.borrow().cmp(&*other.borrow())

0 commit comments

Comments
 (0)