mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-21 22:34:05 +00:00
Rollup merge of #132473 - ZhekaS:core_fmt_radix_no_panic, r=joboet
[core/fmt] 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:
commit
57f64c67e0
@ -88,7 +88,10 @@ unsafe trait GenericRadix: Sized {
|
||||
};
|
||||
}
|
||||
}
|
||||
let buf = &buf[curr..];
|
||||
// SAFETY: `curr` is initialized to `buf.len()` and is only decremented, so it can't overflow. It is
|
||||
// decremented exactly once for each digit. Since u128 is the widest fixed width integer format supported,
|
||||
// the maximum number of digits (bits) is 128 for base-2, so `curr` won't underflow as well.
|
||||
let buf = unsafe { buf.get_unchecked(curr..) };
|
||||
// SAFETY: The only chars in `buf` are created by `Self::digit` which are assumed to be
|
||||
// valid UTF-8
|
||||
let buf = unsafe {
|
||||
|
Loading…
Reference in New Issue
Block a user