Skip to content

Commit 8e12365

Browse files
committed
Auto merge of rust-lang#30935 - ollie27:pad_int, r=alexcrichton
The function expects a value of true for zero but zero is not positive.
2 parents 83c3b7f + b31df78 commit 8e12365

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/libcore/fmt/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ impl<'a> Formatter<'a> {
852852
///
853853
/// # Arguments
854854
///
855-
/// * is_positive - whether the original integer was positive or not.
855+
/// * is_nonnegative - whether the original integer was either positive or zero.
856856
/// * prefix - if the '#' character (Alternate) is provided, this
857857
/// is the prefix to put in front of the number.
858858
/// * buf - the byte array that the number has been formatted into
@@ -861,7 +861,7 @@ impl<'a> Formatter<'a> {
861861
/// the minimum width. It will not take precision into account.
862862
#[stable(feature = "rust1", since = "1.0.0")]
863863
pub fn pad_integral(&mut self,
864-
is_positive: bool,
864+
is_nonnegative: bool,
865865
prefix: &str,
866866
buf: &str)
867867
-> Result {
@@ -870,7 +870,7 @@ impl<'a> Formatter<'a> {
870870
let mut width = buf.len();
871871

872872
let mut sign = None;
873-
if !is_positive {
873+
if !is_nonnegative {
874874
sign = Some('-'); width += 1;
875875
} else if self.sign_plus() {
876876
sign = Some('+'); width += 1;

src/libcore/fmt/num.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ trait GenericRadix {
6060
// The radix can be as low as 2, so we need a buffer of at least 64
6161
// characters for a base 2 number.
6262
let zero = T::zero();
63-
let is_positive = x >= zero;
63+
let is_nonnegative = x >= zero;
6464
let mut buf = [0; 64];
6565
let mut curr = buf.len();
6666
let base = T::from_u8(self.base());
67-
if is_positive {
67+
if is_nonnegative {
6868
// Accumulate each digit of the number from the least significant
6969
// to the most significant figure.
7070
for byte in buf.iter_mut().rev() {
@@ -91,7 +91,7 @@ trait GenericRadix {
9191
}
9292
}
9393
let buf = unsafe { str::from_utf8_unchecked(&buf[curr..]) };
94-
f.pad_integral(is_positive, self.prefix(), buf)
94+
f.pad_integral(is_nonnegative, self.prefix(), buf)
9595
}
9696
}
9797

@@ -268,8 +268,8 @@ macro_rules! impl_Display {
268268
impl fmt::Display for $t {
269269
#[allow(unused_comparisons)]
270270
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
271-
let is_positive = *self >= 0;
272-
let mut n = if is_positive {
271+
let is_nonnegative = *self >= 0;
272+
let mut n = if is_nonnegative {
273273
self.$conv_fn()
274274
} else {
275275
// convert the negative num to positive by summing 1 to it's 2 complement
@@ -321,7 +321,7 @@ macro_rules! impl_Display {
321321
str::from_utf8_unchecked(
322322
slice::from_raw_parts(buf_ptr.offset(curr), buf.len() - curr as usize))
323323
};
324-
f.pad_integral(is_positive, "", buf_slice)
324+
f.pad_integral(is_nonnegative, "", buf_slice)
325325
}
326326
})*);
327327
}

0 commit comments

Comments
 (0)