Skip to content

Commit e5d8bc2

Browse files
committed
Auto merge of rust-lang#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.
2 parents 5c22587 + cc30169 commit e5d8bc2

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

core/src/fmt/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1245,12 +1245,13 @@ impl<'a> Formatter<'a> {
12451245
/// // We need to remove "-" from the number output.
12461246
/// let tmp = self.nb.abs().to_string();
12471247
///
1248-
/// formatter.pad_integral(self.nb > 0, "Foo ", &tmp)
1248+
/// formatter.pad_integral(self.nb >= 0, "Foo ", &tmp)
12491249
/// }
12501250
/// }
12511251
///
12521252
/// assert_eq!(&format!("{}", Foo::new(2)), "2");
12531253
/// assert_eq!(&format!("{}", Foo::new(-1)), "-1");
1254+
/// assert_eq!(&format!("{}", Foo::new(0)), "0");
12541255
/// assert_eq!(&format!("{:#}", Foo::new(-1)), "-Foo 1");
12551256
/// assert_eq!(&format!("{:0>#8}", Foo::new(-1)), "00-Foo 1");
12561257
/// ```

0 commit comments

Comments
 (0)