@@ -18,6 +18,7 @@ mod float;
18
18
#[ cfg( no_fp_fmt_parse) ]
19
19
mod nofloat;
20
20
mod num;
21
+ mod rt;
21
22
22
23
#[ stable( feature = "fmt_flags_align" , since = "1.28.0" ) ]
23
24
#[ cfg_attr( not( test) , rustc_diagnostic_item = "Alignment" ) ]
@@ -38,12 +39,6 @@ pub enum Alignment {
38
39
#[ stable( feature = "debug_builders" , since = "1.2.0" ) ]
39
40
pub use self :: builders:: { DebugList , DebugMap , DebugSet , DebugStruct , DebugTuple } ;
40
41
41
- #[ unstable( feature = "fmt_internals" , reason = "internal to format_args!" , issue = "none" ) ]
42
- #[ doc( hidden) ]
43
- pub mod rt {
44
- pub mod v1;
45
- }
46
-
47
42
/// The type returned by formatter methods.
48
43
///
49
44
/// # Examples
@@ -227,7 +222,7 @@ impl<W: Write + ?Sized> Write for &mut W {
227
222
pub struct Formatter < ' a > {
228
223
flags : u32 ,
229
224
fill : char ,
230
- align : rt:: v1 :: Alignment ,
225
+ align : rt:: Alignment ,
231
226
width : Option < usize > ,
232
227
precision : Option < usize > ,
233
228
@@ -248,7 +243,7 @@ impl<'a> Formatter<'a> {
248
243
Formatter {
249
244
flags : 0 ,
250
245
fill : ' ' ,
251
- align : rt:: v1 :: Alignment :: Unknown ,
246
+ align : rt:: Alignment :: Unknown ,
252
247
width : None ,
253
248
precision : None ,
254
249
buf,
@@ -433,17 +428,15 @@ impl<'a> Arguments<'a> {
433
428
/// An `UnsafeArg` is required because the following invariants must be held
434
429
/// in order for this function to be safe:
435
430
/// 1. The `pieces` slice must be at least as long as `fmt`.
436
- /// 2. Every [`rt::v1::Argument::position`] value within `fmt` must be a
437
- /// valid index of `args`.
438
- /// 3. Every [`rt::v1::Count::Param`] within `fmt` must contain a valid index of
439
- /// `args`.
431
+ /// 2. Every `rt::Placeholder::position` value within `fmt` must be a valid index of `args`.
432
+ /// 3. Every `rt::Count::Param` within `fmt` must contain a valid index of `args`.
440
433
#[ doc( hidden) ]
441
434
#[ inline]
442
435
#[ unstable( feature = "fmt_internals" , reason = "internal to format_args!" , issue = "none" ) ]
443
436
pub fn new_v1_formatted (
444
437
pieces : & ' a [ & ' static str ] ,
445
438
args : & ' a [ ArgumentV1 < ' a > ] ,
446
- fmt : & ' a [ rt:: v1 :: Argument ] ,
439
+ fmt : & ' a [ rt:: Placeholder ] ,
447
440
_unsafe_arg : UnsafeArg ,
448
441
) -> Arguments < ' a > {
449
442
Arguments { pieces, fmt : Some ( fmt) , args }
@@ -505,7 +498,7 @@ pub struct Arguments<'a> {
505
498
pieces : & ' a [ & ' static str ] ,
506
499
507
500
// Placeholder specs, or `None` if all specs are default (as in "{}{}").
508
- fmt : Option < & ' a [ rt:: v1 :: Argument ] > ,
501
+ fmt : Option < & ' a [ rt:: Placeholder ] > ,
509
502
510
503
// Dynamic arguments for interpolation, to be interleaved with string
511
504
// pieces. (Every argument is preceded by a string piece.)
@@ -1281,15 +1274,15 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
1281
1274
Ok ( ( ) )
1282
1275
}
1283
1276
1284
- unsafe fn run ( fmt : & mut Formatter < ' _ > , arg : & rt:: v1 :: Argument , args : & [ ArgumentV1 < ' _ > ] ) -> Result {
1285
- fmt. fill = arg. format . fill ;
1286
- fmt. align = arg. format . align ;
1287
- fmt. flags = arg. format . flags ;
1277
+ unsafe fn run ( fmt : & mut Formatter < ' _ > , arg : & rt:: Placeholder , args : & [ ArgumentV1 < ' _ > ] ) -> Result {
1278
+ fmt. fill = arg. fill ;
1279
+ fmt. align = arg. align ;
1280
+ fmt. flags = arg. flags ;
1288
1281
// SAFETY: arg and args come from the same Arguments,
1289
1282
// which guarantees the indexes are always within bounds.
1290
1283
unsafe {
1291
- fmt. width = getcount ( args, & arg. format . width ) ;
1292
- fmt. precision = getcount ( args, & arg. format . precision ) ;
1284
+ fmt. width = getcount ( args, & arg. width ) ;
1285
+ fmt. precision = getcount ( args, & arg. precision ) ;
1293
1286
}
1294
1287
1295
1288
// Extract the correct argument
@@ -1302,11 +1295,11 @@ unsafe fn run(fmt: &mut Formatter<'_>, arg: &rt::v1::Argument, args: &[ArgumentV
1302
1295
( value. formatter ) ( value. value , fmt)
1303
1296
}
1304
1297
1305
- unsafe fn getcount ( args : & [ ArgumentV1 < ' _ > ] , cnt : & rt:: v1 :: Count ) -> Option < usize > {
1298
+ unsafe fn getcount ( args : & [ ArgumentV1 < ' _ > ] , cnt : & rt:: Count ) -> Option < usize > {
1306
1299
match * cnt {
1307
- rt:: v1 :: Count :: Is ( n) => Some ( n) ,
1308
- rt:: v1 :: Count :: Implied => None ,
1309
- rt:: v1 :: Count :: Param ( i) => {
1300
+ rt:: Count :: Is ( n) => Some ( n) ,
1301
+ rt:: Count :: Implied => None ,
1302
+ rt:: Count :: Param ( i) => {
1310
1303
debug_assert ! ( i < args. len( ) ) ;
1311
1304
// SAFETY: cnt and args come from the same Arguments,
1312
1305
// which guarantees this index is always within bounds.
@@ -1449,9 +1442,9 @@ impl<'a> Formatter<'a> {
1449
1442
// is zero
1450
1443
Some ( min) if self . sign_aware_zero_pad ( ) => {
1451
1444
let old_fill = crate :: mem:: replace ( & mut self . fill , '0' ) ;
1452
- let old_align = crate :: mem:: replace ( & mut self . align , rt:: v1 :: Alignment :: Right ) ;
1445
+ let old_align = crate :: mem:: replace ( & mut self . align , rt:: Alignment :: Right ) ;
1453
1446
write_prefix ( self , sign, prefix) ?;
1454
- let post_padding = self . padding ( min - width, rt :: v1 :: Alignment :: Right ) ?;
1447
+ let post_padding = self . padding ( min - width, Alignment :: Right ) ?;
1455
1448
self . buf . write_str ( buf) ?;
1456
1449
post_padding. write ( self ) ?;
1457
1450
self . fill = old_fill;
@@ -1460,7 +1453,7 @@ impl<'a> Formatter<'a> {
1460
1453
}
1461
1454
// Otherwise, the sign and prefix goes after the padding
1462
1455
Some ( min) => {
1463
- let post_padding = self . padding ( min - width, rt :: v1 :: Alignment :: Right ) ?;
1456
+ let post_padding = self . padding ( min - width, Alignment :: Right ) ?;
1464
1457
write_prefix ( self , sign, prefix) ?;
1465
1458
self . buf . write_str ( buf) ?;
1466
1459
post_padding. write ( self )
@@ -1535,7 +1528,7 @@ impl<'a> Formatter<'a> {
1535
1528
// If we're under both the maximum and the minimum width, then fill
1536
1529
// up the minimum width with the specified string + some alignment.
1537
1530
else {
1538
- let align = rt :: v1 :: Alignment :: Left ;
1531
+ let align = Alignment :: Left ;
1539
1532
let post_padding = self . padding ( width - chars_count, align) ?;
1540
1533
self . buf . write_str ( s) ?;
1541
1534
post_padding. write ( self )
@@ -1550,17 +1543,19 @@ impl<'a> Formatter<'a> {
1550
1543
pub ( crate ) fn padding (
1551
1544
& mut self ,
1552
1545
padding : usize ,
1553
- default : rt :: v1 :: Alignment ,
1546
+ default : Alignment ,
1554
1547
) -> result:: Result < PostPadding , Error > {
1555
1548
let align = match self . align {
1556
- rt:: v1:: Alignment :: Unknown => default,
1557
- _ => self . align ,
1549
+ rt:: Alignment :: Unknown => default,
1550
+ rt:: Alignment :: Left => Alignment :: Left ,
1551
+ rt:: Alignment :: Right => Alignment :: Right ,
1552
+ rt:: Alignment :: Center => Alignment :: Center ,
1558
1553
} ;
1559
1554
1560
1555
let ( pre_pad, post_pad) = match align {
1561
- rt :: v1 :: Alignment :: Left => ( 0 , padding) ,
1562
- rt :: v1 :: Alignment :: Right | rt :: v1 :: Alignment :: Unknown => ( padding, 0 ) ,
1563
- rt :: v1 :: Alignment :: Center => ( padding / 2 , ( padding + 1 ) / 2 ) ,
1556
+ Alignment :: Left => ( 0 , padding) ,
1557
+ Alignment :: Right => ( padding, 0 ) ,
1558
+ Alignment :: Center => ( padding / 2 , ( padding + 1 ) / 2 ) ,
1564
1559
} ;
1565
1560
1566
1561
for _ in 0 ..pre_pad {
@@ -1580,7 +1575,6 @@ impl<'a> Formatter<'a> {
1580
1575
let mut formatted = formatted. clone ( ) ;
1581
1576
let old_fill = self . fill ;
1582
1577
let old_align = self . align ;
1583
- let mut align = old_align;
1584
1578
if self . sign_aware_zero_pad ( ) {
1585
1579
// a sign always goes first
1586
1580
let sign = formatted. sign ;
@@ -1589,9 +1583,8 @@ impl<'a> Formatter<'a> {
1589
1583
// remove the sign from the formatted parts
1590
1584
formatted. sign = "" ;
1591
1585
width = width. saturating_sub ( sign. len ( ) ) ;
1592
- align = rt:: v1:: Alignment :: Right ;
1593
1586
self . fill = '0' ;
1594
- self . align = rt:: v1 :: Alignment :: Right ;
1587
+ self . align = rt:: Alignment :: Right ;
1595
1588
}
1596
1589
1597
1590
// remaining parts go through the ordinary padding process.
@@ -1600,7 +1593,7 @@ impl<'a> Formatter<'a> {
1600
1593
// no padding
1601
1594
self . write_formatted_parts ( & formatted)
1602
1595
} else {
1603
- let post_padding = self . padding ( width - len, align ) ?;
1596
+ let post_padding = self . padding ( width - len, Alignment :: Right ) ?;
1604
1597
self . write_formatted_parts ( & formatted) ?;
1605
1598
post_padding. write ( self )
1606
1599
} ;
@@ -1788,10 +1781,10 @@ impl<'a> Formatter<'a> {
1788
1781
#[ stable( feature = "fmt_flags_align" , since = "1.28.0" ) ]
1789
1782
pub fn align ( & self ) -> Option < Alignment > {
1790
1783
match self . align {
1791
- rt:: v1 :: Alignment :: Left => Some ( Alignment :: Left ) ,
1792
- rt:: v1 :: Alignment :: Right => Some ( Alignment :: Right ) ,
1793
- rt:: v1 :: Alignment :: Center => Some ( Alignment :: Center ) ,
1794
- rt:: v1 :: Alignment :: Unknown => None ,
1784
+ rt:: Alignment :: Left => Some ( Alignment :: Left ) ,
1785
+ rt:: Alignment :: Right => Some ( Alignment :: Right ) ,
1786
+ rt:: Alignment :: Center => Some ( Alignment :: Center ) ,
1787
+ rt:: Alignment :: Unknown => None ,
1795
1788
}
1796
1789
}
1797
1790
0 commit comments