Skip to content

Commit d9c0f46

Browse files
Rollup merge of #133701 - kornelski:c-str, r=workingjubilee
Use c"lit" for CStrings without unwrap I've reviewed uses of `CString::new("lit")`. Some could be changed to `c"lit"`. Some could be changed to `c"lit".to_owned()`, avoiding an `unwrap()`. Many `CString` documentation examples could be simplified. I deliberately haven't changed all the examples to use the exact same expression, so that they can demonstrate many ways of creating `CString`s. I've left UI tests mostly unchanged, because `c""` requires edition 2021, but most UI tests use 2015, and I didn't want to accidentally change what the tests are testing.
2 parents 60677d0 + 8e51a0a commit d9c0f46

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

crates/profile/src/memory_usage.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,13 @@ fn memusage_linux() -> MemoryUsage {
6262
// mallinfo2 is very recent, so its presence needs to be detected at runtime.
6363
// Both are abysmally slow.
6464

65-
use std::ffi::CStr;
6665
use std::sync::atomic::{AtomicUsize, Ordering};
6766

6867
static MALLINFO2: AtomicUsize = AtomicUsize::new(1);
6968

7069
let mut mallinfo2 = MALLINFO2.load(Ordering::Relaxed);
7170
if mallinfo2 == 1 {
72-
let cstr = CStr::from_bytes_with_nul(b"mallinfo2\0").unwrap();
73-
mallinfo2 = unsafe { libc::dlsym(libc::RTLD_DEFAULT, cstr.as_ptr()) } as usize;
71+
mallinfo2 = unsafe { libc::dlsym(libc::RTLD_DEFAULT, c"mallinfo2".as_ptr()) } as usize;
7472
// NB: races don't matter here, since they'll always store the same value
7573
MALLINFO2.store(mallinfo2, Ordering::Relaxed);
7674
}

0 commit comments

Comments
 (0)