From 04334394337e19e632eba32ae1dfd554f5831b42 Mon Sep 17 00:00:00 2001 From: David Thomas Date: Wed, 14 Feb 2024 20:03:55 +0000 Subject: [PATCH] Add some comments to prevent regression --- library/std/src/sys/pal/common/small_c_string.rs | 5 +++++ 1 file changed, 5 insertions(+) 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 2312e6e5ee29..8e5ecdea9a8b 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(bytes: &[u8], mut f: F) -> io::Result where F: FnMut(&CStr) -> io::Result, { + // 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( bytes: &[u8], f: &mut dyn FnMut(&CStr) -> io::Result,