Skip to content

Commit 0433439

Browse files
committed
Add some comments to prevent regression
1 parent 8daf137 commit 0433439

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

library/std/src/sys/pal/common/small_c_string.rs

+5
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,18 @@ pub fn run_with_cstr<T, F>(bytes: &[u8], mut f: F) -> io::Result<T>
2727
where
2828
F: FnMut(&CStr) -> io::Result<T>,
2929
{
30+
// Dispatch and dyn erase the closure type to prevent mono bloat.
31+
// See https://github.com/rust-lang/rust/pull/121101.
3032
if bytes.len() >= MAX_STACK_ALLOCATION {
3133
run_with_cstr_allocating(bytes, &mut f)
3234
} else {
3335
unsafe { run_with_cstr_stack(bytes, &mut f) }
3436
}
3537
}
3638

39+
/// # Safety
40+
///
41+
/// `bytes` must have a length less than `MAX_STACK_ALLOCATION`.
3742
unsafe fn run_with_cstr_stack<T>(
3843
bytes: &[u8],
3944
f: &mut dyn FnMut(&CStr) -> io::Result<T>,

0 commit comments

Comments
 (0)