Skip to content

Commit 581aa8d

Browse files
author
Eugene Shamis
committed
Replace checked slice indexing by unchecked to support panic-free code
Fixes rust-lang#126425 Replace the potentially panicking `[]` indexing with `get_unchecked()` to prevent linking with panic-related code.
1 parent 84fae7e commit 581aa8d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

core/src/fmt/num.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ unsafe trait GenericRadix: Sized {
8888
};
8989
}
9090
}
91-
let buf = &buf[curr..];
91+
// SAFETY: `curr` is initialized to `buf.len()` and is only decremented,
92+
// so it is always in bounds.
93+
let buf = unsafe { buf.get_unchecked(curr..) };
9294
// SAFETY: The only chars in `buf` are created by `Self::digit` which are assumed to be
9395
// valid UTF-8
9496
let buf = unsafe {

0 commit comments

Comments
 (0)