Skip to content

Commit eff71b9

Browse files
Rollup merge of rust-lang#100371 - xfix:inline-from-bytes-with-nul-unchecked-rt-impl, r=scottmcm
Inline CStr::from_bytes_with_nul_unchecked::rt_impl Currently `CStr::from_bytes_with_nul_unchecked::rt_impl` is not being inlined. The following function: ```rust pub unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) { CStr::from_bytes_with_nul_unchecked(bytes); } ``` Outputs the following assembly on current nightly ```asm example::from_bytes_with_nul_unchecked: jmp qword ptr [rip + _ZN4core3ffi5c_str4CStr29from_bytes_with_nul_unchecked7rt_impl17h026f29f3d6a41333E@GOTPCREL] ``` Meanwhile on beta this provides the following assembly: ```asm example::from_bytes_with_nul_unchecked: ret ``` This pull request adds `#[inline]` annotation to`rt_impl` to fix a code generation regression for `CStr::from_bytes_with_nul_unchecked`.
2 parents 96fc9f1 + de95117 commit eff71b9

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

library/core/src/ffi/c_str.rs

+1
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ impl CStr {
387387
#[rustc_const_stable(feature = "const_cstr_unchecked", since = "1.59.0")]
388388
#[rustc_allow_const_fn_unstable(const_eval_select)]
389389
pub const unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &CStr {
390+
#[inline]
390391
fn rt_impl(bytes: &[u8]) -> &CStr {
391392
// Chance at catching some UB at runtime with debug builds.
392393
debug_assert!(!bytes.is_empty() && bytes[bytes.len() - 1] == 0);

0 commit comments

Comments
 (0)