about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-05-24 10:02:55 +0000
committerbors <bors@rust-lang.org>2021-05-24 10:02:55 +0000
commit6f6919231e405cea114fbd6872b25c3614ee38f0 (patch)
tree3d9a2e3cc11d3ec95f913a8c9f4ef8c6d6a30b69
parent68424e2f01ef6884af440114f7cf2ed01faf86e3 (diff)
parent7c0db6f0f178334ca6e1fdfdfed25fb89daf568b (diff)
downloadrust-6f6919231e405cea114fbd6872b25c3614ee38f0.tar.gz
rust-6f6919231e405cea114fbd6872b25c3614ee38f0.zip
Auto merge of #85601 - klensy:padint-example-fix, r=dtolnay
fix pad_integral example

pad_integral's parameter `is_nonnegative - whether the original integer was either positive or zero`, but in example it checked as `self.nb > 0`, so it previously printed `-0` for `format!("{}", Foo::new(0)`, what is wrong.
-rw-r--r--library/core/src/fmt/mod.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs
index afef790ca64..02ac4fb8006 100644
--- a/library/core/src/fmt/mod.rs
+++ b/library/core/src/fmt/mod.rs
@@ -1245,12 +1245,13 @@ impl<'a> Formatter<'a> {
     ///         // We need to remove "-" from the number output.
     ///         let tmp = self.nb.abs().to_string();
     ///
-    ///         formatter.pad_integral(self.nb > 0, "Foo ", &tmp)
+    ///         formatter.pad_integral(self.nb >= 0, "Foo ", &tmp)
     ///     }
     /// }
     ///
     /// assert_eq!(&format!("{}", Foo::new(2)), "2");
     /// assert_eq!(&format!("{}", Foo::new(-1)), "-1");
+    /// assert_eq!(&format!("{}", Foo::new(0)), "0");
     /// assert_eq!(&format!("{:#}", Foo::new(-1)), "-Foo 1");
     /// assert_eq!(&format!("{:0>#8}", Foo::new(-1)), "00-Foo 1");
     /// ```