about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-01-01 06:36:24 +0000
committerbors <bors@rust-lang.org>2015-01-01 06:36:24 +0000
commitc594959cdff07b5545747809bb045bfa2868ebcc (patch)
tree513aa126d93284020db5f97fd32ed45b0e0f26af /src/libcore
parent47b8479e73e40395f1b1b2d0c6281f28f80301e4 (diff)
parentf0976e2cf3f6b0027f118b791e0888b29fbb41a7 (diff)
downloadrust-c594959cdff07b5545747809bb045bfa2868ebcc.tar.gz
rust-c594959cdff07b5545747809bb045bfa2868ebcc.zip
auto merge of #19388 : nick29581/rust/rc-show, r=alexcrichto
r? @huonw or @alexcrichton

Apparently, we have previously rejected an RFC like this. However, since then we removed `{:?}` and so without this debugging gets really difficult as soon as there is a RefCell anywhere, so I believe there is more benefit to adding these impls than there was before. By using "try_borrow" we can avoid panicing in `Show` (I think).

@ huon in response to a comment in #19254: I noticed that `drop()` checks for the ptr being null, so I checked here too. Now I am checking for both, if you're confident I can change to only checking `strong()`.

Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/cell.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs
index 6249f7600cd..4b246860006 100644
--- a/src/libcore/cell.rs
+++ b/src/libcore/cell.rs
@@ -158,6 +158,7 @@
 use clone::Clone;
 use cmp::PartialEq;
 use default::Default;
+use fmt;
 use kinds::{Copy, Send};
 use ops::{Deref, DerefMut, Drop};
 use option::Option;
@@ -365,6 +366,16 @@ impl<T: PartialEq> PartialEq for RefCell<T> {
     }
 }
 
+#[unstable]
+impl<T:fmt::Show> fmt::Show for RefCell<T> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match self.try_borrow() {
+            Some(val) => write!(f, "{}", val),
+            None => write!(f, "<borrowed RefCell>")
+        }
+    }
+}
+
 struct BorrowRef<'b> {
     _borrow: &'b Cell<BorrowFlag>,
 }