@@ -126,7 +126,7 @@ pub trait Write {
126
126
/// traits.
127
127
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
128
128
pub struct Formatter < ' a > {
129
- flags : u32 ,
129
+ flags : FlagV1 ,
130
130
fill : char ,
131
131
align : rt:: v1:: Alignment ,
132
132
width : Option < usize > ,
@@ -193,10 +193,21 @@ impl<'a> ArgumentV1<'a> {
193
193
}
194
194
}
195
195
196
- // flags available in the v1 format of format_args
197
- #[ derive( Copy , Clone ) ]
198
- #[ allow( dead_code) ] // SignMinus isn't currently used
199
- enum FlagV1 { SignPlus , SignMinus , Alternate , SignAwareZeroPad , }
196
+ bitflags ! {
197
+ // flags available in the v1 format of format_args
198
+ #[ doc( hidden) ]
199
+ flags FlagV1 : u32 {
200
+ #[ doc( hidden) ]
201
+ const SIGNPLUS = 1 << 0 ,
202
+ #[ doc( hidden) ]
203
+ #[ allow( dead_code) ] // SIGNMINUS isn't currently used
204
+ const SIGNMINUS = 1 << 1 ,
205
+ #[ doc( hidden) ]
206
+ const ALTERNATE = 1 << 2 ,
207
+ #[ doc( hidden) ]
208
+ const SIGNAWAREZEROPAD = 1 << 3 ,
209
+ }
210
+ }
200
211
201
212
impl < ' a > Arguments < ' a > {
202
213
/// When using the format_args!() macro, this function is used to generate the
@@ -360,7 +371,7 @@ pub trait UpperExp {
360
371
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
361
372
pub fn write ( output : & mut Write , args : Arguments ) -> Result {
362
373
let mut formatter = Formatter {
363
- flags : 0 ,
374
+ flags : FlagV1 :: empty ( ) ,
364
375
width : None ,
365
376
precision : None ,
366
377
buf : output,
@@ -410,7 +421,7 @@ impl<'a> Formatter<'a> {
410
421
// Fill in the format parameters into the formatter
411
422
self . fill = arg. format . fill ;
412
423
self . align = arg. format . align ;
413
- self . flags = arg. format . flags ;
424
+ self . flags = FlagV1 :: from_bits_truncate ( arg. format . flags ) ;
414
425
self . width = self . getcount ( & arg. format . width ) ;
415
426
self . precision = self . getcount ( & arg. format . precision ) ;
416
427
@@ -466,12 +477,12 @@ impl<'a> Formatter<'a> {
466
477
let mut sign = None ;
467
478
if !is_positive {
468
479
sign = Some ( '-' ) ; width += 1 ;
469
- } else if self . flags & ( 1 << ( FlagV1 :: SignPlus as u32 ) ) != 0 {
480
+ } else if self . flags . intersects ( FlagV1 :: SIGNPLUS ) {
470
481
sign = Some ( '+' ) ; width += 1 ;
471
482
}
472
483
473
484
let mut prefixed = false ;
474
- if self . flags & ( 1 << ( FlagV1 :: Alternate as u32 ) ) != 0 {
485
+ if self . flags . intersects ( FlagV1 :: ALTERNATE ) {
475
486
prefixed = true ; width += prefix. char_len ( ) ;
476
487
}
477
488
@@ -501,7 +512,7 @@ impl<'a> Formatter<'a> {
501
512
}
502
513
// The sign and prefix goes before the padding if the fill character
503
514
// is zero
504
- Some ( min) if self . flags & ( 1 << ( FlagV1 :: SignAwareZeroPad as u32 ) ) != 0 => {
515
+ Some ( min) if self . flags . intersects ( FlagV1 :: SIGNAWAREZEROPAD ) => {
505
516
self . fill = '0' ;
506
517
try!( write_prefix ( self ) ) ;
507
518
self . with_padding ( min - width, Alignment :: Right , |f| {
@@ -619,7 +630,7 @@ impl<'a> Formatter<'a> {
619
630
620
631
/// Flags for formatting (packed version of rt::Flag)
621
632
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
622
- pub fn flags ( & self ) -> u32 { self . flags }
633
+ pub fn flags ( & self ) -> FlagV1 { self . flags }
623
634
624
635
/// Character used as 'fill' whenever there is alignment
625
636
#[ unstable( feature = "core" , reason = "method was just created" ) ]
@@ -867,8 +878,8 @@ impl<T> Pointer for *const T {
867
878
// it denotes whether to prefix with 0x. We use it to work out whether
868
879
// or not to zero extend, and then unconditionally set it to get the
869
880
// prefix.
870
- if f. flags & 1 << ( FlagV1 :: Alternate as u32 ) > 0 {
871
- f. flags |= 1 << ( FlagV1 :: SignAwareZeroPad as u32 ) ;
881
+ if f. flags . intersects ( FlagV1 :: ALTERNATE ) {
882
+ f. flags . insert ( FlagV1 :: SIGNAWAREZEROPAD ) ;
872
883
873
884
if let None = f. width {
874
885
// The formats need two extra bytes, for the 0x
@@ -879,7 +890,7 @@ impl<T> Pointer for *const T {
879
890
}
880
891
}
881
892
}
882
- f. flags |= 1 << ( FlagV1 :: Alternate as u32 ) ;
893
+ f. flags . insert ( FlagV1 :: ALTERNATE ) ;
883
894
884
895
let ret = LowerHex :: fmt ( & ( * self as usize ) , f) ;
885
896
0 commit comments