44
55use crate :: cell:: { Cell , Ref , RefCell , RefMut , UnsafeCell } ;
66use crate :: char:: EscapeDebugExtArgs ;
7- use crate :: iter;
87use crate :: marker:: PhantomData ;
98use crate :: mem;
109use crate :: num:: fmt as numfmt;
@@ -1141,7 +1140,10 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
11411140 match args. fmt {
11421141 None => {
11431142 // We can use default formatting parameters for all arguments.
1144- for ( arg, piece) in iter:: zip ( args. args , args. pieces ) {
1143+ for ( i, arg) in args. args . iter ( ) . enumerate ( ) {
1144+ // SAFETY: args.args and args.pieces come from the same Arguments,
1145+ // which guarantees the indexes are always within bounds.
1146+ let piece = unsafe { args. pieces . get_unchecked ( i) } ;
11451147 if !piece. is_empty ( ) {
11461148 formatter. buf . write_str ( * piece) ?;
11471149 }
@@ -1152,7 +1154,10 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
11521154 Some ( fmt) => {
11531155 // Every spec has a corresponding argument that is preceded by
11541156 // a string piece.
1155- for ( arg, piece) in iter:: zip ( fmt, args. pieces ) {
1157+ for ( i, arg) in fmt. iter ( ) . enumerate ( ) {
1158+ // SAFETY: fmt and args.pieces come from the same Arguments,
1159+ // which guarantees the indexes are always within bounds.
1160+ let piece = unsafe { args. pieces . get_unchecked ( i) } ;
11561161 if !piece. is_empty ( ) {
11571162 formatter. buf . write_str ( * piece) ?;
11581163 }
0 commit comments