about summary refs log tree commit diff
path: root/library/alloc/src/string.rs
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2025-07-08 06:59:33 +0000
committerGitHub <noreply@github.com>2025-07-08 06:59:33 +0000
commit9110617cc7192e512511ef74de83cb8a8ab06a69 (patch)
tree4376d8c702b0394cca4f7cc3204ed2c521d87530 /library/alloc/src/string.rs
parenta96e73f39e99811a2550c1c96923058da3fa0a47 (diff)
parentbd84ba8ddab8817691022cc7ef6e0bd36015e819 (diff)
Merge pull request #4455 from RalfJung/rustup
Rustup
Diffstat (limited to 'library/alloc/src/string.rs')
-rw-r--r--library/alloc/src/string.rs8
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() }
             }
         }
         )*