diff options
Diffstat (limited to 'library/alloc/src/string.rs')
| -rw-r--r-- | library/alloc/src/string.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index 5f69f699867..187d1ca71d9 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -156,7 +156,7 @@ use crate::vec::{self, Vec}; /// ``` /// /// Next, what should `s[i]` return? Because indexing returns a reference -/// to underlying data it could be `&u8`, `&[u8]`, or something else similar. +/// to underlying data it could be `&u8`, `&[u8]`, or something similar. /// Since we're only providing one index, `&u8` makes the most sense but that /// might not be what the user expects and can be explicitly achieved with /// [`as_bytes()`]: @@ -2875,7 +2875,8 @@ macro_rules! impl_to_string { out = String::with_capacity(SIZE); } - out.push_str(self.unsigned_abs()._fmt(&mut buf)); + // SAFETY: `buf` is always big enough to contain all the digits. + unsafe { out.push_str(self.unsigned_abs()._fmt(&mut buf)); } out } } @@ -2887,7 +2888,8 @@ macro_rules! impl_to_string { const SIZE: usize = $unsigned::MAX.ilog10() as usize + 1; let mut buf = [core::mem::MaybeUninit::<u8>::uninit(); SIZE]; - self._fmt(&mut buf).to_string() + // SAFETY: `buf` is always big enough to contain all the digits. + unsafe { self._fmt(&mut buf).to_string() } } } )* |
