From f9f5c03026ebd2c5ee6f0cba3878c08d157da9cb Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Thu, 20 Nov 2014 11:20:10 +0100 Subject: [PATCH] Add comment on why `RefCell::unwrap` is safe --- src/libcore/cell.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 0b7389b20190c..c4d0bec83eaa7 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -258,6 +258,9 @@ impl RefCell { /// Consumes the `RefCell`, returning the wrapped value. #[unstable = "may be renamed, depending on global conventions"] pub fn unwrap(self) -> T { + // Since this function takes `self` (the `RefCell`) by value, the + // compiler statically verifies that it is not currently borrowed. + // Therefore the following assertion is just a `debug_assert!`. debug_assert!(self.borrow.get() == UNUSED); unsafe{self.value.unwrap()} }