From f9d92d219d266c3161367cc694743e9c0e6d55c7 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 21 Sep 2017 21:52:59 -0700 Subject: Less confusing placeholder when RefCell is exclusively borrowed Based on ExpHP's comment in https://users.rust-lang.org/t/refcell-borrow-mut-get-strange-result/12994 > it would perhaps be nicer if it didn't put something that could be > misinterpreted as a valid string value The previous Debug implementation would show: RefCell { value: "" } The new one is: RefCell { value: } --- src/libcore/fmt/mod.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/libcore') diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index cf6262bda97..b84a1deb611 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -1700,8 +1700,18 @@ impl Debug for RefCell { .finish() } Err(_) => { + // The RefCell is mutably borrowed so we can't look at its value + // here. Show a placeholder instead. + struct BorrowedPlaceholder; + + impl Debug for BorrowedPlaceholder { + fn fmt(&self, f: &mut Formatter) -> Result { + f.write_str("") + } + } + f.debug_struct("RefCell") - .field("value", &"") + .field("value", &BorrowedPlaceholder) .finish() } } -- cgit 1.4.1-3-g733a5