@@ -18,6 +18,7 @@ mod float;
1818#[ cfg( no_fp_fmt_parse) ]
1919mod nofloat;
2020mod num;
21+ mod rt;
2122
2223#[ stable( feature = "fmt_flags_align" , since = "1.28.0" ) ]
2324#[ cfg_attr( not( test) , rustc_diagnostic_item = "Alignment" ) ]
@@ -38,12 +39,6 @@ pub enum Alignment {
3839#[ stable( feature = "debug_builders" , since = "1.2.0" ) ]
3940pub use self :: builders:: { DebugList , DebugMap , DebugSet , DebugStruct , DebugTuple } ;
4041
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-
4742/// The type returned by formatter methods.
4843///
4944/// # Examples
@@ -227,7 +222,7 @@ impl<W: Write + ?Sized> Write for &mut W {
227222pub struct Formatter < ' a > {
228223 flags : u32 ,
229224 fill : char ,
230- align : rt:: v1 :: Alignment ,
225+ align : rt:: Alignment ,
231226 width : Option < usize > ,
232227 precision : Option < usize > ,
233228
@@ -248,7 +243,7 @@ impl<'a> Formatter<'a> {
248243 Formatter {
249244 flags : 0 ,
250245 fill : ' ' ,
251- align : rt:: v1 :: Alignment :: Unknown ,
246+ align : rt:: Alignment :: Unknown ,
252247 width : None ,
253248 precision : None ,
254249 buf,
@@ -433,17 +428,15 @@ impl<'a> Arguments<'a> {
433428 /// An `UnsafeArg` is required because the following invariants must be held
434429 /// in order for this function to be safe:
435430 /// 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`.
440433 #[ doc( hidden) ]
441434 #[ inline]
442435 #[ unstable( feature = "fmt_internals" , reason = "internal to format_args!" , issue = "none" ) ]
443436 pub fn new_v1_formatted (
444437 pieces : & ' a [ & ' static str ] ,
445438 args : & ' a [ ArgumentV1 < ' a > ] ,
446- fmt : & ' a [ rt:: v1 :: Argument ] ,
439+ fmt : & ' a [ rt:: Placeholder ] ,
447440 _unsafe_arg : UnsafeArg ,
448441 ) -> Arguments < ' a > {
449442 Arguments { pieces, fmt : Some ( fmt) , args }
@@ -505,7 +498,7 @@ pub struct Arguments<'a> {
505498 pieces : & ' a [ & ' static str ] ,
506499
507500 // Placeholder specs, or `None` if all specs are default (as in "{}{}").
508- fmt : Option < & ' a [ rt:: v1 :: Argument ] > ,
501+ fmt : Option < & ' a [ rt:: Placeholder ] > ,
509502
510503 // Dynamic arguments for interpolation, to be interleaved with string
511504 // pieces. (Every argument is preceded by a string piece.)
@@ -1281,15 +1274,15 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
12811274 Ok ( ( ) )
12821275}
12831276
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 ;
12881281 // SAFETY: arg and args come from the same Arguments,
12891282 // which guarantees the indexes are always within bounds.
12901283 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 ) ;
12931286 }
12941287
12951288 // Extract the correct argument
@@ -1302,11 +1295,11 @@ unsafe fn run(fmt: &mut Formatter<'_>, arg: &rt::v1::Argument, args: &[ArgumentV
13021295 ( value. formatter ) ( value. value , fmt)
13031296}
13041297
1305- unsafe fn getcount ( args : & [ ArgumentV1 < ' _ > ] , cnt : & rt:: v1 :: Count ) -> Option < usize > {
1298+ unsafe fn getcount ( args : & [ ArgumentV1 < ' _ > ] , cnt : & rt:: Count ) -> Option < usize > {
13061299 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) => {
13101303 debug_assert ! ( i < args. len( ) ) ;
13111304 // SAFETY: cnt and args come from the same Arguments,
13121305 // which guarantees this index is always within bounds.
@@ -1449,9 +1442,9 @@ impl<'a> Formatter<'a> {
14491442 // is zero
14501443 Some ( min) if self . sign_aware_zero_pad ( ) => {
14511444 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 ) ;
14531446 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 ) ?;
14551448 self . buf . write_str ( buf) ?;
14561449 post_padding. write ( self ) ?;
14571450 self . fill = old_fill;
@@ -1460,7 +1453,7 @@ impl<'a> Formatter<'a> {
14601453 }
14611454 // Otherwise, the sign and prefix goes after the padding
14621455 Some ( min) => {
1463- let post_padding = self . padding ( min - width, rt :: v1 :: Alignment :: Right ) ?;
1456+ let post_padding = self . padding ( min - width, Alignment :: Right ) ?;
14641457 write_prefix ( self , sign, prefix) ?;
14651458 self . buf . write_str ( buf) ?;
14661459 post_padding. write ( self )
@@ -1535,7 +1528,7 @@ impl<'a> Formatter<'a> {
15351528 // If we're under both the maximum and the minimum width, then fill
15361529 // up the minimum width with the specified string + some alignment.
15371530 else {
1538- let align = rt :: v1 :: Alignment :: Left ;
1531+ let align = Alignment :: Left ;
15391532 let post_padding = self . padding ( width - chars_count, align) ?;
15401533 self . buf . write_str ( s) ?;
15411534 post_padding. write ( self )
@@ -1550,17 +1543,19 @@ impl<'a> Formatter<'a> {
15501543 pub ( crate ) fn padding (
15511544 & mut self ,
15521545 padding : usize ,
1553- default : rt :: v1 :: Alignment ,
1546+ default : Alignment ,
15541547 ) -> result:: Result < PostPadding , Error > {
15551548 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 ,
15581553 } ;
15591554
15601555 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 ) ,
15641559 } ;
15651560
15661561 for _ in 0 ..pre_pad {
@@ -1580,7 +1575,6 @@ impl<'a> Formatter<'a> {
15801575 let mut formatted = formatted. clone ( ) ;
15811576 let old_fill = self . fill ;
15821577 let old_align = self . align ;
1583- let mut align = old_align;
15841578 if self . sign_aware_zero_pad ( ) {
15851579 // a sign always goes first
15861580 let sign = formatted. sign ;
@@ -1589,9 +1583,8 @@ impl<'a> Formatter<'a> {
15891583 // remove the sign from the formatted parts
15901584 formatted. sign = "" ;
15911585 width = width. saturating_sub ( sign. len ( ) ) ;
1592- align = rt:: v1:: Alignment :: Right ;
15931586 self . fill = '0' ;
1594- self . align = rt:: v1 :: Alignment :: Right ;
1587+ self . align = rt:: Alignment :: Right ;
15951588 }
15961589
15971590 // remaining parts go through the ordinary padding process.
@@ -1600,7 +1593,7 @@ impl<'a> Formatter<'a> {
16001593 // no padding
16011594 self . write_formatted_parts ( & formatted)
16021595 } else {
1603- let post_padding = self . padding ( width - len, align ) ?;
1596+ let post_padding = self . padding ( width - len, Alignment :: Right ) ?;
16041597 self . write_formatted_parts ( & formatted) ?;
16051598 post_padding. write ( self )
16061599 } ;
@@ -1788,10 +1781,10 @@ impl<'a> Formatter<'a> {
17881781 #[ stable( feature = "fmt_flags_align" , since = "1.28.0" ) ]
17891782 pub fn align ( & self ) -> Option < Alignment > {
17901783 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 ,
17951788 }
17961789 }
17971790
0 commit comments