4
4
5
5
use crate :: cell:: { Cell , Ref , RefCell , RefMut , UnsafeCell } ;
6
6
use crate :: char:: EscapeDebugExtArgs ;
7
- use crate :: iter;
8
7
use crate :: marker:: PhantomData ;
9
8
use crate :: mem;
10
9
use crate :: num:: fmt as numfmt;
@@ -1141,7 +1140,10 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
1141
1140
match args. fmt {
1142
1141
None => {
1143
1142
// 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) } ;
1145
1147
if !piece. is_empty ( ) {
1146
1148
formatter. buf . write_str ( * piece) ?;
1147
1149
}
@@ -1152,7 +1154,10 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
1152
1154
Some ( fmt) => {
1153
1155
// Every spec has a corresponding argument that is preceded by
1154
1156
// 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) } ;
1156
1161
if !piece. is_empty ( ) {
1157
1162
formatter. buf . write_str ( * piece) ?;
1158
1163
}
0 commit comments