Replace checked slice indexing by unchecked to support panic-free code

Fixes #126425

Replace the potentially panicking `[]` indexing with `get_unchecked()`
to prevent linking with panic-related code.
This commit is contained in:
Eugene Shamis 2024-11-01 15:33:07 -04:00
parent 432972cae6
commit 02a1ab8071

View File

@ -88,7 +88,9 @@ fn fmt_int<T: DisplayInt>(&self, mut x: T, f: &mut fmt::Formatter<'_>) -> fmt::R
}; };
} }
} }
let buf = &buf[curr..]; // SAFETY: `curr` is initialized to `buf.len()` and is only decremented,
// so it is always in bounds.
let buf = unsafe { buf.get_unchecked(curr..) };
// SAFETY: The only chars in `buf` are created by `Self::digit` which are assumed to be // SAFETY: The only chars in `buf` are created by `Self::digit` which are assumed to be
// valid UTF-8 // valid UTF-8
let buf = unsafe { let buf = unsafe {