@@ -245,7 +245,7 @@ impl<'a, W: Write + ?Sized> Write for &'a mut W {
245
245
#[ allow( missing_debug_implementations) ]
246
246
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
247
247
pub struct Formatter < ' a > {
248
- flags : u32 ,
248
+ flags : FlagV1 ,
249
249
fill : char ,
250
250
align : rt:: v1:: Alignment ,
251
251
width : Option < usize > ,
@@ -320,9 +320,15 @@ impl<'a> ArgumentV1<'a> {
320
320
}
321
321
}
322
322
323
- // flags available in the v1 format of format_args
324
- #[ derive( Copy , Clone ) ]
325
- enum FlagV1 { SignPlus , SignMinus , Alternate , SignAwareZeroPad , }
323
+ bitflags ! {
324
+ // flags available in the v1 format of format_args
325
+ struct FlagV1 : u32 {
326
+ const SIGN_PLUS = 1 << 0 ;
327
+ const SIGN_MINUS = 1 << 1 ;
328
+ const ALTERNATE = 1 << 2 ;
329
+ const SIGN_AWARE_ZERO_PAD = 1 << 3 ;
330
+ }
331
+ }
326
332
327
333
impl < ' a > Arguments < ' a > {
328
334
/// When using the format_args!() macro, this function is used to generate the
@@ -947,7 +953,7 @@ pub trait UpperExp {
947
953
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
948
954
pub fn write ( output : & mut Write , args : Arguments ) -> Result {
949
955
let mut formatter = Formatter {
950
- flags : 0 ,
956
+ flags : FlagV1 :: empty ( ) ,
951
957
width : None ,
952
958
precision : None ,
953
959
buf : output,
@@ -993,7 +999,7 @@ impl<'a> Formatter<'a> {
993
999
// Fill in the format parameters into the formatter
994
1000
self . fill = arg. format . fill ;
995
1001
self . align = arg. format . align ;
996
- self . flags = arg. format . flags ;
1002
+ self . flags = FlagV1 :: from_bits_truncate ( arg. format . flags ) ;
997
1003
self . width = self . getcount ( & arg. format . width ) ;
998
1004
self . precision = self . getcount ( & arg. format . precision ) ;
999
1005
@@ -1277,7 +1283,7 @@ impl<'a> Formatter<'a> {
1277
1283
1278
1284
/// Flags for formatting
1279
1285
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1280
- pub fn flags ( & self ) -> u32 { self . flags }
1286
+ pub fn flags ( & self ) -> u32 { self . flags . bits }
1281
1287
1282
1288
/// Character used as 'fill' whenever there is alignment
1283
1289
#[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
@@ -1305,20 +1311,20 @@ impl<'a> Formatter<'a> {
1305
1311
1306
1312
/// Determines if the `+` flag was specified.
1307
1313
#[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
1308
- pub fn sign_plus ( & self ) -> bool { self . flags & ( 1 << FlagV1 :: SignPlus as u32 ) != 0 }
1314
+ pub fn sign_plus ( & self ) -> bool { self . flags . intersects ( FlagV1 :: SIGN_PLUS ) }
1309
1315
1310
1316
/// Determines if the `-` flag was specified.
1311
1317
#[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
1312
- pub fn sign_minus ( & self ) -> bool { self . flags & ( 1 << FlagV1 :: SignMinus as u32 ) != 0 }
1318
+ pub fn sign_minus ( & self ) -> bool { f . flags . intersects ( FlagV1 :: SIGN_MINUS ) }
1313
1319
1314
1320
/// Determines if the `#` flag was specified.
1315
1321
#[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
1316
- pub fn alternate ( & self ) -> bool { self . flags & ( 1 << FlagV1 :: Alternate as u32 ) != 0 }
1322
+ pub fn alternate ( & self ) -> bool { f . flags . intersects ( FlagV1 :: ALTERNATE ) }
1317
1323
1318
1324
/// Determines if the `0` flag was specified.
1319
1325
#[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
1320
1326
pub fn sign_aware_zero_pad ( & self ) -> bool {
1321
- self . flags & ( 1 << FlagV1 :: SignAwareZeroPad as u32 ) != 0
1327
+ self . flags . intersects ( FlagV1 :: SIGN_AWARE_ZERO_PAD )
1322
1328
}
1323
1329
1324
1330
/// Creates a [`DebugStruct`] builder designed to assist with creation of
@@ -1584,13 +1590,13 @@ impl<T: ?Sized> Pointer for *const T {
1584
1590
// or not to zero extend, and then unconditionally set it to get the
1585
1591
// prefix.
1586
1592
if f. alternate ( ) {
1587
- f. flags |= 1 << ( FlagV1 :: SignAwareZeroPad as u32 ) ;
1593
+ f. flags . insert ( FlagV1 :: SIGN_AWARE_ZERO_PAD ) ;
1588
1594
1589
1595
if let None = f. width {
1590
1596
f. width = Some ( ( ( mem:: size_of :: < usize > ( ) * 8 ) / 4 ) + 2 ) ;
1591
1597
}
1592
1598
}
1593
- f. flags |= 1 << ( FlagV1 :: Alternate as u32 ) ;
1599
+ f. flags . insert ( FlagV1 :: ALTERNATE ) ;
1594
1600
1595
1601
let ret = LowerHex :: fmt ( & ( * self as * const ( ) as usize ) , f) ;
1596
1602
0 commit comments