diff options
Diffstat (limited to 'library/core/src/fmt')
-rw-r--r-- | library/core/src/fmt/builders.rs | 6 | ||||
-rw-r--r-- | library/core/src/fmt/mod.rs | 20 |
2 files changed, 8 insertions, 18 deletions
diff --git a/library/core/src/fmt/builders.rs b/library/core/src/fmt/builders.rs index 36f49d51c..d2c9f9800 100644 --- a/library/core/src/fmt/builders.rs +++ b/library/core/src/fmt/builders.rs @@ -518,7 +518,7 @@ impl<'a, 'b: 'a> DebugSet<'a, 'b> { /// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { /// fmt.debug_set() /// .entries(self.0.iter()) - /// .finish() // Ends the struct formatting. + /// .finish() // Ends the set formatting. /// } /// } /// @@ -648,7 +648,7 @@ impl<'a, 'b: 'a> DebugList<'a, 'b> { /// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { /// fmt.debug_list() /// .entries(self.0.iter()) - /// .finish() // Ends the struct formatting. + /// .finish() // Ends the list formatting. /// } /// } /// @@ -905,7 +905,7 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> { /// fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { /// fmt.debug_map() /// .entries(self.0.iter().map(|&(ref k, ref v)| (k, v))) - /// .finish() // Ends the struct formatting. + /// .finish() // Ends the map formatting. /// } /// } /// diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 1786b309c..9ce6093f1 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -2521,22 +2521,12 @@ impl<T: Copy + Debug> Debug for Cell<T> { #[stable(feature = "rust1", since = "1.0.0")] impl<T: ?Sized + Debug> Debug for RefCell<T> { fn fmt(&self, f: &mut Formatter<'_>) -> Result { + let mut d = f.debug_struct("RefCell"); match self.try_borrow() { - Ok(borrow) => f.debug_struct("RefCell").field("value", &borrow).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("<borrowed>") - } - } - - f.debug_struct("RefCell").field("value", &BorrowedPlaceholder).finish() - } - } + Ok(borrow) => d.field("value", &borrow), + Err(_) => d.field("value", &format_args!("<borrowed>")), + }; + d.finish() } } |