Skip to content

Rename is_positive argument in fmt::Formatter::pad_integral #30935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ impl<'a> Formatter<'a> {
///
/// # Arguments
///
/// * is_positive - whether the original integer was positive or not.
/// * is_nonnegative - whether the original integer was either positive or zero.
/// * prefix - if the '#' character (Alternate) is provided, this
/// is the prefix to put in front of the number.
/// * buf - the byte array that the number has been formatted into
Expand All @@ -861,7 +861,7 @@ impl<'a> Formatter<'a> {
/// the minimum width. It will not take precision into account.
#[stable(feature = "rust1", since = "1.0.0")]
pub fn pad_integral(&mut self,
is_positive: bool,
is_nonnegative: bool,
prefix: &str,
buf: &str)
-> Result {
Expand All @@ -870,7 +870,7 @@ impl<'a> Formatter<'a> {
let mut width = buf.len();

let mut sign = None;
if !is_positive {
if !is_nonnegative {
sign = Some('-'); width += 1;
} else if self.sign_plus() {
sign = Some('+'); width += 1;
Expand Down
12 changes: 6 additions & 6 deletions src/libcore/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ trait GenericRadix {
// The radix can be as low as 2, so we need a buffer of at least 64
// characters for a base 2 number.
let zero = T::zero();
let is_positive = x >= zero;
let is_nonnegative = x >= zero;
let mut buf = [0; 64];
let mut curr = buf.len();
let base = T::from_u8(self.base());
if is_positive {
if is_nonnegative {
// Accumulate each digit of the number from the least significant
// to the most significant figure.
for byte in buf.iter_mut().rev() {
Expand All @@ -91,7 +91,7 @@ trait GenericRadix {
}
}
let buf = unsafe { str::from_utf8_unchecked(&buf[curr..]) };
f.pad_integral(is_positive, self.prefix(), buf)
f.pad_integral(is_nonnegative, self.prefix(), buf)
}
}

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