Skip to content

Commit c10e80a

Browse files
committed
Revert "Get piece unchecked in write"
This reverts commit f4ef07c.
1 parent 97f0b3c commit c10e80a

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

library/core/src/fmt/mod.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use crate::cell::{Cell, Ref, RefCell, RefMut, UnsafeCell};
66
use crate::char::EscapeDebugExtArgs;
7+
use crate::iter;
78
use crate::marker::PhantomData;
89
use crate::mem;
910
use crate::num::fmt as numfmt;
@@ -1116,10 +1117,7 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
11161117
match args.fmt {
11171118
None => {
11181119
// We can use default formatting parameters for all arguments.
1119-
for (i, arg) in args.args.iter().enumerate() {
1120-
// SAFETY: args.args and args.pieces come from the same Arguments,
1121-
// which guarantees the indexes are always within bounds.
1122-
let piece = unsafe { args.pieces.get_unchecked(i) };
1120+
for (arg, piece) in iter::zip(args.args, args.pieces) {
11231121
if !piece.is_empty() {
11241122
formatter.buf.write_str(*piece)?;
11251123
}
@@ -1130,10 +1128,7 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
11301128
Some(fmt) => {
11311129
// Every spec has a corresponding argument that is preceded by
11321130
// a string piece.
1133-
for (i, arg) in fmt.iter().enumerate() {
1134-
// SAFETY: fmt and args.pieces come from the same Arguments,
1135-
// which guarantees the indexes are always within bounds.
1136-
let piece = unsafe { args.pieces.get_unchecked(i) };
1131+
for (arg, piece) in iter::zip(fmt, args.pieces) {
11371132
if !piece.is_empty() {
11381133
formatter.buf.write_str(*piece)?;
11391134
}

0 commit comments

Comments
 (0)