Skip to content

Commit bde8555

Browse files
committed
RefCell: document panics in Clone, PartialEq, PartialOrd, Ord. Fixes rust-lang#47400
1 parent 27a046e commit bde8555

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/libcore/cell.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,9 @@ impl<T: ?Sized> !Sync for RefCell<T> {}
863863

864864
#[stable(feature = "rust1", since = "1.0.0")]
865865
impl<T: Clone> Clone for RefCell<T> {
866+
/// # Panics
867+
///
868+
/// Panics if the value is currently mutably borrowed.
866869
#[inline]
867870
fn clone(&self) -> RefCell<T> {
868871
RefCell::new(self.borrow().clone())
@@ -880,6 +883,9 @@ impl<T:Default> Default for RefCell<T> {
880883

881884
#[stable(feature = "rust1", since = "1.0.0")]
882885
impl<T: ?Sized + PartialEq> PartialEq for RefCell<T> {
886+
/// # Panics
887+
///
888+
/// Panics if the value is currently mutably borrowed.
883889
#[inline]
884890
fn eq(&self, other: &RefCell<T>) -> bool {
885891
*self.borrow() == *other.borrow()
@@ -891,26 +897,41 @@ impl<T: ?Sized + Eq> Eq for RefCell<T> {}
891897

892898
#[stable(feature = "cell_ord", since = "1.10.0")]
893899
impl<T: ?Sized + PartialOrd> PartialOrd for RefCell<T> {
900+
/// # Panics
901+
///
902+
/// Panics if the value is currently mutably borrowed.
894903
#[inline]
895904
fn partial_cmp(&self, other: &RefCell<T>) -> Option<Ordering> {
896905
self.borrow().partial_cmp(&*other.borrow())
897906
}
898907

908+
/// # Panics
909+
///
910+
/// Panics if the value is currently mutably borrowed.
899911
#[inline]
900912
fn lt(&self, other: &RefCell<T>) -> bool {
901913
*self.borrow() < *other.borrow()
902914
}
903915

916+
/// # Panics
917+
///
918+
/// Panics if the value is currently mutably borrowed.
904919
#[inline]
905920
fn le(&self, other: &RefCell<T>) -> bool {
906921
*self.borrow() <= *other.borrow()
907922
}
908923

924+
/// # Panics
925+
///
926+
/// Panics if the value is currently mutably borrowed.
909927
#[inline]
910928
fn gt(&self, other: &RefCell<T>) -> bool {
911929
*self.borrow() > *other.borrow()
912930
}
913931

932+
/// # Panics
933+
///
934+
/// Panics if the value is currently mutably borrowed.
914935
#[inline]
915936
fn ge(&self, other: &RefCell<T>) -> bool {
916937
*self.borrow() >= *other.borrow()
@@ -919,6 +940,9 @@ impl<T: ?Sized + PartialOrd> PartialOrd for RefCell<T> {
919940

920941
#[stable(feature = "cell_ord", since = "1.10.0")]
921942
impl<T: ?Sized + Ord> Ord for RefCell<T> {
943+
/// # Panics
944+
///
945+
/// Panics if the value is currently mutably borrowed.
922946
#[inline]
923947
fn cmp(&self, other: &RefCell<T>) -> Ordering {
924948
self.borrow().cmp(&*other.borrow())

0 commit comments

Comments
 (0)