diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 0178b321e88c..58361614525a 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -12,6 +12,8 @@ #![stable(feature = "rust1", since = "1.0.0")] +#[macro_use] #[no_link] extern crate rustc_bitflags; + use prelude::*; use cell::{Cell, RefCell, Ref, RefMut, BorrowState}; @@ -198,9 +200,16 @@ impl<'a> ArgumentV1<'a> { } // flags available in the v1 format of format_args -#[derive(Copy, Clone)] -#[allow(dead_code)] // SignMinus isn't currently used -enum FlagV1 { SignPlus, SignMinus, Alternate, SignAwareZeroPad, } +bitflags! { + #[derive(Copy, Clone)] + #[allow(dead_code)] // SignMinus isn't currently used + flags FlagV1 : u32 { + const SignPlus = 1 << 0, + const SignMinus = 1 << 1, + const Alternate = 1 << 2, + const SignAwareZeroPad = 1 << 3, + } +} impl<'a> Arguments<'a> { /// When using the format_args!() macro, this function is used to generate the @@ -472,12 +481,12 @@ impl<'a> Formatter<'a> { let mut sign = None; if !is_positive { sign = Some('-'); width += 1; - } else if self.flags & (1 << (FlagV1::SignPlus as u32)) != 0 { + } else if self.flags.contains(FlagV1::SignPlus) { sign = Some('+'); width += 1; } let mut prefixed = false; - if self.flags & (1 << (FlagV1::Alternate as u32)) != 0 { + if self.flags.contains(FlagV1::Alternate) { prefixed = true; width += prefix.char_len(); } @@ -507,7 +516,7 @@ impl<'a> Formatter<'a> { } // The sign and prefix goes before the padding if the fill character // is zero - Some(min) if self.flags & (1 << (FlagV1::SignAwareZeroPad as u32)) != 0 => { + Some(min) if self.flags.contains(FlagV1::SignAwareZeroPad) => { self.fill = '0'; try!(write_prefix(self)); self.with_padding(min - width, Alignment::Right, |f| { @@ -873,8 +882,8 @@ impl Pointer for *const T { // it denotes whether to prefix with 0x. We use it to work out whether // or not to zero extend, and then unconditionally set it to get the // prefix. - if f.flags & 1 << (FlagV1::Alternate as u32) > 0 { - f.flags |= 1 << (FlagV1::SignAwareZeroPad as u32); + if f.flags.contains(FlagV1::Alternate) { + f.flags.insert(FlagV1::SignAwareZeroPad); if let None = f.width { // The formats need two extra bytes, for the 0x @@ -885,7 +894,7 @@ impl Pointer for *const T { } } } - f.flags |= 1 << (FlagV1::Alternate as u32); + f.flags.insert(FlagV1::Alternate); let ret = LowerHex::fmt(&(*self as usize), f);