@@ -2409,9 +2409,10 @@ impl Debug for str {
2409
2409
2410
2410
// the outer loop here splits the string into chunks of printable ASCII, which is just skipped over,
2411
2411
// and chunks of other chars (unicode, or ASCII that needs escaping), which is handler per-`char`.
2412
- let mut rest = self . as_bytes ( ) ;
2412
+ let mut rest = self ;
2413
2413
while rest. len ( ) > 0 {
2414
- let Some ( non_printable_start) = rest. iter ( ) . position ( |& b| needs_escape ( b) ) else {
2414
+ let Some ( non_printable_start) = rest. as_bytes ( ) . iter ( ) . position ( |& b| needs_escape ( b) )
2415
+ else {
2415
2416
printable_range. end += rest. len ( ) ;
2416
2417
break ;
2417
2418
} ;
@@ -2420,12 +2421,10 @@ impl Debug for str {
2420
2421
// SAFETY: the position was derived from an iterator, so is known to be within bounds, and at a char boundary
2421
2422
rest = unsafe { rest. get_unchecked ( non_printable_start..) } ;
2422
2423
2423
- let printable_start = rest. iter ( ) . position ( |& b| !needs_escape ( b) ) . unwrap_or ( rest. len ( ) ) ;
2424
+ let printable_start =
2425
+ rest. as_bytes ( ) . iter ( ) . position ( |& b| !needs_escape ( b) ) . unwrap_or ( rest. len ( ) ) ;
2424
2426
let prefix;
2425
- // SAFETY: the position was derived from an iterator, so is known to be within bounds, and at a char boundary
2426
- ( prefix, rest) = unsafe { rest. split_at_unchecked ( printable_start) } ;
2427
- // SAFETY: prefix is a valid utf8 sequence, and at a char boundary
2428
- let prefix = unsafe { crate :: str:: from_utf8_unchecked ( prefix) } ;
2427
+ ( prefix, rest) = rest. split_at ( printable_start) ;
2429
2428
2430
2429
for c in prefix. chars ( ) {
2431
2430
let esc = c. escape_debug_ext ( EscapeDebugExtArgs {
0 commit comments