about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Thomas <david2005thomas@gmail.com>2024-02-14 20:03:55 +0000
committerGnomedDev <david2005thomas@gmail.com>2024-02-18 17:57:13 +0000
commit04334394337e19e632eba32ae1dfd554f5831b42 (patch)
tree8fdde78528b3f76e1d316bef5dd7c3e25ac0d55a
parent8daf1375437eb381e10fd4a88da5526c7b3ae64b (diff)
downloadrust-04334394337e19e632eba32ae1dfd554f5831b42.tar.gz
rust-04334394337e19e632eba32ae1dfd554f5831b42.zip
Add some comments to prevent regression
-rw-r--r--library/std/src/sys/pal/common/small_c_string.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/library/std/src/sys/pal/common/small_c_string.rs b/library/std/src/sys/pal/common/small_c_string.rs
index 2312e6e5ee2..8e5ecdea9a8 100644
--- a/library/std/src/sys/pal/common/small_c_string.rs
+++ b/library/std/src/sys/pal/common/small_c_string.rs
@@ -27,6 +27,8 @@ pub fn run_with_cstr<T, F>(bytes: &[u8], mut f: F) -> io::Result<T>
 where
     F: FnMut(&CStr) -> io::Result<T>,
 {
+    // Dispatch and dyn erase the closure type to prevent mono bloat.
+    // See https://github.com/rust-lang/rust/pull/121101.
     if bytes.len() >= MAX_STACK_ALLOCATION {
         run_with_cstr_allocating(bytes, &mut f)
     } else {
@@ -34,6 +36,9 @@ where
     }
 }
 
+/// # Safety
+///
+/// `bytes` must have a length less than `MAX_STACK_ALLOCATION`.
 unsafe fn run_with_cstr_stack<T>(
     bytes: &[u8],
     f: &mut dyn FnMut(&CStr) -> io::Result<T>,