@@ -294,8 +294,8 @@ pub struct FormattingOptions {
294294 flags : u32 ,
295295 fill : char ,
296296 align : Option < Alignment > ,
297- width : Option < usize > ,
298- precision : Option < usize > ,
297+ width : Option < u16 > ,
298+ precision : Option < u16 > ,
299299}
300300
301301impl FormattingOptions {
@@ -389,7 +389,7 @@ impl FormattingOptions {
389389 /// the padding specified by [`FormattingOptions::fill`]/[`FormattingOptions::align`]
390390 /// will be used to take up the required space.
391391 #[ unstable( feature = "formatting_options" , issue = "118117" ) ]
392- pub fn width ( & mut self , width : Option < usize > ) -> & mut Self {
392+ pub fn width ( & mut self , width : Option < u16 > ) -> & mut Self {
393393 self . width = width;
394394 self
395395 }
@@ -403,7 +403,7 @@ impl FormattingOptions {
403403 /// - For floating-point types, this indicates how many digits after the
404404 /// decimal point should be printed.
405405 #[ unstable( feature = "formatting_options" , issue = "118117" ) ]
406- pub fn precision ( & mut self , precision : Option < usize > ) -> & mut Self {
406+ pub fn precision ( & mut self , precision : Option < u16 > ) -> & mut Self {
407407 self . precision = precision;
408408 self
409409 }
@@ -455,12 +455,12 @@ impl FormattingOptions {
455455 }
456456 /// Returns the current width.
457457 #[ unstable( feature = "formatting_options" , issue = "118117" ) ]
458- pub const fn get_width ( & self ) -> Option < usize > {
458+ pub const fn get_width ( & self ) -> Option < u16 > {
459459 self . width
460460 }
461461 /// Returns the current precision.
462462 #[ unstable( feature = "formatting_options" , issue = "118117" ) ]
463- pub const fn get_precision ( & self ) -> Option < usize > {
463+ pub const fn get_precision ( & self ) -> Option < u16 > {
464464 self . precision
465465 }
466466 /// Returns the current precision.
@@ -1499,15 +1499,18 @@ unsafe fn run(fmt: &mut Formatter<'_>, arg: &rt::Placeholder, args: &[rt::Argume
14991499 unsafe { value. fmt ( fmt) }
15001500}
15011501
1502- unsafe fn getcount ( args : & [ rt:: Argument < ' _ > ] , cnt : & rt:: Count ) -> Option < usize > {
1502+ unsafe fn getcount ( args : & [ rt:: Argument < ' _ > ] , cnt : & rt:: Count ) -> Option < u16 > {
15031503 match * cnt {
1504+ #[ cfg( bootstrap) ]
1505+ rt:: Count :: Is ( n) => Some ( n as u16 ) ,
1506+ #[ cfg( not( bootstrap) ) ]
15041507 rt:: Count :: Is ( n) => Some ( n) ,
15051508 rt:: Count :: Implied => None ,
15061509 rt:: Count :: Param ( i) => {
15071510 debug_assert ! ( i < args. len( ) ) ;
15081511 // SAFETY: cnt and args come from the same Arguments,
15091512 // which guarantees this index is always within bounds.
1510- unsafe { args. get_unchecked ( i) . as_usize ( ) }
1513+ unsafe { args. get_unchecked ( i) . as_u16 ( ) }
15111514 }
15121515 }
15131516}
@@ -1516,11 +1519,11 @@ unsafe fn getcount(args: &[rt::Argument<'_>], cnt: &rt::Count) -> Option<usize>
15161519#[ must_use = "don't forget to write the post padding" ]
15171520pub ( crate ) struct PostPadding {
15181521 fill : char ,
1519- padding : usize ,
1522+ padding : u16 ,
15201523}
15211524
15221525impl PostPadding {
1523- fn new ( fill : char , padding : usize ) -> PostPadding {
1526+ fn new ( fill : char , padding : u16 ) -> PostPadding {
15241527 PostPadding { fill, padding }
15251528 }
15261529
@@ -1634,7 +1637,7 @@ impl<'a> Formatter<'a> {
16341637 }
16351638 // Check if we're over the minimum width, if so then we can also
16361639 // just write the bytes.
1637- Some ( min) if width >= min => {
1640+ Some ( min) if width >= usize :: from ( min) => {
16381641 write_prefix ( self , sign, prefix) ?;
16391642 self . buf . write_str ( buf)
16401643 }
@@ -1645,7 +1648,7 @@ impl<'a> Formatter<'a> {
16451648 let old_align =
16461649 crate :: mem:: replace ( & mut self . options . align , Some ( Alignment :: Right ) ) ;
16471650 write_prefix ( self , sign, prefix) ?;
1648- let post_padding = self . padding ( min - width, Alignment :: Right ) ?;
1651+ let post_padding = self . padding ( min - width as u16 , Alignment :: Right ) ?;
16491652 self . buf . write_str ( buf) ?;
16501653 post_padding. write ( self ) ?;
16511654 self . options . fill = old_fill;
@@ -1654,7 +1657,7 @@ impl<'a> Formatter<'a> {
16541657 }
16551658 // Otherwise, the sign and prefix goes after the padding
16561659 Some ( min) => {
1657- let post_padding = self . padding ( min - width, Alignment :: Right ) ?;
1660+ let post_padding = self . padding ( min - width as u16 , Alignment :: Right ) ?;
16581661 write_prefix ( self , sign, prefix) ?;
16591662 self . buf . write_str ( buf) ?;
16601663 post_padding. write ( self )
@@ -1702,26 +1705,26 @@ impl<'a> Formatter<'a> {
17021705 // string being formatted.
17031706 let ( s, char_count) = if let Some ( max_char_count) = self . options . precision {
17041707 let mut iter = s. char_indices ( ) ;
1705- let remaining = match iter. advance_by ( max_char_count) {
1708+ let remaining = match iter. advance_by ( usize :: from ( max_char_count) ) {
17061709 Ok ( ( ) ) => 0 ,
17071710 Err ( remaining) => remaining. get ( ) ,
17081711 } ;
17091712 // SAFETY: The offset of `.char_indices()` is guaranteed to be
17101713 // in-bounds and between character boundaries.
17111714 let truncated = unsafe { s. get_unchecked ( ..iter. offset ( ) ) } ;
1712- ( truncated, max_char_count - remaining)
1715+ ( truncated, usize :: from ( max_char_count) - remaining)
17131716 } else {
17141717 // Use the optimized char counting algorithm for the full string.
17151718 ( s, s. chars ( ) . count ( ) )
17161719 } ;
17171720
17181721 // The `width` field is more of a minimum width parameter at this point.
17191722 if let Some ( width) = self . options . width
1720- && char_count < width
1723+ && char_count < usize :: from ( width)
17211724 {
17221725 // If we're under the minimum width, then fill up the minimum width
17231726 // with the specified string + some alignment.
1724- let post_padding = self . padding ( width - char_count, Alignment :: Left ) ?;
1727+ let post_padding = self . padding ( width - char_count as u16 , Alignment :: Left ) ?;
17251728 self . buf . write_str ( s) ?;
17261729 post_padding. write ( self )
17271730 } else {
@@ -1737,7 +1740,7 @@ impl<'a> Formatter<'a> {
17371740 /// thing that is being padded.
17381741 pub ( crate ) fn padding (
17391742 & mut self ,
1740- padding : usize ,
1743+ padding : u16 ,
17411744 default : Alignment ,
17421745 ) -> result:: Result < PostPadding , Error > {
17431746 let align = self . align ( ) . unwrap_or ( default) ;
@@ -1777,19 +1780,19 @@ impl<'a> Formatter<'a> {
17771780
17781781 // remove the sign from the formatted parts
17791782 formatted. sign = "" ;
1780- width = width. saturating_sub ( sign. len ( ) ) ;
1783+ width = width. saturating_sub ( sign. len ( ) as u16 ) ;
17811784 self . options . fill = '0' ;
17821785 self . options . align = Some ( Alignment :: Right ) ;
17831786 }
17841787
17851788 // remaining parts go through the ordinary padding process.
17861789 let len = formatted. len ( ) ;
1787- let ret = if width <= len {
1790+ let ret = if usize :: from ( width) <= len {
17881791 // no padding
17891792 // SAFETY: Per the precondition.
17901793 unsafe { self . write_formatted_parts ( & formatted) }
17911794 } else {
1792- let post_padding = self . padding ( width - len, Alignment :: Right ) ?;
1795+ let post_padding = self . padding ( width - len as u16 , Alignment :: Right ) ?;
17931796 // SAFETY: Per the precondition.
17941797 unsafe {
17951798 self . write_formatted_parts ( & formatted) ?;
@@ -2021,7 +2024,7 @@ impl<'a> Formatter<'a> {
20212024 #[ must_use]
20222025 #[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
20232026 pub fn width ( & self ) -> Option < usize > {
2024- self . options . width
2027+ self . options . width . map ( |x| x as usize )
20252028 }
20262029
20272030 /// Returns the optionally specified precision for numeric types.
@@ -2052,7 +2055,7 @@ impl<'a> Formatter<'a> {
20522055 #[ must_use]
20532056 #[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
20542057 pub fn precision ( & self ) -> Option < usize > {
2055- self . options . precision
2058+ self . options . precision . map ( |x| x as usize )
20562059 }
20572060
20582061 /// Determines if the `+` flag was specified.
@@ -2792,7 +2795,7 @@ pub(crate) fn pointer_fmt_inner(ptr_addr: usize, f: &mut Formatter<'_>) -> Resul
27922795 f. options . flags |= 1 << ( rt:: Flag :: SignAwareZeroPad as u32 ) ;
27932796
27942797 if f. options . width . is_none ( ) {
2795- f. options . width = Some ( ( usize:: BITS / 4 ) as usize + 2 ) ;
2798+ f. options . width = Some ( ( usize:: BITS / 4 ) as u16 + 2 ) ;
27962799 }
27972800 }
27982801 f. options . flags |= 1 << ( rt:: Flag :: Alternate as u32 ) ;
0 commit comments