diff options
| author | Ralf Jung <post@ralfj.de> | 2025-07-08 08:34:55 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2025-07-08 08:34:55 +0200 |
| commit | bd84ba8ddab8817691022cc7ef6e0bd36015e819 (patch) | |
| tree | 4376d8c702b0394cca4f7cc3204ed2c521d87530 /library/alloc/src/string.rs | |
| parent | 0d306dd7f43574eede5bfdd883c298a07da0b2cc (diff) | |
| parent | b1d45f6b3e672cee544e6ff197a9f21022026871 (diff) | |
Merge from rustc
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() } } } )* |
