From deed093a38243ced1f52927ebf7511c099a3bf36 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 1 Feb 2015 18:53:47 -0800 Subject: std: Deprecate RefCell::{try_borrow, try_borrow_mut} The existence of these two functions is at odds with our current [error conventions][conventions] which recommend that panicking and `Result`-like variants should not be provided together. [conventions]: https://github.com/rust-lang/rfcs/blob/master/text/0236-error-conventions.md#do-not-provide-both-result-and-fail-variants This commit adds a new `borrow_state` function returning a `BorrowState` enum to `RefCell` which serves as a replacemnt for the `try_borrow` and `try_borrow_mut` functions. --- src/libcoretest/cell.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/libcoretest') diff --git a/src/libcoretest/cell.rs b/src/libcoretest/cell.rs index 5815dbc0acc..8939bd61fe4 100644 --- a/src/libcoretest/cell.rs +++ b/src/libcoretest/cell.rs @@ -60,6 +60,7 @@ fn no_mut_then_imm_borrow() { let x = RefCell::new(0); let _b1 = x.borrow_mut(); assert!(x.try_borrow().is_none()); + assert_eq!(x.borrow_state(), BorrowState::Writing); } #[test] @@ -67,13 +68,16 @@ fn no_imm_then_borrow_mut() { let x = RefCell::new(0); let _b1 = x.borrow(); assert!(x.try_borrow_mut().is_none()); + assert_eq!(x.borrow_state(), BorrowState::Reading); } #[test] fn no_double_borrow_mut() { let x = RefCell::new(0); + assert_eq!(x.borrow_state(), BorrowState::Unused); let _b1 = x.borrow_mut(); assert!(x.try_borrow_mut().is_none()); + assert_eq!(x.borrow_state(), BorrowState::Writing); } #[test] -- cgit 1.4.1-3-g733a5