@@ -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 )
@@ -1703,7 +1706,7 @@ impl<'a> Formatter<'a> {
17031706 // If our string is longer that the precision, then we must have
17041707 // truncation. However other flags like `fill`, `width` and `align`
17051708 // must act as always.
1706- if let Some ( ( i, _) ) = s. char_indices ( ) . nth ( max) {
1709+ if let Some ( ( i, _) ) = s. char_indices ( ) . nth ( usize :: from ( max) ) {
17071710 // LLVM here can't prove that `..i` won't panic `&s[..i]`, but
17081711 // we know that it can't panic. Use `get` + `unwrap_or` to avoid
17091712 // `unsafe` and otherwise don't emit any panic-related code
@@ -1724,14 +1727,14 @@ impl<'a> Formatter<'a> {
17241727 let chars_count = s. chars ( ) . count ( ) ;
17251728 // If we're under the maximum width, check if we're over the minimum
17261729 // width, if so it's as easy as just emitting the string.
1727- if chars_count >= width {
1730+ if chars_count >= usize :: from ( width) {
17281731 self . buf . write_str ( s)
17291732 }
17301733 // If we're under both the maximum and the minimum width, then fill
17311734 // up the minimum width with the specified string + some alignment.
17321735 else {
17331736 let align = Alignment :: Left ;
1734- let post_padding = self . padding ( width - chars_count, align) ?;
1737+ let post_padding = self . padding ( width - chars_count as u16 , align) ?;
17351738 self . buf . write_str ( s) ?;
17361739 post_padding. write ( self )
17371740 }
@@ -1745,7 +1748,7 @@ impl<'a> Formatter<'a> {
17451748 /// thing that is being padded.
17461749 pub ( crate ) fn padding (
17471750 & mut self ,
1748- padding : usize ,
1751+ padding : u16 ,
17491752 default : Alignment ,
17501753 ) -> result:: Result < PostPadding , Error > {
17511754 let align = self . align ( ) . unwrap_or ( default) ;
@@ -1785,19 +1788,19 @@ impl<'a> Formatter<'a> {
17851788
17861789 // remove the sign from the formatted parts
17871790 formatted. sign = "" ;
1788- width = width. saturating_sub ( sign. len ( ) ) ;
1791+ width = width. saturating_sub ( sign. len ( ) as u16 ) ;
17891792 self . options . fill = '0' ;
17901793 self . options . align = Some ( Alignment :: Right ) ;
17911794 }
17921795
17931796 // remaining parts go through the ordinary padding process.
17941797 let len = formatted. len ( ) ;
1795- let ret = if width <= len {
1798+ let ret = if usize :: from ( width) <= len {
17961799 // no padding
17971800 // SAFETY: Per the precondition.
17981801 unsafe { self . write_formatted_parts ( & formatted) }
17991802 } else {
1800- let post_padding = self . padding ( width - len, Alignment :: Right ) ?;
1803+ let post_padding = self . padding ( width - len as u16 , Alignment :: Right ) ?;
18011804 // SAFETY: Per the precondition.
18021805 unsafe {
18031806 self . write_formatted_parts ( & formatted) ?;
@@ -2029,7 +2032,7 @@ impl<'a> Formatter<'a> {
20292032 #[ must_use]
20302033 #[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
20312034 pub fn width ( & self ) -> Option < usize > {
2032- self . options . width
2035+ self . options . width . map ( |x| x as usize )
20332036 }
20342037
20352038 /// Returns the optionally specified precision for numeric types.
@@ -2060,7 +2063,7 @@ impl<'a> Formatter<'a> {
20602063 #[ must_use]
20612064 #[ stable( feature = "fmt_flags" , since = "1.5.0" ) ]
20622065 pub fn precision ( & self ) -> Option < usize > {
2063- self . options . precision
2066+ self . options . precision . map ( |x| x as usize )
20642067 }
20652068
20662069 /// Determines if the `+` flag was specified.
@@ -2800,7 +2803,7 @@ pub(crate) fn pointer_fmt_inner(ptr_addr: usize, f: &mut Formatter<'_>) -> Resul
28002803 f. options . flags |= 1 << ( rt:: Flag :: SignAwareZeroPad as u32 ) ;
28012804
28022805 if f. options . width . is_none ( ) {
2803- f. options . width = Some ( ( usize:: BITS / 4 ) as usize + 2 ) ;
2806+ f. options . width = Some ( ( usize:: BITS / 4 ) as u16 + 2 ) ;
28042807 }
28052808 }
28062809 f. options . flags |= 1 << ( rt:: Flag :: Alternate as u32 ) ;
0 commit comments