12
12
13
13
#![ stable( feature = "rust1" , since = "1.0.0" ) ]
14
14
15
+ #[ macro_use] #[ no_link] extern crate rustc_bitflags;
16
+
15
17
use prelude:: * ;
16
18
17
19
use cell:: { Cell , RefCell , Ref , RefMut , BorrowState } ;
@@ -198,9 +200,16 @@ impl<'a> ArgumentV1<'a> {
198
200
}
199
201
200
202
// flags available in the v1 format of format_args
201
- #[ derive( Copy , Clone ) ]
202
- #[ allow( dead_code) ] // SignMinus isn't currently used
203
- enum FlagV1 { SignPlus , SignMinus , Alternate , SignAwareZeroPad , }
203
+ bitflags ! {
204
+ #[ derive( Copy , Clone ) ]
205
+ #[ allow( dead_code) ] // SignMinus isn't currently used
206
+ flags FlagV1 : u32 {
207
+ const SignPlus = 1 << 0 ,
208
+ const SignMinus = 1 << 1 ,
209
+ const Alternate = 1 << 2 ,
210
+ const SignAwareZeroPad = 1 << 3 ,
211
+ }
212
+ }
204
213
205
214
impl < ' a > Arguments < ' a > {
206
215
/// When using the format_args!() macro, this function is used to generate the
@@ -472,12 +481,12 @@ impl<'a> Formatter<'a> {
472
481
let mut sign = None ;
473
482
if !is_positive {
474
483
sign = Some ( '-' ) ; width += 1 ;
475
- } else if self . flags & ( 1 << ( FlagV1 :: SignPlus as u32 ) ) != 0 {
484
+ } else if self . flags . contains ( FlagV1 :: SignPlus ) {
476
485
sign = Some ( '+' ) ; width += 1 ;
477
486
}
478
487
479
488
let mut prefixed = false ;
480
- if self . flags & ( 1 << ( FlagV1 :: Alternate as u32 ) ) != 0 {
489
+ if self . flags . contains ( FlagV1 :: Alternate ) {
481
490
prefixed = true ; width += prefix. char_len ( ) ;
482
491
}
483
492
@@ -507,7 +516,7 @@ impl<'a> Formatter<'a> {
507
516
}
508
517
// The sign and prefix goes before the padding if the fill character
509
518
// is zero
510
- Some ( min) if self . flags & ( 1 << ( FlagV1 :: SignAwareZeroPad as u32 ) ) != 0 => {
519
+ Some ( min) if self . flags . contains ( FlagV1 :: SignAwareZeroPad ) => {
511
520
self . fill = '0' ;
512
521
try!( write_prefix ( self ) ) ;
513
522
self . with_padding ( min - width, Alignment :: Right , |f| {
@@ -873,8 +882,8 @@ impl<T> Pointer for *const T {
873
882
// it denotes whether to prefix with 0x. We use it to work out whether
874
883
// or not to zero extend, and then unconditionally set it to get the
875
884
// prefix.
876
- if f. flags & 1 << ( FlagV1 :: Alternate as u32 ) > 0 {
877
- f. flags |= 1 << ( FlagV1 :: SignAwareZeroPad as u32 ) ;
885
+ if f. flags . contains ( FlagV1 :: Alternate ) {
886
+ f. flags . insert ( FlagV1 :: SignAwareZeroPad ) ;
878
887
879
888
if let None = f. width {
880
889
// The formats need two extra bytes, for the 0x
@@ -885,7 +894,7 @@ impl<T> Pointer for *const T {
885
894
}
886
895
}
887
896
}
888
- f. flags |= 1 << ( FlagV1 :: Alternate as u32 ) ;
897
+ f. flags . insert ( FlagV1 :: Alternate ) ;
889
898
890
899
let ret = LowerHex :: fmt ( & ( * self as usize ) , f) ;
891
900
0 commit comments