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(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,