mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-30 13:06:28 +03:00
Always set result during finish() in debug builders
Most functions for format builders set `self.result` after writing strings. This ensures that any further writing fails immediately rather than trying to write again. A few `.finish()` methods did have this same behavior, so make it consistent here.
This commit is contained in:
@@ -402,6 +402,7 @@ fn is_pretty(&self) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
/// A helper used to print list-like items with no special formatting.
|
||||
struct DebugInner<'a, 'b: 'a> {
|
||||
fmt: &'a mut fmt::Formatter<'b>,
|
||||
result: fmt::Result,
|
||||
@@ -578,7 +579,8 @@ pub fn entries<D, I>(&mut self, entries: I) -> &mut Self
|
||||
/// ```
|
||||
#[stable(feature = "debug_builders", since = "1.2.0")]
|
||||
pub fn finish(&mut self) -> fmt::Result {
|
||||
self.inner.result.and_then(|_| self.inner.fmt.write_str("}"))
|
||||
self.inner.result = self.inner.result.and_then(|_| self.inner.fmt.write_str("}"));
|
||||
self.inner.result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -721,7 +723,8 @@ pub fn entries<D, I>(&mut self, entries: I) -> &mut Self
|
||||
/// ```
|
||||
#[stable(feature = "debug_builders", since = "1.2.0")]
|
||||
pub fn finish(&mut self) -> fmt::Result {
|
||||
self.inner.result.and_then(|_| self.inner.fmt.write_str("]"))
|
||||
self.inner.result = self.inner.result.and_then(|_| self.inner.fmt.write_str("]"));
|
||||
self.inner.result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1002,11 +1005,12 @@ pub fn entries<K, V, I>(&mut self, entries: I) -> &mut Self
|
||||
/// ```
|
||||
#[stable(feature = "debug_builders", since = "1.2.0")]
|
||||
pub fn finish(&mut self) -> fmt::Result {
|
||||
self.result.and_then(|_| {
|
||||
self.result = self.result.and_then(|_| {
|
||||
assert!(!self.has_key, "attempted to finish a map with a partial entry");
|
||||
|
||||
self.fmt.write_str("}")
|
||||
})
|
||||
});
|
||||
self.result
|
||||
}
|
||||
|
||||
fn is_pretty(&self) -> bool {
|
||||
|
||||
Reference in New Issue
Block a user