mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 22:41:50 +00:00
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.
This commit is contained in:
commit
ff21ccfba1
@ -1819,7 +1819,7 @@ impl<'a> Formatter<'a> {
|
||||
/// write!(formatter,
|
||||
/// "Foo({}{})",
|
||||
/// if self.0 < 0 { '-' } else { '+' },
|
||||
/// self.0)
|
||||
/// self.0.abs())
|
||||
/// } else {
|
||||
/// write!(formatter, "Foo({})", self.0)
|
||||
/// }
|
||||
@ -1827,6 +1827,7 @@ impl<'a> Formatter<'a> {
|
||||
/// }
|
||||
///
|
||||
/// assert_eq!(&format!("{:+}", Foo(23)), "Foo(+23)");
|
||||
/// assert_eq!(&format!("{:+}", Foo(-23)), "Foo(-23)");
|
||||
/// assert_eq!(&format!("{}", Foo(23)), "Foo(23)");
|
||||
/// ```
|
||||
#[must_use]
|
||||
|
Loading…
Reference in New Issue
Block a user