File tree Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change @@ -636,6 +636,9 @@ impl<'a> Arguments<'a> {
636636 /// when using `format!`. Note: this is neither the lower nor upper bound.
637637 #[ inline]
638638 pub fn estimated_capacity ( & self ) -> usize {
639+ // Since the format args are constructed from a single string literal in
640+ // `format_args!`, the total length of the pieces is under `isize::MAX`
641+ // and this sum cannot overflow.
639642 let pieces_length: usize = self . pieces . iter ( ) . map ( |x| x. len ( ) ) . sum ( ) ;
640643
641644 if self . args . is_empty ( ) {
@@ -649,7 +652,8 @@ impl<'a> Arguments<'a> {
649652 // There are some arguments, so any additional push
650653 // will reallocate the string. To avoid that,
651654 // we're "pre-doubling" the capacity here.
652- pieces_length. checked_mul ( 2 ) . unwrap_or ( 0 )
655+ // It cannot overflow, because the maximum length is `isize::MAX`.
656+ pieces_length * 2
653657 }
654658 }
655659}
You can’t perform that action at this time.
0 commit comments