Skip to content

Commit 797f260

Browse files
authored
Rollup merge of #101529 - mousetail:patch-2, r=thomcc
Fix the example code and doctest for Formatter::sign_plus The provided example to the `sign_plus` method on `fmt` was broken, it displays the `-` sign twice for negative numbers. This pull request should fix the issue by `.abs()` ing the number so that the negative sign appears only once. It is just one possible solution to the issue, not sure if it's the best. However, this one will behave as expected when combined with fill and alignment operators.
2 parents 7365356 + b0925d8 commit 797f260

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

core/src/fmt/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1819,14 +1819,15 @@ impl<'a> Formatter<'a> {
18191819
/// write!(formatter,
18201820
/// "Foo({}{})",
18211821
/// if self.0 < 0 { '-' } else { '+' },
1822-
/// self.0)
1822+
/// self.0.abs())
18231823
/// } else {
18241824
/// write!(formatter, "Foo({})", self.0)
18251825
/// }
18261826
/// }
18271827
/// }
18281828
///
18291829
/// assert_eq!(&format!("{:+}", Foo(23)), "Foo(+23)");
1830+
/// assert_eq!(&format!("{:+}", Foo(-23)), "Foo(-23)");
18301831
/// assert_eq!(&format!("{}", Foo(23)), "Foo(23)");
18311832
/// ```
18321833
#[must_use]

0 commit comments

Comments
 (0)