Skip to content

Commit 81d470f

Browse files
Improve code by using wrapping_neg
1 parent d318878 commit 81d470f

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

Diff for: library/core/src/fmt/num.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,13 @@ macro_rules! impl_Display {
219219
#[stable(feature = "rust1", since = "1.0.0")]
220220
impl fmt::Display for $signed {
221221
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
222-
let is_nonnegative = *self >= 0;
223-
224-
if !is_nonnegative {
222+
if *self < 0 {
225223
#[cfg(not(feature = "optimize_for_size"))]
226224
{
227-
// convert the negative num to positive by summing 1 to its 2s complement
228225
return (!self as $unsigned).wrapping_add(1)._fmt(false, f);
229226
}
230227
#[cfg(feature = "optimize_for_size")]
231228
{
232-
// convert the negative num to positive by summing 1 to its 2s complement
233229
return $gen_name((!self.$conv_fn()).wrapping_add(1), false, f);
234230
}
235231
}

0 commit comments

Comments
 (0)